@@ -3,7 +3,28 @@ import React, { useEffect, useState } from "react";
3
3
import { useRouter } from "next/navigation" ;
4
4
import PeerprepButton from "../shared/PeerprepButton" ;
5
5
import { useQuestionFilter } from "@/contexts/QuestionFilterContext" ;
6
- const QUERY_INTERVAL_MILLISECONDS = 3000 ;
6
+ import { useUserInfo } from "@/contexts/UserInfoContext" ;
7
+
8
+ const QUERY_INTERVAL_MILLISECONDS = 2000 ;
9
+
10
+ const getMatchRequestTime = ( ) : string => {
11
+ const now = new Date ( ) ;
12
+ const options : Intl . DateTimeFormatOptions = {
13
+ year : "numeric" ,
14
+ month : "2-digit" ,
15
+ day : "2-digit" ,
16
+ hour : "2-digit" ,
17
+ minute : "2-digit" ,
18
+ second : "2-digit" ,
19
+ hour12 : false ,
20
+ } ;
21
+
22
+ const formattedDate = now . toLocaleString ( "en-CA" , options ) ; // gives YYYY-MM-DD, HH:mm:ss
23
+ const finalDate = formattedDate . replace ( "," , "" ) . replace ( / : / g, "-" ) ;
24
+
25
+ return finalDate ;
26
+ } ;
27
+
7
28
const usePeriodicCallback = (
8
29
callback : ( ) => void ,
9
30
intervalTime : number ,
@@ -22,13 +43,16 @@ const Matchmaking = () => {
22
43
const router = useRouter ( ) ;
23
44
const [ isMatching , setIsMatching ] = useState ( false ) ;
24
45
const { difficulty, topics } = useQuestionFilter ( ) ;
46
+ const { userid } = useUserInfo ( ) ;
25
47
26
48
const handleMatch = ( ) => {
27
49
if ( ! isMatching ) {
28
50
setIsMatching ( true ) ;
29
51
console . log ( "Match attempted" ) ;
30
52
console . log ( "Selected Difficulty:" , difficulty ) ;
31
53
console . log ( "Selected Topics:" , topics ) ;
54
+ console . debug ( "Request time: " , getMatchRequestTime ( ) ) ;
55
+ console . debug ( "User id: " , userid ) ;
32
56
} else {
33
57
setIsMatching ( false ) ;
34
58
console . debug ( "User stopped matching" ) ;
@@ -46,13 +70,18 @@ const Matchmaking = () => {
46
70
47
71
return (
48
72
// TODO: move this to some admin panel or something
49
- < div className = "p-4 space-x-4" >
73
+ < div className = "p-4 flex flex-row items-center space-x-4" >
50
74
< PeerprepButton onClick = { ( ) => router . push ( `questions/new` ) } >
51
75
Add Question
52
76
</ PeerprepButton >
53
- < PeerprepButton onClick = { handleMatch } >
54
- { isMatching ? "Cancel Match" : "Find Match" }
55
- </ PeerprepButton >
77
+ < div className = "flex flex-row items-center space-x-4" >
78
+ < PeerprepButton onClick = { handleMatch } >
79
+ { isMatching ? "Cancel Match" : "Find Match" }
80
+ </ PeerprepButton >
81
+ { isMatching && (
82
+ < div className = "w-5 h-5 bg-difficulty-hard rounded-full ml-2" />
83
+ ) }
84
+ </ div >
56
85
</ div >
57
86
) ;
58
87
} ;
0 commit comments