@@ -17,7 +17,7 @@ import {
17
17
topicsList ,
18
18
} from "@/utils/constants" ;
19
19
import Swal from "sweetalert2" ;
20
- import { createRoot } from "react-dom/client" ;
20
+ // import { createRoot } from "react-dom/client";
21
21
22
22
interface FindMatchFormOutput {
23
23
questionDifficulties : string [ ] ;
@@ -36,24 +36,27 @@ interface FindMatchSocketMessageResponse {
36
36
matchedUserEmail : string ;
37
37
}
38
38
39
+ const TIMEOUT_TIMER = 30 ; // in seconds
40
+
39
41
const showLoadingSpinner = ( onCancel : ( ) => void ) => {
40
42
Swal . fire ( {
41
43
title : "Finding a match..." ,
42
44
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>
45
46
` ,
46
47
allowOutsideClick : false ,
47
48
allowEscapeKey : false ,
48
49
showCancelButton : true ,
49
50
cancelButtonText : "Cancel" ,
50
51
showConfirmButton : false ,
52
+ timer : TIMEOUT_TIMER * 1000 ,
53
+ timerProgressBar : true ,
51
54
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 ) ;
57
60
} ,
58
61
} ) . then ( ( result ) => {
59
62
// Handle cancel button click
@@ -73,8 +76,6 @@ const SOCKET_URL =
73
76
74
77
const CURRENT_USER = getBaseUserData ( ) . username ; // Username is unique
75
78
76
- const TIMEOUT_TIMER = 100 ; // in seconds
77
-
78
79
const FindPeer = ( ) => {
79
80
const stompClientRef = useRef < StompClient | null > ( null ) ;
80
81
const [ isConnected , setIsConnected ] = useState ( false ) ;
0 commit comments