refactor: imports resolutions

This commit is contained in:
Timothy Z. 2024-10-24 11:36:13 +03:00
parent b6b9128fcd
commit dc5f90b2e8
3 changed files with 25 additions and 23 deletions

View file

@ -11,27 +11,27 @@ import Icon from '@stremio/stremio-icons/react';
import styles from './Item.less';
import classNames from 'classnames';
import Checkbox from 'stremio/common/Checkbox';
import useStreamingServerUrls from '../useStreamingServerUrls';
type ViewModeProps = {
url: string;
onDelete?: (url: string) => void;
onSelect?: (url: string) => void;
};
}
const ViewMode = ({ url, onDelete, onSelect }: ViewModeProps) => {
const ViewMode = ({ url }: ViewModeProps) => {
const { t } = useTranslation();
const streamingServer = useStreamingServer();
const { deleteServerUrl, selectServerUrl } = useStreamingServerUrls();
const profile = useProfile();
const selected = useMemo(() => profile.settings.streamingServerUrl === url, [url, profile.settings]);
const defaultUrl = useMemo(() => url === DEFAULT_STREAMING_SERVER_URL, [url]);
const handleDelete = useCallback(() => {
onDelete?.(url);
onSelect?.(DEFAULT_STREAMING_SERVER_URL);
deleteServerUrl?.(url);
selectServerUrl?.(DEFAULT_STREAMING_SERVER_URL);
}, [url]);
const handleSelect = useCallback(() => {
onSelect?.(url);
selectServerUrl?.(url);
}, [url]);
return (
@ -79,7 +79,7 @@ type AddModeProps = {
handleValueChange: (event: ChangeEvent<HTMLInputElement>) => void;
onAdd?: (url: string) => void;
onCancel?: () => void;
};
}
const AddMode = ({ inputValue, handleValueChange, onAdd, onCancel }: AddModeProps) => {
const handleAdd = useCallback(() => {
@ -115,8 +115,6 @@ type Props =
| {
mode: 'view';
url: string;
onDelete?: (url: string) => void;
onSelect?: (url: string) => void;
};
const Item = (props: Props) => {
@ -140,11 +138,11 @@ const Item = (props: Props) => {
</div>
);
} else if (props.mode === 'view') {
const { url, onDelete, onSelect } = props;
const { url } = props;
return (
<div className={classNames(styles['item'])}>
<ViewMode url={url} onDelete={onDelete} onSelect={onSelect} />
<ViewMode url={url} />
</div>
);
}

View file

@ -11,7 +11,7 @@ import useStreamingServerUrls from './useStreamingServerUrls';
const URLsManager = () => {
const { t } = useTranslation();
const [addMode, setAddMode] = useState(false);
const { streamingServerUrls, actions } = useStreamingServerUrls();
const { streamingServerUrls, addServerUrl, reloadServer } = useStreamingServerUrls();
const onAdd = () => {
setAddMode(true);
@ -22,7 +22,7 @@ const URLsManager = () => {
};
const handleAddUrl = useCallback((url: string) => {
actions.onAdd(url);
addServerUrl(url);
setAddMode(false);
}, []);
@ -35,7 +35,7 @@ const URLsManager = () => {
<div className={styles['content']}>
{
streamingServerUrls.map((item: StreamingServerUrl) => (
<Item mode={'view'} key={item.url} {...item} {...actions} />
<Item mode={'view'} key={item.url} {...item} />
))
}
{
@ -49,7 +49,7 @@ const URLsManager = () => {
<Icon name={'add'} className={styles['icon']} />
{t('SETTINGS_SERVER_ADD_URL')}
</Button>
<Button className={styles['reload']} title={'Reload'} onClick={actions.onReload}>
<Button className={styles['reload']} title={'Reload'} onClick={reloadServer}>
<Icon name={'reset'} className={styles['icon']} />
<div className={styles['label']}>{t('RELOAD')}</div>
</Button>

View file

@ -17,7 +17,7 @@ const useStreamingServerUrls = () => {
return dateA - dateB;
});
const onAdd = useCallback((url) => {
const addServerUrl = useCallback((url) => {
const isValidUrl = (url) => {
try {
new URL(url);
@ -52,7 +52,7 @@ const useStreamingServerUrls = () => {
}
}, []);
const onDelete = useCallback((url) => {
const deleteServerUrl = useCallback((url) => {
core.transport.dispatch({
action: 'Ctx',
args: {
@ -61,7 +61,7 @@ const useStreamingServerUrls = () => {
}
});
}, []);
const onSelect = useCallback((url) => {
const selectServerUrl = useCallback((url) => {
core.transport.dispatch({
action: 'Ctx',
args: {
@ -73,7 +73,7 @@ const useStreamingServerUrls = () => {
}
});
}, []);
const onReload = useCallback(() => {
const reloadServer = useCallback(() => {
core.transport.dispatch({
action: 'StreamingServer',
args: {
@ -82,9 +82,13 @@ const useStreamingServerUrls = () => {
});
}, []);
const actions = { onAdd, onDelete, onSelect, onReload };
return { streamingServerUrls, actions };
return {
streamingServerUrls,
addServerUrl,
deleteServerUrl,
selectServerUrl,
reloadServer
}
};
export default useStreamingServerUrls;