mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-16 16:32:11 +08:00
refactor: frontend (#5068)
* refactor: setting components * refactor: frontend * fix: settings router
This commit is contained in:
@@ -23,8 +23,12 @@ interface Props {
|
||||
onDelete: (uid: string) => void;
|
||||
}
|
||||
|
||||
export const TestItem = (props: Props) => {
|
||||
const { itemData, onEdit, onDelete: onDeleteItem } = props;
|
||||
export const TestItem = ({
|
||||
id,
|
||||
itemData,
|
||||
onEdit,
|
||||
onDelete: removeTest,
|
||||
}: Props) => {
|
||||
const {
|
||||
attributes,
|
||||
listeners,
|
||||
@@ -33,7 +37,7 @@ export const TestItem = (props: Props) => {
|
||||
transition,
|
||||
isDragging,
|
||||
} = useSortable({
|
||||
id: props.id,
|
||||
id,
|
||||
});
|
||||
|
||||
const { t } = useTranslation();
|
||||
@@ -50,17 +54,19 @@ export const TestItem = (props: Props) => {
|
||||
setDelay(result);
|
||||
}, [url]);
|
||||
|
||||
useEffect(() => {
|
||||
initIconCachePath();
|
||||
}, [icon]);
|
||||
|
||||
async function initIconCachePath() {
|
||||
const initIconCachePath = useCallback(async () => {
|
||||
if (icon && icon.trim().startsWith("http")) {
|
||||
const fileName = uid + "-" + getFileName(icon);
|
||||
const iconPath = await downloadIconCache(icon, fileName);
|
||||
setIconCachePath(convertFileSrc(iconPath));
|
||||
} else {
|
||||
setIconCachePath("");
|
||||
}
|
||||
}
|
||||
}, [icon, uid]);
|
||||
|
||||
useEffect(() => {
|
||||
void initIconCachePath();
|
||||
}, [initIconCachePath]);
|
||||
|
||||
function getFileName(url: string) {
|
||||
return url.substring(url.lastIndexOf("/") + 1);
|
||||
@@ -74,7 +80,7 @@ export const TestItem = (props: Props) => {
|
||||
const onDelete = useLockFn(async () => {
|
||||
setAnchorEl(null);
|
||||
try {
|
||||
onDeleteItem(uid);
|
||||
removeTest(uid);
|
||||
} catch (err: any) {
|
||||
showNotice("error", err.message || err.toString());
|
||||
}
|
||||
@@ -102,12 +108,12 @@ export const TestItem = (props: Props) => {
|
||||
return () => {
|
||||
if (unlistenFn) {
|
||||
console.log(
|
||||
`TestItem for ${props.id} unmounting or url changed, cleaning up test-all listener.`,
|
||||
`TestItem for ${id} unmounting or url changed, cleaning up test-all listener.`,
|
||||
);
|
||||
unlistenFn();
|
||||
}
|
||||
};
|
||||
}, [url, addListener, onDelay, props.id]);
|
||||
}, [url, addListener, onDelay, id]);
|
||||
|
||||
return (
|
||||
<Box
|
||||
|
||||
@@ -26,12 +26,7 @@ export const TestViewer = forwardRef<TestViewerRef, Props>((props, ref) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { verge, patchVerge } = useVerge();
|
||||
const testList = verge?.test_list ?? [];
|
||||
const {
|
||||
control,
|
||||
watch: _watch,
|
||||
register: _register,
|
||||
...formIns
|
||||
} = useForm<IVergeTestItem>({
|
||||
const { control, ...formIns } = useForm<IVergeTestItem>({
|
||||
defaultValues: {
|
||||
name: "",
|
||||
icon: "",
|
||||
|
||||
Reference in New Issue
Block a user