refactor: frontend (#5068)

* refactor: setting components

* refactor: frontend

* fix: settings router
This commit is contained in:
Sline
2025-10-15 18:57:44 +08:00
committed by GitHub
parent a591ee1efc
commit 0b4403b67b
34 changed files with 1072 additions and 861 deletions
+18 -12
View File
@@ -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
+1 -6
View File
@@ -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: "",