@@ -4,13 +4,18 @@ 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" ;
12
- import { match } from "assert " ;
13
- import { TIMEOUT } from "dns " ;
17
+ import ResettingStopwatch from "../shared/ResettingStopwatch " ;
18
+ import PeerprepDropdown from "../shared/PeerprepDropdown " ;
14
19
15
20
const QUERY_INTERVAL_MILLISECONDS = 5000 ;
16
21
const TIMEOUT_MILLISECONDS = 30000 ;
@@ -50,7 +55,9 @@ const usePeriodicCallback = (
50
55
const Matchmaking = ( ) => {
51
56
const router = useRouter ( ) ;
52
57
const [ isMatching , setIsMatching ] = useState < boolean > ( false ) ;
53
- const { difficulty, topics } = useQuestionFilter ( ) ;
58
+ const [ difficultyFilter , setDifficultyFilter ] = useState < string > ( Difficulty . Easy ) ;
59
+ const [ topicFilter , setTopicFilter ] = useState < string [ ] > ( [ "all" ] ) ;
60
+ const { difficulties, topicList } = useQuestionFilter ( ) ;
54
61
const { userid } = useUserInfo ( ) ;
55
62
const timeout = useRef < NodeJS . Timeout > ( ) ;
56
63
@@ -62,6 +69,17 @@ const Matchmaking = () => {
62
69
}
63
70
} ;
64
71
72
+ const getMatchMakingRequest = ( ) : MatchRequest => {
73
+ const matchRequest : MatchRequest = {
74
+ userId : userid ,
75
+ difficulty : difficultyFilter ,
76
+ topicTags : topicFilter ,
77
+ requestTime : getMatchRequestTime ( ) ,
78
+ } ;
79
+
80
+ return matchRequest ;
81
+ } ;
82
+
65
83
const handleMatch = async ( ) => {
66
84
if ( ! isMatching ) {
67
85
setIsMatching ( true ) ;
@@ -73,12 +91,7 @@ const Matchmaking = () => {
73
91
} , TIMEOUT_MILLISECONDS ) ;
74
92
75
93
// assemble the match request
76
- const matchRequest : MatchRequest = {
77
- userId : userid ,
78
- difficulty : difficulty ,
79
- topicTags : topics ,
80
- requestTime : getMatchRequestTime ( ) ,
81
- } ;
94
+ const matchRequest = getMatchMakingRequest ( ) ;
82
95
console . log ( "Match attempted" ) ;
83
96
console . debug ( matchRequest ) ;
84
97
@@ -128,9 +141,20 @@ const Matchmaking = () => {
128
141
< PeerprepButton onClick = { handleMatch } >
129
142
{ isMatching ? "Cancel Match" : "Find Match" }
130
143
</ PeerprepButton >
131
- { isMatching && (
132
- < div className = "w-3 h-3 bg-difficulty-hard rounded-full ml-2" />
133
- ) }
144
+ { ! isMatching &&
145
+ < PeerprepDropdown label = "Difficulty"
146
+ value = { difficultyFilter }
147
+ onChange = { e => setDifficultyFilter ( e . target . value ) }
148
+ // truthfully we don't need this difficulties list, but we are temporarily including it
149
+ options = { difficulties } />
150
+ }
151
+ { ! isMatching &&
152
+ < PeerprepDropdown label = "Topics"
153
+ value = { topicFilter [ 0 ] }
154
+ onChange = { e => setTopicFilter ( e . target . value === "all" ? topicList : [ e . target . value ] ) }
155
+ options = { topicList } />
156
+ }
157
+ { isMatching && < ResettingStopwatch isActive = { isMatching } /> }
134
158
</ div >
135
159
</ div >
136
160
) ;
0 commit comments