refactor: unify showNotice usage

This commit is contained in:
Slinetrac
2025-11-02 14:59:06 +08:00
Unverified
parent 50710e0633
commit 3eb8e7a066
38 changed files with 139 additions and 192 deletions

View File

@@ -133,7 +133,7 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
currData.current = value;
onChange?.(prevData.current, currData.current);
} catch (err: any) {
showNotice("error", createRawNotice(err.message || err.toString()));
showNotice.error(createRawNotice(err.message || err.toString()));
}
});
@@ -144,7 +144,7 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
}
onClose();
} catch (err: any) {
showNotice("error", createRawNotice(err.message || err.toString()));
showNotice.error(createRawNotice(err.message || err.toString()));
}
});
@@ -152,7 +152,7 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
try {
onClose();
} catch (err: any) {
showNotice("error", createRawNotice(err.message || err.toString()));
showNotice.error(createRawNotice(err.message || err.toString()));
}
});

View File

@@ -384,14 +384,14 @@ export const GroupsEditorViewer = (props: Props) => {
}
await saveProfileFile(property, nextData);
showNotice("success", {
showNotice.success({
i18nKey: "components.profile.notifications.saved",
});
setPrevData(nextData);
onSave?.(prevData, nextData);
onClose();
} catch (err: any) {
showNotice("error", createRawNotice(err.toString()));
showNotice.error(createRawNotice(err.toString()));
}
});
@@ -922,8 +922,7 @@ export const GroupsEditorViewer = (props: Props) => {
}
setPrependSeq([formIns.getValues(), ...prependSeq]);
} catch (err: any) {
showNotice(
"error",
showNotice.error(
createRawNotice(err.message || err.toString()),
);
}
@@ -951,8 +950,7 @@ export const GroupsEditorViewer = (props: Props) => {
}
setAppendSeq([...appendSeq, formIns.getValues()]);
} catch (err: any) {
showNotice(
"error",
showNotice.error(
createRawNotice(err.message || err.toString()),
);
}

View File

@@ -321,7 +321,7 @@ export const ProfileItem = (props: Props) => {
try {
await viewProfile(itemData.uid);
} catch (err: any) {
showNotice("error", createRawNotice(err?.message || err.toString()));
showNotice.error(createRawNotice(err?.message || err.toString()));
}
});

View File

@@ -48,7 +48,7 @@ export const ProfileMore = (props: Props) => {
try {
await viewProfile(id);
} catch (err: any) {
showNotice("error", createRawNotice(err?.message || err.toString()));
showNotice.error(createRawNotice(err?.message || err.toString()));
}
});

View File

@@ -144,8 +144,7 @@ export function ProfileViewer({ onChange, ref }: ProfileViewerProps) {
}
} catch {
// 首次创建/更新失败,尝试使用自身代理
showNotice(
"info",
showNotice.info(
t("components.profile.viewer.notifications.creationRetry"),
);
@@ -170,8 +169,7 @@ export function ProfileViewer({ onChange, ref }: ProfileViewerProps) {
await patchProfile(form.uid, { option: originalOptions });
}
showNotice(
"success",
showNotice.success(
t("components.profile.viewer.notifications.creationSuccess"),
);
}
@@ -187,7 +185,7 @@ export function ProfileViewer({ onChange, ref }: ProfileViewerProps) {
onChange(isActivating);
}, 0);
} catch (err: any) {
showNotice("error", createRawNotice(err.message || err.toString()));
showNotice.error(createRawNotice(err.message || err.toString()));
} finally {
setLoading(false);
}

View File

@@ -263,13 +263,13 @@ export const ProxiesEditorViewer = (props: Props) => {
const handleSave = useLockFn(async () => {
try {
await saveProfileFile(property, currData);
showNotice("success", {
showNotice.success({
i18nKey: "components.profile.notifications.saved",
});
onSave?.(prevData, currData);
onClose();
} catch (err: any) {
showNotice("error", createRawNotice(err.toString()));
showNotice.error(createRawNotice(err.toString()));
}
});

View File

@@ -351,8 +351,7 @@ export const RulesEditorViewer = (props: Props) => {
),
);
} catch (e: any) {
showNotice(
"error",
showNotice.error(
createRawNotice(e?.message || e?.toString() || "YAML dump error"),
);
}
@@ -482,13 +481,13 @@ export const RulesEditorViewer = (props: Props) => {
const handleSave = useLockFn(async () => {
try {
await saveProfileFile(property, currData);
showNotice("success", {
showNotice.success({
i18nKey: "components.profile.notifications.saved",
});
onSave?.(prevData, currData);
onClose();
} catch (err: any) {
showNotice("error", createRawNotice(err.toString()));
showNotice.error(createRawNotice(err.toString()));
}
});
@@ -631,8 +630,7 @@ export const RulesEditorViewer = (props: Props) => {
if (prependSeq.includes(raw)) return;
setPrependSeq([raw, ...prependSeq]);
} catch (err: any) {
showNotice(
"error",
showNotice.error(
createRawNotice(err.message || err.toString()),
);
}
@@ -652,8 +650,7 @@ export const RulesEditorViewer = (props: Props) => {
if (appendSeq.includes(raw)) return;
setAppendSeq([...appendSeq, raw]);
} catch (err: any) {
showNotice(
"error",
showNotice.error(
createRawNotice(err.message || err.toString()),
);
}