Skip to content

Commit 8eb21bb

Browse files
committed
Fix topic population issue for EditQuestionDialog
1 parent 5c5d286 commit 8eb21bb

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

frontend/src/app/(auth)/leetcode-dashboard/EditQuestionDialog.tsx

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { topicsList } from "@/app/(auth)/match/page";
3+
import { capitalizeWords, topicsList } from "@/app/(auth)/match/page";
44
import { Button } from "@/components/ui/button";
55
import {
66
Form,
@@ -69,10 +69,11 @@ const EditQuestionDialog = ({
6969
const questionData = {
7070
questionTitle: resp.title,
7171
questionDifficulty: resp.complexity,
72-
questionTopics: resp.category.map((x: string) => x.toLowerCase()),
72+
questionTopics: resp.category.map((x: string) => capitalizeWords(x)),
7373
questionDescription: resp.description,
7474
};
75-
console.log(questionData);
75+
console.log(questionData.questionTopics);
76+
console.log(typeof questionData.questionTopics);
7677
setLeetcodeData(questionData);
7778
reset(questionData);
7879
});
@@ -175,22 +176,27 @@ const EditQuestionDialog = ({
175176
<FormField
176177
control={form.control}
177178
name="questionTopics"
178-
render={({ field }) => (
179-
<FormItem>
180-
<FormLabel className="text-primary-500">Topics</FormLabel>
181-
<FormControl>
182-
<MultiSelect
183-
options={topicsList}
184-
onValueChange={field.onChange}
185-
value={field.value}
186-
placeholder="Select topics"
187-
variant="inverted"
188-
className="bg-primary-800"
189-
/>
190-
</FormControl>
191-
<FormMessage />
192-
</FormItem>
193-
)}
179+
render={({ field }) => {
180+
console.log(field);
181+
return (
182+
<FormItem>
183+
<FormLabel className="text-primary-500">Topics</FormLabel>
184+
<FormControl>
185+
<MultiSelect
186+
key={field.value.join(",")}
187+
options={topicsList}
188+
defaultValue={field.value}
189+
onValueChange={field.onChange}
190+
value={field.value}
191+
placeholder="Select topics"
192+
variant="inverted"
193+
className="bg-primary-800"
194+
/>
195+
</FormControl>
196+
<FormMessage />
197+
</FormItem>
198+
);
199+
}}
194200
/>
195201

196202
<FormField

frontend/src/app/(auth)/match/page.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,25 @@ interface FindMatchFormOutput {
2323
preferredLanguages: string;
2424
}
2525

26-
function capitalizeWord(word: string) {
27-
if (!word) return word;
28-
return word[0].toUpperCase() + word.substr(1).toLowerCase();
26+
export function capitalizeWords(input: string): string {
27+
return input
28+
.split(" ") // Split the string by spaces to get each word
29+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) // Capitalize the first letter and lowercase the rest
30+
.join(" "); // Join the words back into a single string
2931
}
3032

3133
export const preferredLanguagesList = Object.values(QuestionLanguages).map(
3234
(ql) => {
3335
return {
34-
label: capitalizeWord(ql),
36+
label: ql,
3537
value: ql,
3638
};
3739
}
3840
);
3941

4042
export const topicsList = Object.values(QuestionTopics).map((qt) => {
4143
return {
42-
label: capitalizeWord(qt),
44+
label: qt,
4345
value: qt,
4446
};
4547
});
@@ -70,15 +72,15 @@ const FindPeer = () => {
7072

7173
const preferredLanguagesList = Object.values(QuestionLanguages).map((ql) => {
7274
return {
73-
label: capitalizeWord(ql),
75+
label: capitalizeWords(ql),
7476
value: ql,
7577
};
7678
});
7779

7880
const topicsList = Object.values(QuestionTopics)
7981
.map((qt) => {
8082
return {
81-
label: capitalizeWord(qt),
83+
label: capitalizeWords(qt),
8284
value: qt,
8385
};
8486
})

frontend/src/types/find-match.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export enum QuestionTopics {
7575
DYNAMIC_PROGRAMMING = "Dynamic Programming",
7676
BINARY_SEARCH_TREE = "Binary Search Tree",
7777
BINARY_TREE = "Binary Tree",
78+
HASH_SUM = "Hash Sum",
7879
}
7980

8081
export interface QuestionMinified {

0 commit comments

Comments
 (0)