File tree Expand file tree Collapse file tree 3 files changed +33
-25
lines changed
app/dashboard/_components/FindMatch Expand file tree Collapse file tree 3 files changed +33
-25
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ import { FindMatchProvider } from "@/contexts/FindMatchContext";
3
3
import ControlButton from "./ControlButton" ;
4
4
import ConfigurationPanel from "./ConfigurationPanel" ;
5
5
import ConfirmationDialog from "./ConfirmationDialog" ;
6
- // import CheatPanel from "./CheatPanel";
7
6
import { getQuestionCategories } from "@/services/questionService" ;
8
7
import { DifficultyEnum } from "@/types/Question" ;
9
8
import { getCurrentUser } from "@/services/userService" ;
@@ -32,7 +31,6 @@ export default async function FindMatchButton() {
32
31
socketUrl = { `ws://localhost:4000/match` }
33
32
userId = { userData . id }
34
33
>
35
- { /* <CheatPanel /> */ }
36
34
< ControlButton />
37
35
< ConfigurationPanel
38
36
difficulties = { DifficultyEnum . options }
Original file line number Diff line number Diff line change
1
+ import { useState , useCallback } from "react" ;
2
+
3
+ // Define possible states and transitions
4
+ const states = {
5
+ IDLE : "IDLE" ,
6
+ FINDING : "FINDING" ,
7
+ FOUND : "FOUND" ,
8
+ } ;
9
+
10
+ const stateTransitions = {
11
+ [ states . IDLE ] : [ states . FINDING , states . FOUND ] ,
12
+ [ states . FINDING ] : [ states . IDLE ] ,
13
+ [ states . FOUND ] : [ states . IDLE ] ,
14
+ } ;
15
+
16
+ function useStateMachine ( ) {
17
+ const [ state , setState ] = useState ( states . IDLE ) ;
18
+
19
+ const transition = useCallback (
20
+ ( newState : string ) => {
21
+ if ( stateTransitions [ state ] . includes ( newState ) ) {
22
+ setState ( newState ) ;
23
+ } else {
24
+ console . warn ( `Invalid transition from ${ state } to ${ newState } ` ) ;
25
+ }
26
+ } ,
27
+ [ state ]
28
+ ) ;
29
+
30
+ return [ state , transition ] ;
31
+ }
32
+
33
+ export default useStateMachine ;
You can’t perform that action at this time.
0 commit comments