Skip to content

Commit b21b159

Browse files
committed
Remove CheatPanel component and add useStateMachine hook
1 parent 3720a6f commit b21b159

File tree

3 files changed

+33
-25
lines changed

3 files changed

+33
-25
lines changed

frontend/src/app/dashboard/_components/FindMatch/CheatPanel.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

frontend/src/app/dashboard/_components/FindMatch/FindMatchButton.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { FindMatchProvider } from "@/contexts/FindMatchContext";
33
import ControlButton from "./ControlButton";
44
import ConfigurationPanel from "./ConfigurationPanel";
55
import ConfirmationDialog from "./ConfirmationDialog";
6-
// import CheatPanel from "./CheatPanel";
76
import { getQuestionCategories } from "@/services/questionService";
87
import { DifficultyEnum } from "@/types/Question";
98
import { getCurrentUser } from "@/services/userService";
@@ -32,7 +31,6 @@ export default async function FindMatchButton() {
3231
socketUrl={`ws://localhost:4000/match`}
3332
userId={userData.id}
3433
>
35-
{/* <CheatPanel /> */}
3634
<ControlButton />
3735
<ConfigurationPanel
3836
difficulties={DifficultyEnum.options}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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;

0 commit comments

Comments
 (0)