@@ -3,10 +3,10 @@ import { useState } from "react";
3
3
import QueueButton from "../button/QueueButton" ;
4
4
import { QuestionType } from "../../admin/question/page" ;
5
5
import { atom , useAtom } from "jotai" ;
6
- import { innkeeperWriteAtom } from "@/libs/room-jotai" ;
6
+ import { innkeeperWriteAtom , isQueuingAtom } from "@/libs/room-jotai" ;
7
7
import { fetchAllQuestionsDoneByUser } from "@/app/api" ;
8
8
import { useQuery } from "@tanstack/react-query" ;
9
- import { Skeleton , Table } from "antd" ;
9
+ import { Skeleton , Table , notification } from "antd" ;
10
10
11
11
const sendMatchRequestAtom = atom (
12
12
null ,
@@ -23,9 +23,17 @@ const MatchingPage = () => {
23
23
questionDifficulty : "EASY" | "MEDIUM" | "HARD" ,
24
24
) => void = useAtom ( sendMatchRequestAtom ) [ 1 ] ;
25
25
26
+ const [ isQueueing , setIsQueueing ] = useAtom ( isQueuingAtom ) ;
27
+
26
28
const [ difficulty , setDifficulty ] = useState < "EASY" | "MEDIUM" | "HARD" > (
27
29
"EASY" ,
28
30
) ;
31
+
32
+ const handleChangeDiff = ( difficulty : "EASY" | "MEDIUM" | "HARD" ) => {
33
+ if ( ! isQueueing ) {
34
+ setDifficulty ( difficulty ) ;
35
+ }
36
+ } ;
29
37
const activityTableColumns : any = [
30
38
{
31
39
title : "Question" ,
@@ -105,55 +113,63 @@ const MatchingPage = () => {
105
113
console . log ( { allQuestions } ) ;
106
114
107
115
return (
108
- < main className = "flex h-full flex-col items-center justify-center" >
109
- < section className = "flex items-center gap-4" >
110
- < label >
111
- < span > Difficulty Setting:</ span >
112
- </ label >
113
- < div className = "join" >
114
- < button
115
- type = "button"
116
- className = { `btn btn-primary join-item text-white ${
117
- difficulty == "EASY" && "btn-success"
118
- } `}
119
- onClick = { ( ) => setDifficulty ( "EASY" ) }
120
- >
121
- Easy
122
- </ button >
123
- < button
124
- type = "button"
125
- className = { `btn btn-primary join-item text-white ${
126
- difficulty == "MEDIUM" && "btn-warning"
127
- } `}
128
- onClick = { ( ) => setDifficulty ( "MEDIUM" ) }
129
- >
130
- Medium
131
- </ button >
132
- < button
133
- type = "button"
134
- className = { `btn btn-primary join-item text-white ${
135
- difficulty == "HARD" && "btn-error"
136
- } `}
137
- onClick = { ( ) => setDifficulty ( "HARD" ) }
138
- >
139
- Hard
140
- </ button >
116
+ < >
117
+ < main className = "flex h-full flex-col items-center justify-center" >
118
+ < section className = "flex items-center gap-4" >
119
+ < label >
120
+ < span > Difficulty Setting:</ span >
121
+ </ label >
122
+ < div className = "join" >
123
+ < button
124
+ type = "button"
125
+ className = { `btn btn-primary join-item text-white ${
126
+ difficulty == "EASY" && "btn-success"
127
+ } `}
128
+ onClick = { ( ) => handleChangeDiff ( "EASY" ) }
129
+ >
130
+ Easy
131
+ </ button >
132
+ < button
133
+ type = "button"
134
+ className = { `btn btn-primary join-item text-white ${
135
+ difficulty == "MEDIUM" && "btn-warning"
136
+ } `}
137
+ onClick = { ( ) => handleChangeDiff ( "MEDIUM" ) }
138
+ >
139
+ Medium
140
+ </ button >
141
+ < button
142
+ type = "button"
143
+ className = { `btn btn-primary join-item text-white ${
144
+ difficulty == "HARD" && "btn-error"
145
+ } `}
146
+ onClick = { ( ) => handleChangeDiff ( "HARD" ) }
147
+ >
148
+ Hard
149
+ </ button >
150
+ </ div >
151
+ < QueueButton
152
+ enterQueue = { ( ) => {
153
+ setIsQueueing ( true ) ;
154
+ sendMatchRequest ( difficulty ) ;
155
+ } }
156
+ selectedDifficulty = { difficulty }
157
+ />
158
+ </ section >
159
+ < div className = "m-7" >
160
+ < h1 className = "mb-2 block text-5xl font-bold text-white underline" >
161
+ Completed Questions
162
+ </ h1 >
163
+ < Table
164
+ className = "mt-4"
165
+ bordered
166
+ columns = { activityTableColumns }
167
+ dataSource = { allQuestions as any }
168
+ pagination = { { position : [ "bottomCenter" ] } }
169
+ />
141
170
</ div >
142
- < QueueButton enterQueue = { ( ) => sendMatchRequest ( difficulty ) } />
143
- </ section >
144
- < div className = "m-7" >
145
- < h1 className = "mb-2 block text-5xl font-bold text-white underline" >
146
- Completed Questions
147
- </ h1 >
148
- < Table
149
- className = "mt-4"
150
- bordered
151
- columns = { activityTableColumns }
152
- dataSource = { allQuestions as any }
153
- pagination = { { position : [ "bottomCenter" ] } }
154
- />
155
- </ div >
156
- </ main >
171
+ </ main >
172
+ </ >
157
173
) ;
158
174
} ;
159
175
0 commit comments