import cx from 'clsx'; import * as React from 'react'; import { Eye, EyeOff, X as Close } from 'react-feather'; import { useToggle } from 'src/hooks/basic'; import { getClashAPIConfigs, getSelectedClashAPIConfigIndex, } from 'src/store/app'; import { ClashAPIConfig } from 'src/types'; import s from './BackendList.module.scss'; import { connect, useStoreActions } from './StateProvider'; type Config = ClashAPIConfig & { addedAt: number }; const mapState = (s) => ({ apiConfigs: getClashAPIConfigs(s), selectedClashAPIConfigIndex: getSelectedClashAPIConfigIndex(s), }); export const BackendList = connect(mapState)(BackendListImpl); function BackendListImpl({ apiConfigs, selectedClashAPIConfigIndex, }: { apiConfigs: Config[]; selectedClashAPIConfigIndex: number; }) { const { app: { removeClashAPIConfig, selectClashAPIConfig }, } = useStoreActions(); const onRemove = React.useCallback( (conf: ClashAPIConfig) => { removeClashAPIConfig(conf); }, [removeClashAPIConfig] ); const onSelect = React.useCallback( (conf: ClashAPIConfig) => { selectClashAPIConfig(conf); }, [selectClashAPIConfig] ); return ( <> ); } function Item({ baseURL, secret, disableRemove, onRemove, onSelect, }: { baseURL: string; secret: string; disableRemove: boolean; onRemove: (x: ClashAPIConfig) => void; onSelect: (x: ClashAPIConfig) => void; }) { const [show, toggle] = useToggle(); const Icon = show ? EyeOff : Eye; const handleTap = React.useCallback((e: React.KeyboardEvent) => { e.stopPropagation(); }, []); return ( <> onSelect({ baseURL, secret })} onKeyUp={handleTap} > {baseURL} {secret ? ( <> {show ? secret : '***'} {/* @ts-expect-error ts-migrate(2322) FIXME: Type 'boolean | (() => void)' is not assignable to... Remove this comment to see the full error message */} ) : null} ); } function Button({ children, onClick, className, disabled, }: { children: React.ReactNode; onClick?: (e: React.MouseEvent) => unknown; className: string; disabled?: boolean; }) { return ( ); }