import React, { ChangeEvent } from 'react'; import { Box, Button, Divider, FormControl, InputBase, InputLabel, Link, MenuItem, Select, TextField, Tooltip, Typography } from '@mui/material'; import useStore from '../../../hooks/useStore'; import MultiSelect from '../../reusable/MultiSelect'; import { messageChannelContext } from '../../../provider/MessageChannel'; import LoadingButton from '@mui/lab/LoadingButton'; import { useSnackbar } from 'notistack'; import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'; type DownloadSelectorProps = { onFinish?: () => unknown } const DownloadSelector: React.FC = ({ onFinish }) => { const messageHandler = React.useContext(messageChannelContext); const [store, dispatch] = useStore(); const [availableDubs, setAvailableDubs] = React.useState([]); const [availableSubs, setAvailableSubs ] = React.useState([]); const [ loading, setLoading ] = React.useState(false); const { enqueueSnackbar } = useSnackbar(); const ITEM_HEIGHT = 48; const ITEM_PADDING_TOP = 8; React.useEffect(() => { (async () => { /* If we don't wait the response is undefined? */ await new Promise((resolve) => setTimeout(() => resolve(undefined), 100)); const dubLang = messageHandler?.handleDefault('dubLang'); const subLang = messageHandler?.handleDefault('dlsubs'); const q = messageHandler?.handleDefault('q'); const fileName = messageHandler?.handleDefault('fileName'); const dlVideoOnce = messageHandler?.handleDefault('dlVideoOnce'); const result = await Promise.all([dubLang, subLang, q, fileName, dlVideoOnce]); dispatch({ type: 'downloadOptions', payload: { ...store.downloadOptions, dubLang: result[0], dlsubs: result[1], q: result[2], fileName: result[3], dlVideoOnce: result[4], } }); setAvailableDubs(await messageHandler?.availableDubCodes() ?? []); setAvailableSubs(await messageHandler?.availableSubCodes() ?? []); })(); }, []); const addToQueue = async () => { setLoading(true); const res = await messageHandler?.resolveItems(store.downloadOptions); if (!res) return enqueueSnackbar('The request failed. Please check if the ID is correct.', { variant: 'error' }); setLoading(false); if (onFinish) onFinish(); }; const listEpisodes = async () => { if (!store.downloadOptions.id) { return enqueueSnackbar('Please enter a ID', { variant: 'error' }); } setLoading(true); const res = await messageHandler?.listEpisodes(store.downloadOptions.id); if (!res || !res.isOk) { setLoading(false); return enqueueSnackbar('The request failed. Please check if the ID is correct.', { variant: 'error' }); } else { dispatch({ type: 'episodeListing', payload: res.value }); } setLoading(false); }; return General Options { dispatch({ type: 'downloadOptions', payload: { ...store.downloadOptions, id: e.target.value } }); }} label='Show ID'/> { const parsed = parseInt(e.target.value); if (isNaN(parsed) || parsed < 0 || parsed > 10) return; dispatch({ type: 'downloadOptions', payload: { ...store.downloadOptions, q: parsed } }); }} label='Quality Level (0 for max)'/> Simulcast is only supported on Hidive } arrow placement='top' > Episode Options { dispatch({ type: 'downloadOptions', payload: { ...store.downloadOptions, e: e.target.value } }); }} placeholder='Episode Select'/> List
Episodes
Language Options { dispatch({ type: 'downloadOptions', payload: { ...store.downloadOptions, dubLang: e } }); }} allOption /> { dispatch({ type: 'downloadOptions', payload: { ...store.downloadOptions, dlsubs: e } }); }} /> Hardsubs are only supported on Crunchyroll } arrow placement='top'> Hardsub Language Downloads the hardsub version of the selected subtitle.
Subtitles are displayed PERMANENTLY!
You can choose only 1 subtitle per video! } arrow placement='top'>
{ dispatch({ type: 'downloadOptions', payload: { ...store.downloadOptions, fileName: e.target.value } }); }} sx={{ width: '87%' }} label='Filename Overwrite' /> Click here to see the documentation } arrow placement='top'> Add to Queue ; }; export default DownloadSelector;