diff options
author | crupest <crupest@outlook.com> | 2023-07-31 21:16:27 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-07-31 21:16:27 +0800 |
commit | 710ff9d3d2e55113798c39b0595f8f71b12091ef (patch) | |
tree | dabb6c0af713de201094532a8c1b3f5299df7139 /FrontEnd/src/views/common | |
parent | 00c3736c3818053859710a2fbaec837dd9cbb586 (diff) | |
download | timeline-710ff9d3d2e55113798c39b0595f8f71b12091ef.tar.gz timeline-710ff9d3d2e55113798c39b0595f8f71b12091ef.tar.bz2 timeline-710ff9d3d2e55113798c39b0595f8f71b12091ef.zip |
...
Diffstat (limited to 'FrontEnd/src/views/common')
-rw-r--r-- | FrontEnd/src/views/common/dialog/index.ts | 14 |
1 files changed, 11 insertions, 3 deletions
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<D extends string> = DialogMap< export function useDialog<D extends string>( dialogs: D[], - initDialog?: D | null, + options?: { + initDialog?: D | null; + onClose?: { + [K in D]?: () => void; + }; + }, ): { dialog: D | null; switchDialog: (newDialog: D | null) => void; dialogPropsMap: DialogPropsMap<D>; createDialogSwitch: (newDialog: D | null) => () => void; } { - const [dialog, setDialog] = useState<D | null>(initDialog ?? null); + const [dialog, setDialog] = useState<D | null>(options?.initDialog ?? null); const [dialogKeys, setDialogKeys] = useState<DialogKeyMap<D>>( () => Object.fromEntries(dialogs.map((d) => [d, 0])) as DialogKeyMap<D>, @@ -47,7 +52,10 @@ export function useDialog<D extends string>( { key: `${d}-${dialogKeys[d]}`, open: dialog === d, - onClose: () => switchDialog(null), + onClose: () => { + switchDialog(null); + options?.onClose?.[d]?.(); + }, }, ]), ) as DialogPropsMap<D>, |