Skip to content

Commit 3720a6f

Browse files
authored
Merge pull request #94 from CS3219-AY2425S1/ms4-shavonne/update-match-ui
Change checkbox to radio buttons
2 parents 7a80968 + f5c5962 commit 3720a6f

File tree

2 files changed

+39
-49
lines changed

2 files changed

+39
-49
lines changed

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

Lines changed: 34 additions & 43 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[];
@@ -45,14 +46,6 @@ export default function ConfigurationPanel({
4546
handleFindMatch,
4647
} = useFindMatchContext();
4748

48-
const handleDifficultyCheckboxChange = (text: Difficulty) => {
49-
if (difficulties.includes(text)) {
50-
setDifficulty(difficulties.filter((item) => item !== text));
51-
} else {
52-
setDifficulty([...difficulties, text]);
53-
}
54-
};
55-
5649
const handleTopicCheckboxChange = (text: Category) => {
5750
if (topics.includes(text)) {
5851
setTopics(topics.filter((item) => item !== text));
@@ -87,7 +80,7 @@ export default function ConfigurationPanel({
8780
variant={collapseDifficulties ? "soft" : "outline"}
8881
>
8982
<div className="flex flex-row justify-between w-full">
90-
<span>Select difficulties</span>
83+
<span>Select difficulty</span>
9184
<CaretDownIcon
9285
className={cn(
9386
"w-6 h-6",
@@ -100,7 +93,7 @@ export default function ConfigurationPanel({
10093
<div
10194
ref={difficultyRef}
10295
className={cn(
103-
"grid grid-cols-2 gap-4 z-0 opacity-100 transition-all duration-500",
96+
"z-0 opacity-100 transition-all duration-500",
10497
collapseDifficulties && `-z-10 opacity-0`
10598
)}
10699
style={{
@@ -109,40 +102,38 @@ export default function ConfigurationPanel({
109102
}px`,
110103
}}
111104
>
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-
/>
138-
<label
139-
htmlFor={difficulty}
140-
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
141-
>
142-
{difficulty}
143-
</label>
105+
<RadioGroup
106+
value={difficulties}
107+
onValueChange={(selectedValue: Difficulty) =>
108+
setDifficulty(selectedValue)
109+
}
110+
className="flex w-full"
111+
>
112+
<div className="flex flex-row justify-start w-full gap-12">
113+
{difficultyOptions.map((difficultyOption) => (
114+
<div
115+
key={difficultyOption}
116+
className="flex flex-row items-center gap-2"
117+
>
118+
<RadioGroupItem
119+
value={difficultyOption}
120+
id={difficultyOption}
121+
className="flex items-center space-x-2"
122+
>
123+
<span className="text-sm font-medium leading-none">
124+
{difficultyOption}
125+
</span>
126+
</RadioGroupItem>
127+
<label
128+
htmlFor={difficultyOption}
129+
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
130+
>
131+
{difficultyOption}
132+
</label>
133+
</div>
134+
))}
144135
</div>
145-
))}
136+
</RadioGroup>
146137
</div>
147138
<Button
148139
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)