Skip to content

Commit ba33ed6

Browse files
committed
Change match criteria from multiselect to single select
1 parent 1222d17 commit ba33ed6

File tree

3 files changed

+40
-45
lines changed

3 files changed

+40
-45
lines changed

backend/matching-service/src/handlers/matchHandler.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export interface MatchUser {
1616

1717
export interface MatchRequest {
1818
user: MatchUser;
19-
complexities: string[];
20-
categories: string[];
21-
languages: string[];
19+
complexity: string;
20+
category: string;
21+
language: string;
2222
timeout: number;
2323
}
2424

@@ -37,7 +37,7 @@ export const sendMatchRequest = async (
3737
requestId: string,
3838
rejectedPartnerId?: string
3939
): Promise<boolean> => {
40-
const { user, complexities, categories, languages, timeout } = matchRequest;
40+
const { user, complexity, category, language, timeout } = matchRequest;
4141

4242
const matchItem: MatchRequestItem = {
4343
id: requestId,
@@ -47,12 +47,7 @@ export const sendMatchRequest = async (
4747
rejectedPartnerId: rejectedPartnerId,
4848
};
4949

50-
const sent = await sendToQueue(
51-
complexities[0],
52-
categories[0],
53-
languages[0],
54-
matchItem
55-
);
50+
const sent = await sendToQueue(complexity, category, language, matchItem);
5651
return sent;
5752
};
5853

frontend/src/contexts/MatchContext.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ type MatchUser = {
2323
};
2424

2525
type MatchCriteria = {
26-
complexities: string[];
27-
categories: string[];
28-
languages: string[];
26+
complexity: string;
27+
category: string;
28+
language: string;
2929
timeout: number;
3030
};
3131

@@ -67,9 +67,9 @@ enum MatchPaths {
6767

6868
type MatchContextType = {
6969
findMatch: (
70-
complexities: string[],
71-
categories: string[],
72-
languages: string[],
70+
complexity: string,
71+
category: string,
72+
language: string,
7373
timeout: number
7474
) => void;
7575
stopMatch: () => void;
@@ -297,9 +297,9 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
297297
};
298298

299299
const findMatch = (
300-
complexities: string[],
301-
categories: string[],
302-
languages: string[],
300+
complexity: string,
301+
category: string,
302+
language: string,
303303
timeout: number
304304
) => {
305305
if (!matchUser) {
@@ -318,19 +318,19 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
318318
MatchEvents.MATCH_REQUEST,
319319
{
320320
user: matchUser,
321-
complexities: complexities,
322-
categories: categories,
323-
languages: languages,
321+
complexity: complexity,
322+
category: category,
323+
language: language,
324324
timeout: timeout,
325325
},
326326
(requested: boolean) => {
327327
clearTimeout(requestTimeout);
328328
setTimeout(() => setLoading(false), 500);
329329
if (requested) {
330330
setMatchCriteria({
331-
complexities,
332-
categories,
333-
languages,
331+
complexity: complexity,
332+
category: category,
333+
language: language,
334334
timeout,
335335
});
336336
appNavigate(MatchPaths.MATCHING);
@@ -388,9 +388,9 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
388388

389389
const rematchRequest = {
390390
user: matchUser,
391-
complexities: matchCriteria.complexities,
392-
categories: matchCriteria.categories,
393-
languages: matchCriteria.languages,
391+
complexities: matchCriteria.complexity,
392+
categories: matchCriteria.category,
393+
languages: matchCriteria.language,
394394
timeout: matchCriteria.timeout,
395395
};
396396
matchSocket.emit(
@@ -416,9 +416,9 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
416416
}
417417

418418
findMatch(
419-
matchCriteria.complexities,
420-
matchCriteria.categories,
421-
matchCriteria.languages,
419+
matchCriteria.complexity,
420+
matchCriteria.category,
421+
matchCriteria.language,
422422
matchCriteria.timeout
423423
);
424424
};

frontend/src/pages/Home/index.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ import Loader from "../../components/Loader";
3434
import { toast } from "react-toastify";
3535

3636
const Home: React.FC = () => {
37-
const [complexities, setComplexities] = useState<string[]>([]);
38-
const [categories, setCategories] = useState<string[]>([]);
39-
const [languages, setLanguages] = useState<string[]>([]);
37+
const [complexity, setComplexity] = useState<string>("");
38+
const [category, setCategory] = useState<string>("");
39+
const [language, setLanguage] = useState<string>("");
4040
const [timeout, setTimeout] = useState<number | undefined>(30);
4141

4242
const [isQueryingQnDB, setIsQueryingQnDB] = useState<boolean>(false);
@@ -58,7 +58,7 @@ const Home: React.FC = () => {
5858
useEffect(() => {
5959
if (isQueryingQnDB) {
6060
if (state.questions.length > 0) {
61-
findMatch(complexities, categories, languages, timeout!);
61+
findMatch(complexity, category, language, timeout!);
6262
} else {
6363
toast.error(QUESTION_DOES_NOT_EXIST_ERROR);
6464
}
@@ -139,8 +139,8 @@ const Home: React.FC = () => {
139139
>
140140
<Autocomplete
141141
options={complexityList}
142-
onChange={(_, selectedOptions) => {
143-
setComplexities(selectedOptions ? [selectedOptions] : []);
142+
onChange={(_, selectedOption) => {
143+
setComplexity(selectedOption || "");
144144
}}
145145
renderInput={(params) => <TextField {...params} />}
146146
renderTags={(tagValue, getTagProps) =>
@@ -177,8 +177,8 @@ const Home: React.FC = () => {
177177
>
178178
<Autocomplete
179179
options={state.questionCategories}
180-
onChange={(_, selectedOptions) => {
181-
setCategories(selectedOptions ? [selectedOptions] : []);
180+
onChange={(_, selectedOption) => {
181+
setCategory(selectedOption || "");
182182
}}
183183
renderInput={(params) => <TextField {...params} />}
184184
renderTags={(tagValue, getTagProps) =>
@@ -215,8 +215,8 @@ const Home: React.FC = () => {
215215
>
216216
<Autocomplete
217217
options={languageList}
218-
onChange={(_, selectedOptions) => {
219-
setLanguages(selectedOptions ? [selectedOptions] : []);
218+
onChange={(_, selectedOption) => {
219+
setLanguage(selectedOption || "");
220220
}}
221221
renderInput={(params) => <TextField {...params} />}
222222
renderTags={(tagValue, getTagProps) =>
@@ -284,13 +284,13 @@ const Home: React.FC = () => {
284284
!timeout ||
285285
timeout < minMatchTimeout ||
286286
timeout > maxMatchTimeout ||
287-
complexities.length == 0 ||
288-
categories.length == 0 ||
289-
languages.length == 0
287+
!complexity ||
288+
!category ||
289+
!language
290290
}
291291
onClick={() => {
292292
setIsQueryingQnDB(true);
293-
getQuestionList(1, 10, "", complexities, categories, dispatch);
293+
getQuestionList(1, 10, "", [complexity], [category], dispatch);
294294
}}
295295
>
296296
{isQueryingQnDB ? <CircularProgress /> : "Find my match!"}

0 commit comments

Comments
 (0)