refactor: notification system
This commit is contained in:
@@ -16,9 +16,9 @@ import {
|
||||
CloseFullscreenRounded,
|
||||
} from "@mui/icons-material";
|
||||
import { useThemeMode } from "@/services/states";
|
||||
import { Notice } from "@/components/base";
|
||||
import { nanoid } from "nanoid";
|
||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
import getSystem from "@/utils/get-system";
|
||||
import debounce from "@/utils/debounce";
|
||||
|
||||
@@ -127,7 +127,7 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
||||
currData.current = value;
|
||||
onChange?.(prevData.current, currData.current);
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString());
|
||||
showNotice('error', err.message || err.toString());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -136,7 +136,7 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
||||
!readOnly && onSave?.(prevData.current, currData.current);
|
||||
onClose();
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString());
|
||||
showNotice('error', err.message || err.toString());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -144,7 +144,7 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
|
||||
try {
|
||||
onClose();
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString());
|
||||
showNotice('error', err.message || err.toString());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -40,13 +40,14 @@ import {
|
||||
readProfileFile,
|
||||
saveProfileFile,
|
||||
} from "@/services/cmds";
|
||||
import { Notice, Switch } from "@/components/base";
|
||||
import { Switch } from "@/components/base";
|
||||
import getSystem from "@/utils/get-system";
|
||||
import { BaseSearchBox } from "../base/base-search-box";
|
||||
import { Virtuoso } from "react-virtuoso";
|
||||
import MonacoEditor from "react-monaco-editor";
|
||||
import { useThemeMode } from "@/services/states";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
|
||||
interface Props {
|
||||
proxiesUid: string;
|
||||
@@ -285,10 +286,11 @@ export const GroupsEditorViewer = (props: Props) => {
|
||||
const handleSave = useLockFn(async () => {
|
||||
try {
|
||||
await saveProfileFile(property, currData);
|
||||
showNotice('success', t("Saved Successfully"));
|
||||
onSave?.(prevData, currData);
|
||||
onClose();
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString());
|
||||
showNotice('error', err.toString());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -725,7 +727,7 @@ export const GroupsEditorViewer = (props: Props) => {
|
||||
}
|
||||
setPrependSeq([formIns.getValues(), ...prependSeq]);
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString());
|
||||
showNotice('error', err.message || err.toString());
|
||||
}
|
||||
}}
|
||||
>
|
||||
@@ -747,7 +749,7 @@ export const GroupsEditorViewer = (props: Props) => {
|
||||
}
|
||||
setAppendSeq([...appendSeq, formIns.getValues()]);
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString());
|
||||
showNotice('error', err.message || err.toString());
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
saveProfileFile,
|
||||
getNextUpdateTime,
|
||||
} from "@/services/cmds";
|
||||
import { Notice } from "@/components/base";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
import { GroupsEditorViewer } from "@/components/profile/groups-editor-viewer";
|
||||
import { RulesEditorViewer } from "@/components/profile/rules-editor-viewer";
|
||||
import { EditorViewer } from "@/components/profile/editor-viewer";
|
||||
@@ -271,7 +271,7 @@ export const ProfileItem = (props: Props) => {
|
||||
try {
|
||||
await viewProfile(itemData.uid);
|
||||
} catch (err: any) {
|
||||
Notice.error(err?.message || err.toString());
|
||||
showNotice('error', err?.message || err.toString());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -302,7 +302,7 @@ export const ProfileItem = (props: Props) => {
|
||||
await updateProfile(itemData.uid, option);
|
||||
|
||||
// 更新成功,刷新列表
|
||||
Notice.success(t("Update subscription successfully"));
|
||||
showNotice('success', t("Update subscription successfully"));
|
||||
mutate("getProfiles");
|
||||
} catch (err: any) {
|
||||
// 更新完全失败(包括后端的回退尝试)
|
||||
|
||||
@@ -12,10 +12,10 @@ import {
|
||||
} from "@mui/material";
|
||||
import { FeaturedPlayListRounded } from "@mui/icons-material";
|
||||
import { viewProfile, readProfileFile, saveProfileFile } from "@/services/cmds";
|
||||
import { Notice } from "@/components/base";
|
||||
import { EditorViewer } from "@/components/profile/editor-viewer";
|
||||
import { ProfileBox } from "./profile-box";
|
||||
import { LogViewer } from "./log-viewer";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
|
||||
interface Props {
|
||||
logInfo?: [string, string][];
|
||||
@@ -43,7 +43,7 @@ export const ProfileMore = (props: Props) => {
|
||||
try {
|
||||
await viewProfile(id);
|
||||
} catch (err: any) {
|
||||
Notice.error(err?.message || err.toString());
|
||||
showNotice('error', err?.message || err.toString());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -19,10 +19,11 @@ import {
|
||||
TextField,
|
||||
} from "@mui/material";
|
||||
import { createProfile, patchProfile } from "@/services/cmds";
|
||||
import { BaseDialog, Notice, Switch } from "@/components/base";
|
||||
import { BaseDialog, Switch } from "@/components/base";
|
||||
import { version } from "@root/package.json";
|
||||
import { FileInput } from "./file-input";
|
||||
import { useProfiles } from "@/hooks/use-profiles";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
|
||||
interface Props {
|
||||
onChange: (isActivating?: boolean) => void;
|
||||
@@ -140,7 +141,7 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
||||
}
|
||||
} catch (err) {
|
||||
// 首次创建/更新失败,尝试使用自身代理
|
||||
Notice.info(t("Profile creation failed, retrying with Clash proxy..."));
|
||||
showNotice('info', t("Profile creation failed, retrying with Clash proxy..."));
|
||||
|
||||
// 使用自身代理的配置
|
||||
const retryItem = {
|
||||
@@ -163,7 +164,7 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
||||
await patchProfile(form.uid, { option: originalOptions });
|
||||
}
|
||||
|
||||
Notice.success(t("Profile creation succeeded with Clash proxy"));
|
||||
showNotice('success', t("Profile creation succeeded with Clash proxy"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +176,7 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
||||
// 只传递当前配置激活状态,让父组件决定是否需要触发配置重载
|
||||
props.onChange(isActivating);
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString());
|
||||
showNotice('error', err.message || err.toString());
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@@ -33,13 +33,13 @@ import {
|
||||
} from "@mui/icons-material";
|
||||
import { ProxyItem } from "@/components/profile/proxy-item";
|
||||
import { readProfileFile, saveProfileFile } from "@/services/cmds";
|
||||
import { Notice } from "@/components/base";
|
||||
import getSystem from "@/utils/get-system";
|
||||
import { BaseSearchBox } from "../base/base-search-box";
|
||||
import { Virtuoso } from "react-virtuoso";
|
||||
import MonacoEditor from "react-monaco-editor";
|
||||
import { useThemeMode } from "@/services/states";
|
||||
import parseUri from "@/utils/uri-parser";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
|
||||
interface Props {
|
||||
profileUid: string;
|
||||
@@ -150,7 +150,7 @@ export const ProxiesEditorViewer = (props: Props) => {
|
||||
names.push(proxy.name);
|
||||
}
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString());
|
||||
showNotice('error', err.message || err.toString());
|
||||
}
|
||||
});
|
||||
return proxies;
|
||||
@@ -212,10 +212,11 @@ export const ProxiesEditorViewer = (props: Props) => {
|
||||
const handleSave = useLockFn(async () => {
|
||||
try {
|
||||
await saveProfileFile(property, currData);
|
||||
showNotice('success', t("Saved Successfully"));
|
||||
onSave?.(prevData, currData);
|
||||
onClose();
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString());
|
||||
showNotice('error', err.toString());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -34,13 +34,14 @@ import {
|
||||
VerticalAlignBottomRounded,
|
||||
} from "@mui/icons-material";
|
||||
import { readProfileFile, saveProfileFile } from "@/services/cmds";
|
||||
import { Notice, Switch } from "@/components/base";
|
||||
import { Switch } from "@/components/base";
|
||||
import getSystem from "@/utils/get-system";
|
||||
import { RuleItem } from "@/components/profile/rule-item";
|
||||
import { BaseSearchBox } from "../base/base-search-box";
|
||||
import { Virtuoso } from "react-virtuoso";
|
||||
import MonacoEditor from "react-monaco-editor";
|
||||
import { useThemeMode } from "@/services/states";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
|
||||
interface Props {
|
||||
groupsUid: string;
|
||||
@@ -414,10 +415,11 @@ export const RulesEditorViewer = (props: Props) => {
|
||||
const handleSave = useLockFn(async () => {
|
||||
try {
|
||||
await saveProfileFile(property, currData);
|
||||
showNotice('success', t("Saved Successfully"));
|
||||
onSave?.(prevData, currData);
|
||||
onClose();
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString());
|
||||
showNotice('error', err.toString());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -545,7 +547,7 @@ export const RulesEditorViewer = (props: Props) => {
|
||||
if (prependSeq.includes(raw)) return;
|
||||
setPrependSeq([raw, ...prependSeq]);
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString());
|
||||
showNotice('error', err.message || err.toString());
|
||||
}
|
||||
}}
|
||||
>
|
||||
@@ -563,7 +565,7 @@ export const RulesEditorViewer = (props: Props) => {
|
||||
if (appendSeq.includes(raw)) return;
|
||||
setAppendSeq([...appendSeq, raw]);
|
||||
} catch (err: any) {
|
||||
Notice.error(err.message || err.toString());
|
||||
showNotice('error', err.message || err.toString());
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user