Skip to content

Commit e586597

Browse files
committed
Add timer
1 parent 45438c0 commit e586597

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

frontend/src/app/(auth)/match/page.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
topicsList,
1818
} from "@/utils/constants";
1919
import Swal from "sweetalert2";
20-
import { createRoot } from "react-dom/client";
20+
// import { createRoot } from "react-dom/client";
2121

2222
interface FindMatchFormOutput {
2323
questionDifficulties: string[];
@@ -36,24 +36,27 @@ interface FindMatchSocketMessageResponse {
3636
matchedUserEmail: string;
3737
}
3838

39+
const TIMEOUT_TIMER = 30; // in seconds
40+
3941
const showLoadingSpinner = (onCancel: () => void) => {
4042
Swal.fire({
4143
title: "Finding a match...",
4244
html: `
43-
<div id="spinner-container" class="flex flex-col items-center p-5">
44-
</div>
45+
<div> You have waited for <div><div id="timer"></div></div> seconds...</div>
4546
`,
4647
allowOutsideClick: false,
4748
allowEscapeKey: false,
4849
showCancelButton: true,
4950
cancelButtonText: "Cancel",
5051
showConfirmButton: false,
52+
timer: TIMEOUT_TIMER * 1000,
53+
timerProgressBar: true,
5154
didOpen: () => {
52-
const container = document.getElementById("spinner-container");
53-
if (container) {
54-
const root = createRoot(container);
55-
root.render(<MoonLoader size={60} color={"#3498db"} />);
56-
}
55+
Swal.showLoading();
56+
const timer = Swal.getPopup()!.querySelector("#timer");
57+
setInterval(() => {
58+
timer!.textContent = `${Math.floor(Swal.getTimerLeft() / 1000)}`;
59+
}, 100);
5760
},
5861
}).then((result) => {
5962
// Handle cancel button click
@@ -73,8 +76,6 @@ const SOCKET_URL =
7376

7477
const CURRENT_USER = getBaseUserData().username; // Username is unique
7578

76-
const TIMEOUT_TIMER = 100; // in seconds
77-
7879
const FindPeer = () => {
7980
const stompClientRef = useRef<StompClient | null>(null);
8081
const [isConnected, setIsConnected] = useState(false);

0 commit comments

Comments
 (0)