Skip to content

Commit c16b325

Browse files
committed
Remove multiselect and use a fix set of categories
1 parent a2f9baa commit c16b325

File tree

3 files changed

+40
-31
lines changed

3 files changed

+40
-31
lines changed

backend/question-service/src/controllers/questionController.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,27 @@ export const readCategories = async (
251251
res: Response,
252252
): Promise<void> => {
253253
try {
254-
const uniqueCats = await Question.distinct("category");
255-
256-
res.status(200).json({
257-
message: CATEGORIES_RETRIEVED_MESSAGE,
258-
categories: sortAlphabetically(uniqueCats),
259-
});
254+
// const uniqueCats = await Question.distinct("category");
255+
256+
// res.status(200).json({
257+
// message: CATEGORIES_RETRIEVED_MESSAGE,
258+
// categories: sortAlphabetically(uniqueCats),
259+
// });
260+
res
261+
.status(200)
262+
.json({
263+
message: CATEGORIES_RETRIEVED_MESSAGE,
264+
categories: [
265+
"Strings",
266+
"Algorithms",
267+
"Data Structures",
268+
"Bit Manipulation",
269+
"Recursion",
270+
"Databases",
271+
"Arrays",
272+
"Brainteaser",
273+
],
274+
});
260275
} catch (error) {
261276
res.status(500).json({ message: SERVER_ERROR_MESSAGE, error });
262277
}

frontend/src/components/QuestionCategoryAutoComplete/index.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@ const QuestionCategoryAutoComplete: React.FC<
2424
return (
2525
<Autocomplete
2626
multiple
27-
freeSolo
2827
options={state.questionCategories}
2928
sx={{ marginTop: 2 }}
3029
value={selectedCategories}
3130
onChange={(_e, newCategoriesSelected) => {
32-
const newValue =
33-
newCategoriesSelected[newCategoriesSelected.length - 1];
34-
if (typeof newValue === "string" && newValue.startsWith(`Add: "`)) {
35-
const newCategory = newValue.slice(6, -1);
36-
state.questionCategories.push(newCategory);
37-
setSelectedCategories((prev) => [...prev, newCategory]);
38-
} else {
39-
setSelectedCategories(newCategoriesSelected);
40-
}
31+
// const newValue =
32+
// newCategoriesSelected[newCategoriesSelected.length - 1];
33+
// if (typeof newValue === "string" && newValue.startsWith(`Add: "`)) {
34+
// const newCategory = newValue.slice(6, -1);
35+
// state.questionCategories.push(newCategory);
36+
// setSelectedCategories((prev) => [...prev, newCategory]);
37+
// } else {
38+
// setSelectedCategories(newCategoriesSelected);
39+
// }
40+
setSelectedCategories(newCategoriesSelected);
4141
}}
4242
filterOptions={(options, params) => {
4343
const filtered = filter(options, params);
4444

45-
const { inputValue } = params;
45+
// const { inputValue } = params;
4646

47-
const isExisting = options.some((option) => inputValue === option);
47+
// const isExisting = options.some((option) => inputValue === option);
4848

49-
if (inputValue !== "" && !isExisting) {
50-
filtered.push(`Add: "${inputValue}"`);
51-
}
49+
// if (inputValue !== "" && !isExisting) {
50+
// filtered.push(`Add: "${inputValue}"`);
51+
// }
5252

5353
return filtered;
5454
}}

frontend/src/pages/Home/index.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const Home: React.FC = () => {
4949
}
5050
const { findMatch, loading } = match;
5151

52-
const isSmallerThan1100px = useMediaQuery('(max-width:1100px)');
52+
const isSmallerThan1100px = useMediaQuery("(max-width:1100px)");
5353

5454
useEffect(() => {
5555
getQuestionCategories(dispatch);
@@ -138,11 +138,9 @@ const Home: React.FC = () => {
138138
sx={{ backgroundColor: "white" }}
139139
>
140140
<Autocomplete
141-
multiple
142-
disableCloseOnSelect
143141
options={complexityList}
144142
onChange={(_, selectedOptions) => {
145-
setComplexities(selectedOptions);
143+
setComplexities(selectedOptions ? [selectedOptions] : []);
146144
}}
147145
renderInput={(params) => <TextField {...params} />}
148146
renderTags={(tagValue, getTagProps) =>
@@ -178,11 +176,9 @@ const Home: React.FC = () => {
178176
sx={{ backgroundColor: "white" }}
179177
>
180178
<Autocomplete
181-
multiple
182-
disableCloseOnSelect
183179
options={state.questionCategories}
184180
onChange={(_, selectedOptions) => {
185-
setCategories(selectedOptions);
181+
setCategories(selectedOptions ? [selectedOptions] : []);
186182
}}
187183
renderInput={(params) => <TextField {...params} />}
188184
renderTags={(tagValue, getTagProps) =>
@@ -218,11 +214,9 @@ const Home: React.FC = () => {
218214
sx={{ backgroundColor: "white" }}
219215
>
220216
<Autocomplete
221-
multiple
222-
disableCloseOnSelect
223217
options={languageList}
224218
onChange={(_, selectedOptions) => {
225-
setLanguages(selectedOptions);
219+
setLanguages(selectedOptions ? [selectedOptions] : []);
226220
}}
227221
renderInput={(params) => <TextField {...params} />}
228222
renderTags={(tagValue, getTagProps) =>

0 commit comments

Comments
 (0)