From 710ff9d3d2e55113798c39b0595f8f71b12091ef Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 31 Jul 2023 21:16:27 +0800 Subject: ... --- FrontEnd/src/views/common/dialog/index.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'FrontEnd/src/views/common/dialog/index.ts') diff --git a/FrontEnd/src/views/common/dialog/index.ts b/FrontEnd/src/views/common/dialog/index.ts index e37b9ed2..59f15791 100644 --- a/FrontEnd/src/views/common/dialog/index.ts +++ b/FrontEnd/src/views/common/dialog/index.ts @@ -18,14 +18,19 @@ type DialogPropsMap = DialogMap< export function useDialog( dialogs: D[], - initDialog?: D | null, + options?: { + initDialog?: D | null; + onClose?: { + [K in D]?: () => void; + }; + }, ): { dialog: D | null; switchDialog: (newDialog: D | null) => void; dialogPropsMap: DialogPropsMap; createDialogSwitch: (newDialog: D | null) => () => void; } { - const [dialog, setDialog] = useState(initDialog ?? null); + const [dialog, setDialog] = useState(options?.initDialog ?? null); const [dialogKeys, setDialogKeys] = useState>( () => Object.fromEntries(dialogs.map((d) => [d, 0])) as DialogKeyMap, @@ -47,7 +52,10 @@ export function useDialog( { key: `${d}-${dialogKeys[d]}`, open: dialog === d, - onClose: () => switchDialog(null), + onClose: () => { + switchDialog(null); + options?.onClose?.[d]?.(); + }, }, ]), ) as DialogPropsMap, -- cgit v1.2.3