diff options
author | crupest <crupest@outlook.com> | 2023-08-26 21:36:58 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-08-26 21:36:58 +0800 |
commit | f5dfd52f6efece2f4cad227044ecf4dd66301bbc (patch) | |
tree | 0d64daae438ac6d95f0848a0b3387134d9528438 /FrontEnd/src/views/common/dialog/index.ts | |
parent | 4daa84ede781cdf6f424d68c967a17c7e1c79f59 (diff) | |
download | timeline-f5dfd52f6efece2f4cad227044ecf4dd66301bbc.tar.gz timeline-f5dfd52f6efece2f4cad227044ecf4dd66301bbc.tar.bz2 timeline-f5dfd52f6efece2f4cad227044ecf4dd66301bbc.zip |
...
Diffstat (limited to 'FrontEnd/src/views/common/dialog/index.ts')
-rw-r--r-- | FrontEnd/src/views/common/dialog/index.ts | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/FrontEnd/src/views/common/dialog/index.ts b/FrontEnd/src/views/common/dialog/index.ts deleted file mode 100644 index 59f15791..00000000 --- a/FrontEnd/src/views/common/dialog/index.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { useState } from "react"; - -export { default as Dialog } from "./Dialog"; -export { default as FullPageDialog } from "./FullPageDialog"; -export { default as OperationDialog } from "./OperationDialog"; -export { default as ConfirmDialog } from "./ConfirmDialog"; - -type DialogMap<D extends string, V> = { - [K in D]: V; -}; - -type DialogKeyMap<D extends string> = DialogMap<D, number>; - -type DialogPropsMap<D extends string> = DialogMap< - D, - { key: number | string; open: boolean; onClose: () => void } ->; - -export function useDialog<D extends string>( - dialogs: D[], - 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>(options?.initDialog ?? null); - - const [dialogKeys, setDialogKeys] = useState<DialogKeyMap<D>>( - () => Object.fromEntries(dialogs.map((d) => [d, 0])) as DialogKeyMap<D>, - ); - - const switchDialog = (newDialog: D | null) => { - if (dialog !== null) { - setDialogKeys({ ...dialogKeys, [dialog]: dialogKeys[dialog] + 1 }); - } - setDialog(newDialog); - }; - - return { - dialog, - switchDialog, - dialogPropsMap: Object.fromEntries( - dialogs.map((d) => [ - d, - { - key: `${d}-${dialogKeys[d]}`, - open: dialog === d, - onClose: () => { - switchDialog(null); - options?.onClose?.[d]?.(); - }, - }, - ]), - ) as DialogPropsMap<D>, - createDialogSwitch: (newDialog: D | null) => () => switchDialog(newDialog), - }; -} |