From e5865973937a6e8f06b611897adbef53f51d56ba Mon Sep 17 00:00:00 2001 From: Mai Ting Kai Date: Sun, 20 Oct 2024 19:33:47 +0800 Subject: [PATCH] Add timer --- frontend/src/app/(auth)/match/page.tsx | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/(auth)/match/page.tsx b/frontend/src/app/(auth)/match/page.tsx index a7c7251943..0644cb77cd 100644 --- a/frontend/src/app/(auth)/match/page.tsx +++ b/frontend/src/app/(auth)/match/page.tsx @@ -17,7 +17,7 @@ import { topicsList, } from "@/utils/constants"; import Swal from "sweetalert2"; -import { createRoot } from "react-dom/client"; +// import { createRoot } from "react-dom/client"; interface FindMatchFormOutput { questionDifficulties: string[]; @@ -36,24 +36,27 @@ interface FindMatchSocketMessageResponse { matchedUserEmail: string; } +const TIMEOUT_TIMER = 30; // in seconds + const showLoadingSpinner = (onCancel: () => void) => { Swal.fire({ title: "Finding a match...", html: ` -
-
+
You have waited for
seconds...
`, allowOutsideClick: false, allowEscapeKey: false, showCancelButton: true, cancelButtonText: "Cancel", showConfirmButton: false, + timer: TIMEOUT_TIMER * 1000, + timerProgressBar: true, didOpen: () => { - const container = document.getElementById("spinner-container"); - if (container) { - const root = createRoot(container); - root.render(); - } + Swal.showLoading(); + const timer = Swal.getPopup()!.querySelector("#timer"); + setInterval(() => { + timer!.textContent = `${Math.floor(Swal.getTimerLeft() / 1000)}`; + }, 100); }, }).then((result) => { // Handle cancel button click @@ -73,8 +76,6 @@ const SOCKET_URL = const CURRENT_USER = getBaseUserData().username; // Username is unique -const TIMEOUT_TIMER = 100; // in seconds - const FindPeer = () => { const stompClientRef = useRef(null); const [isConnected, setIsConnected] = useState(false);