Skip to content

Commit 3b42609

Browse files
author
shavonneg
committed
Change checkbox to radio buttons
1 parent 7a80968 commit 3b42609

File tree

2 files changed

+24
-39
lines changed

2 files changed

+24
-39
lines changed

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

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { Checkbox } from "@/components/ui/checkbox";
2222
import { useState } from "react";
2323
import { cn } from "@/lib/utils";
2424
import { CaretDownIcon } from "@radix-ui/react-icons";
25+
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
2526

2627
interface MatchConfigurationPanelProps {
2728
difficulties: Difficulty[];
@@ -32,6 +33,7 @@ export default function ConfigurationPanel({
3233
difficulties: difficultyOptions,
3334
topics: topicOptions,
3435
}: MatchConfigurationPanelProps) {
36+
3537
const [difficultyRef, { height: difficultyHeight }] = useMeasure();
3638
const [topicsRef, { height: topicsSelectionHeight }] = useMeasure();
3739

@@ -46,11 +48,7 @@ export default function ConfigurationPanel({
4648
} = useFindMatchContext();
4749

4850
const handleDifficultyCheckboxChange = (text: Difficulty) => {
49-
if (difficulties.includes(text)) {
50-
setDifficulty(difficulties.filter((item) => item !== text));
51-
} else {
52-
setDifficulty([...difficulties, text]);
53-
}
51+
setDifficulty(text);
5452
};
5553

5654
const handleTopicCheckboxChange = (text: Category) => {
@@ -109,40 +107,28 @@ export default function ConfigurationPanel({
109107
}px`,
110108
}}
111109
>
112-
<div className="flex items-center col-span-2 space-x-2">
113-
<Checkbox
114-
id="All"
115-
checked={difficulties.length === difficultyOptions.length}
116-
onCheckedChange={() =>
117-
difficulties.length !== difficultyOptions.length
118-
? setDifficulty([...difficultyOptions])
119-
: setDifficulty([])
120-
}
121-
/>
122-
<label
123-
htmlFor="All"
124-
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
125-
>
126-
Select All
127-
</label>
128-
</div>
129-
{difficultyOptions.map((difficulty, index) => (
130-
<div key={index} className="flex items-center space-x-2">
131-
<Checkbox
132-
id={difficulty}
133-
checked={difficulties.includes(difficulty)}
134-
onCheckedChange={() =>
135-
handleDifficultyCheckboxChange(difficulty)
136-
}
137-
/>
110+
111+
<RadioGroup value={difficulties} onValueChange={(selectedValue: Difficulty) => setDifficulty(selectedValue)}>
112+
{difficultyOptions.map((difficultyOption) => (
113+
<div key={difficultyOption} className="flex items-center space-x-2">
114+
<RadioGroupItem
115+
value={difficultyOption}
116+
id={difficultyOption}
117+
className="flex items-center space-x-2"
118+
>
119+
<span className="text-sm font-medium leading-none">{difficultyOption}</span>
120+
</RadioGroupItem>
138121
<label
139-
htmlFor={difficulty}
122+
htmlFor={difficultyOption}
140123
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
141124
>
142-
{difficulty}
125+
{difficultyOption}
143126
</label>
144127
</div>
145128
))}
129+
</RadioGroup>
130+
131+
146132
</div>
147133
<Button
148134
onClick={() => setCollapseTopics(!collapseTopics)}

frontend/src/contexts/FindMatchContext.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ interface FindMatchContextProps {
2727
showConfigurationPanel: boolean;
2828
showContinueDialog: boolean;
2929
timer: number;
30-
difficulties: Difficulty[];
30+
difficulties: Difficulty;
3131
topics: Category[];
3232
handleFindMatch: () => void;
3333
handleCancelMatch: () => void;
3434
handleAcceptMatch: () => void;
3535
handleDeclineMatch: () => void;
3636
setShowConfigurationPanel: (show: boolean) => void;
3737
setShowContinueDialog: (show: boolean) => void;
38-
setDifficulty: (difficulty: Difficulty[]) => void;
38+
setDifficulty: (difficulty: Difficulty) => void;
3939
setTopics: (topics: Category[]) => void;
4040
}
4141

@@ -54,10 +54,9 @@ export function FindMatchProvider({
5454
children,
5555
}: PropsWithChildren<FindMatchProviderProps>) {
5656
const { toast } = useToast();
57+
58+
const [difficulty, setDifficulty] = useState<Difficulty>(DifficultyEnum.enum.Medium);
5759

58-
const [difficulty, setDifficulty] = useState<Difficulty[]>([
59-
DifficultyEnum.enum.Medium,
60-
]);
6160
const [topics, setTopics] = useState<Category[]>(["Array"]);
6261

6362
const [showConfigurationPanel, setShowConfigurationPanel] = useState(false);
@@ -84,7 +83,7 @@ export function FindMatchProvider({
8483
const matchRequest: MatchRequest = useMemo(() => {
8584
return {
8685
userId: userId,
87-
selectedDifficulty: difficulty[0],
86+
selectedDifficulty: difficulty,
8887
selectedTopic: topics,
8988
};
9089
}, [userId, difficulty, topics]);

0 commit comments

Comments
 (0)