@@ -4,11 +4,17 @@ import { useRouter } from "next/navigation";
4
4
import PeerprepButton from "../shared/PeerprepButton" ;
5
5
import { useQuestionFilter } from "@/contexts/QuestionFilterContext" ;
6
6
import { useUserInfo } from "@/contexts/UserInfoContext" ;
7
- import { isError , MatchRequest , MatchResponse } from "@/api/structs" ;
7
+ import {
8
+ Difficulty ,
9
+ isError ,
10
+ MatchRequest ,
11
+ MatchResponse ,
12
+ } from "@/api/structs" ;
8
13
import {
9
14
checkMatchStatus ,
10
15
findMatch ,
11
16
} from "@/app/api/internal/matching/helper" ;
17
+ import ResettingStopwatch from "../shared/ResettingStopwatch" ;
12
18
13
19
const QUERY_INTERVAL_MILLISECONDS = 5000 ;
14
20
const TIMEOUT_MILLISECONDS = 30000 ;
@@ -60,6 +66,18 @@ const Matchmaking = () => {
60
66
}
61
67
} ;
62
68
69
+ const getMatchMakingRequest = ( ) : MatchRequest => {
70
+ const matchRequest : MatchRequest = {
71
+ userId : userid ,
72
+ // welp, just bandaid default easy
73
+ difficulty : difficulty === Difficulty . All ? Difficulty . Easy : difficulty ,
74
+ topicTags : topics ,
75
+ requestTime : getMatchRequestTime ( ) ,
76
+ } ;
77
+
78
+ return matchRequest ;
79
+ } ;
80
+
63
81
const handleMatch = async ( ) => {
64
82
if ( ! isMatching ) {
65
83
setIsMatching ( true ) ;
@@ -71,12 +89,7 @@ const Matchmaking = () => {
71
89
} , TIMEOUT_MILLISECONDS ) ;
72
90
73
91
// assemble the match request
74
- const matchRequest : MatchRequest = {
75
- userId : userid ,
76
- difficulty : difficulty ,
77
- topicTags : topics ,
78
- requestTime : getMatchRequestTime ( ) ,
79
- } ;
92
+ const matchRequest = getMatchMakingRequest ( ) ;
80
93
console . log ( "Match attempted" ) ;
81
94
console . debug ( matchRequest ) ;
82
95
@@ -126,9 +139,7 @@ const Matchmaking = () => {
126
139
< PeerprepButton onClick = { handleMatch } >
127
140
{ isMatching ? "Cancel Match" : "Find Match" }
128
141
</ PeerprepButton >
129
- { isMatching && (
130
- < div className = "w-3 h-3 bg-difficulty-hard rounded-full ml-2" />
131
- ) }
142
+ { isMatching && < ResettingStopwatch isActive = { isMatching } /> }
132
143
</ div >
133
144
</ div >
134
145
) ;
0 commit comments