mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-06 03:23:45 +08:00
feat: profile-viewer: handleOk with loading state
This commit is contained in:
parent
0a61a607c9
commit
6826be73c7
@ -40,6 +40,7 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [openType, setOpenType] = useState<"new" | "edit">("new");
|
const [openType, setOpenType] = useState<"new" | "edit">("new");
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
// file input
|
// file input
|
||||||
const fileDataRef = useRef<string | null>(null);
|
const fileDataRef = useRef<string | null>(null);
|
||||||
@ -87,6 +88,7 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
|||||||
|
|
||||||
const handleOk = useLockFn(
|
const handleOk = useLockFn(
|
||||||
formIns.handleSubmit(async (form) => {
|
formIns.handleSubmit(async (form) => {
|
||||||
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
if (!form.type) throw new Error("`Type` should not be null");
|
if (!form.type) throw new Error("`Type` should not be null");
|
||||||
if (form.type === "remote" && !form.url) {
|
if (form.type === "remote" && !form.url) {
|
||||||
@ -111,11 +113,13 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
|||||||
await patchProfile(form.uid, item);
|
await patchProfile(form.uid, item);
|
||||||
}
|
}
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
|
setLoading(false);
|
||||||
setTimeout(() => formIns.reset(), 500);
|
setTimeout(() => formIns.reset(), 500);
|
||||||
fileDataRef.current = null;
|
fileDataRef.current = null;
|
||||||
props.onChange();
|
props.onChange();
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
Notice.error(err.message || err.toString());
|
Notice.error(err.message || err.toString());
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -149,6 +153,7 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
|||||||
onClose={handleClose}
|
onClose={handleClose}
|
||||||
onCancel={handleClose}
|
onCancel={handleClose}
|
||||||
onOk={handleOk}
|
onOk={handleOk}
|
||||||
|
loading={loading}
|
||||||
>
|
>
|
||||||
<Controller
|
<Controller
|
||||||
name="type"
|
name="type"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user