From ca8f2dc02d6d2143eb216e36cb818cbfd2a4e342 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sat, 19 Nov 2022 23:36:21 +0100 Subject: [PATCH] Updated the logic of the DialogContext.jsx --- .../common/contexts/Dialog/DialogContext.jsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/client/src/common/contexts/Dialog/DialogContext.jsx b/client/src/common/contexts/Dialog/DialogContext.jsx index dfafd5f8..58e3fb02 100644 --- a/client/src/common/contexts/Dialog/DialogContext.jsx +++ b/client/src/common/contexts/Dialog/DialogContext.jsx @@ -7,6 +7,8 @@ import {t} from "i18next"; export const DialogContext = createContext({}); const Dialog = ({dialog, setDialog}) => { + if (!dialog) return; + const [value, setValue] = useState(dialog.value || ""); const ref = useRef(); @@ -27,24 +29,30 @@ const Dialog = ({dialog, setDialog}) => { setValue(e.target.value); } + function closeSlow() { + if (ref.current == null) return; + ref.current.classList.add("dialog-hidden"); + setTimeout(() => setDialog(), 300); + } + function closeDialog() { - setDialog(); + closeSlow(); if (dialog.onClose) dialog.onClose(); } function submit() { if (!dialog.description && !value) return; - setDialog(); + closeSlow(); if (dialog.onSuccess) dialog.onSuccess(value); } function clear() { - setDialog(); + closeSlow(); if (dialog.onClear) dialog.onClear(); } if (dialog.speedtest) return ( -
+
@@ -96,7 +104,7 @@ export const DialogProvider = (props) => { return ( - {dialog ? : <>} + {props.children} )