Skip to content

Commit fa13b2a

Browse files
committed
match buttons
1 parent f2a8240 commit fa13b2a

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

frontend/src/components/QnTable/QnTable.component.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function QnTable(pp: TableProp) {
5151
boxShadow: "xl",
5252
}}
5353
width="80%"
54-
sx={{ tableLayout: "fixed" }}
54+
sx={{ tableLayout: "auto" }}
5555
>
5656
<TableCaption>
5757
<Center>
@@ -67,7 +67,8 @@ export function QnTable(pp: TableProp) {
6767
<Tr boxShadow="base">
6868
<Th>Questions</Th>
6969
<Th>Type</Th>
70-
<Th>Difficulty</Th>
70+
<Th w="10%">Difficulty</Th>
71+
<Th> Match </Th>
7172
{isAdmin ? <Th>Modify/Delete</Th> : <></>}
7273
</Tr>
7374
</Thead>

frontend/src/components/QnTable/QuestionEntry.component.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ButtonGroup, HStack, IconButton, Tag, Td, Text, Tr } from "@chakra-ui/react";
1+
import { Button, ButtonGroup, HStack, IconButton, Tag, Td, Text, Tr } from "@chakra-ui/react";
22
import { Question } from "../../models/Question.model";
33
import { Link } from "react-router-dom";
44
import { DeleteQnBtn } from "../DeleteQnBtn/DeleteQnBtn.component";
@@ -7,6 +7,7 @@ import { diffToScheme } from "../../helper/UIHelper";
77
import { useDispatch } from "react-redux";
88
import { delQuestion } from "../../api/questions";
99
import { deleteQuestion } from "../../reducers/questionsSlice";
10+
import { useMatchmake } from "../../contexts/matchmake.context";
1011

1112
interface QuestionEntryProps {
1213
qn: Question,
@@ -16,6 +17,16 @@ interface QuestionEntryProps {
1617
export function QuestionEntry(props : QuestionEntryProps) {
1718

1819
const {qn, isAdmin} = props;
20+
const {
21+
findMatch,
22+
isMatching,
23+
matchedRoom,
24+
timeLeft,
25+
cancelMatch,
26+
restoreRoom,
27+
quitRoom,
28+
} = useMatchmake();
29+
1930
const dispatch = useDispatch();
2031

2132
const onDelete = async (_id: string) => {
@@ -40,6 +51,13 @@ export function QuestionEntry(props : QuestionEntryProps) {
4051
<Td>
4152
<Tag colorScheme={diffToScheme(qn.difficulty)}>{qn.difficulty}</Tag>
4253
</Td>
54+
<Td>
55+
<Button colorScheme="teal"
56+
isLoading={isMatching}
57+
onClick={() => findMatch(qn.difficulty, qn.difficulty, qn._id)}>
58+
Look for Match
59+
</Button>
60+
</Td>
4361
{isAdmin ? (
4462
<Td>
4563
<ButtonGroup>

frontend/src/contexts/matchmake.context.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface RoomCloseResponse {
2727
}
2828

2929
interface MatchmakeContextInterface {
30-
findMatch: (diffStart: number, diffEnd: number) => void;
30+
findMatch: (diffStart: number, diffEnd: number, qn__id?: string) => void;
3131
cancelMatch: () => void;
3232
quitRoom: () => void;
3333
disconnectRoom: () => void;
@@ -192,7 +192,7 @@ export const MatchmakeProvider = ({
192192
};
193193
}, [navigate, user]);
194194

195-
const findMatch = (diffStart: number, diffEnd: number) => {
195+
const findMatch = (diffStart: number, diffEnd: number, qn__id?: string) => {
196196
if (!socket || !user) return;
197197
if (!socket.connected) socket.connect();
198198

@@ -205,6 +205,7 @@ export const MatchmakeProvider = ({
205205
});
206206
socket.emit("findMatch", {
207207
username: user.username,
208+
preferredQn: qn__id,
208209
from: diffStart,
209210
to: diffEnd,
210211
});

0 commit comments

Comments
 (0)