From 4d842995f4067058b21729aab6139cd388c36353 Mon Sep 17 00:00:00 2001
From: Wolfboy248 <georgejvindkarlsen@gmail.com>
Date: Tue, 29 Oct 2024 11:45:00 +0100
Subject: refactor: loader dialog, uploadrundialog update, touchups

---
 frontend/src/hooks/UseMessageLoad.tsx | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 frontend/src/hooks/UseMessageLoad.tsx

(limited to 'frontend/src/hooks/UseMessageLoad.tsx')

diff --git a/frontend/src/hooks/UseMessageLoad.tsx b/frontend/src/hooks/UseMessageLoad.tsx
new file mode 100644
index 0000000..defd2b3
--- /dev/null
+++ b/frontend/src/hooks/UseMessageLoad.tsx
@@ -0,0 +1,35 @@
+import React, { useState } from 'react';
+import MessageDialogLoad from "../components/MessageDialogLoad";
+
+const useMessageLoad = () => {
+    const [isOpen, setIsOpen] = useState(false);
+
+    const [title, setTitle] = useState<string>("");
+    const [resolvePromise, setResolvePromise] = useState<(() => void) | null>(null);
+
+	const messageLoad = (title: string) => {
+        setIsOpen(true);
+        setTitle(title);
+		return new Promise((resolve) => {
+			setResolvePromise(() => resolve);
+		});
+    };
+
+    const messageLoadClose = () => {
+        setIsOpen(false);
+        if (resolvePromise) {
+            resolvePromise();
+            setResolvePromise(null);
+        }
+    };
+
+    const MessageDialogLoadComponent = isOpen && (
+		<div className="dialog-container">
+        <MessageDialogLoad title={title} onClose={messageLoadClose}></MessageDialogLoad>
+		</div>
+    );
+
+    return { messageLoad, messageLoadClose, MessageDialogLoadComponent };
+}
+
+export default useMessageLoad;
-- 
cgit v1.2.3

