Skip to content

Commit c1b6049

Browse files
Merge pull request #73 from cheehongw/match-buttons
match buttons
2 parents 27390ba + 5239a14 commit c1b6049

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

frontend/src/api/gateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ export const apiGatewayClient = axios.create({
77

88

99
export const wsMatchMakeURL = process.env.NODE_ENV === 'production'? 'http://peerprep-g10.com:7999' : 'http://localhost:7999'
10-
export const wsCollabUrl = process.env.NODE_ENV === 'production'? 'ws://peerprep-g10.com:8083' :'ws://localhost:7998'
10+
export const wsCollabUrl = process.env.NODE_ENV === 'production'? 'ws://peerprep-g10.com:8083' :'ws://localhost:8083'

frontend/src/components/MatchMakeBtn/MatchMakeBtn.component.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ const MatchMakeBtn = () => {
4242
icon={<Icon as={DisconnectIcon} />}
4343
/>
4444
</Tooltip>
45-
<Tooltip label="Open Chat" aria-label="collaborate">
46-
<IconButton
47-
aria-label="open_chat"
48-
colorScheme="teal"
49-
icon={<ChatIcon />}
50-
/>
51-
</Tooltip>
5245
</ButtonGroup>
5346
) : (
5447
<Menu>
@@ -61,13 +54,15 @@ const MatchMakeBtn = () => {
6154
<MenuButton as={Button} isLoading={isMatching}>
6255
Collaborate
6356
</MenuButton>
57+
<Tooltip label="Reconnect" aria-label="collaborate">
6458
<IconButton
6559
aria-label="reconnect"
6660
icon={<RepeatClockIcon />}
6761
variant="outline"
6862
onClick={restoreRoom}
6963
isLoading={isMatching}
7064
/>
65+
</Tooltip>
7166
</ButtonGroup>
7267
)}
7368

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

Lines changed: 2 additions & 1 deletion
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>
@@ -70,6 +70,7 @@ export function QnTable(pp: TableProp) {
7070
<Th>
7171
<Center>Difficulty</Center>
7272
</Th>
73+
<Th> Match </Th>
7374
{isAdmin ? <Th isNumeric>Modify/Delete</Th> : <></>}
7475
</Tr>
7576
</Thead>

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
Button,
23
ButtonGroup,
34
Center,
45
HStack,
@@ -15,6 +16,7 @@ import { EditIcon } from "@chakra-ui/icons";
1516
import { useDispatch } from "react-redux";
1617
import { delQuestion } from "../../api/questions";
1718
import { deleteQuestion } from "../../reducers/questionsSlice";
19+
import { useMatchmake } from "../../contexts/matchmake.context";
1820
import { rangeToScheme } from "../../helper/DifficultyFilterHelper";
1921

2022
interface QuestionEntryProps {
@@ -23,7 +25,18 @@ interface QuestionEntryProps {
2325
}
2426

2527
export function QuestionEntry(props: QuestionEntryProps) {
28+
2629
const { qn, isAdmin } = props;
30+
const {
31+
findMatch,
32+
isMatching,
33+
matchedRoom,
34+
timeLeft,
35+
cancelMatch,
36+
restoreRoom,
37+
quitRoom,
38+
} = useMatchmake();
39+
2740
const dispatch = useDispatch();
2841

2942
const onDelete = async (_id: string) => {
@@ -38,6 +51,7 @@ export function QuestionEntry(props: QuestionEntryProps) {
3851
<Text>{qn.displayedQuestion}</Text>
3952
</Link>
4053
</Td>
54+
4155
<Td>
4256
<HStack spacing={1}>
4357
{qn.topics.map((qntype) => (
@@ -50,14 +64,21 @@ export function QuestionEntry(props: QuestionEntryProps) {
5064
<Tag colorScheme={rangeToScheme(qn.difficulty)}>{qn.difficulty}</Tag>
5165
</Center>
5266
</Td>
67+
<Td>
68+
<Button colorScheme="teal"
69+
size='sm'
70+
isLoading={isMatching}
71+
onClick={() => findMatch(qn.difficulty, qn.difficulty, qn._id)}>
72+
Look for Match
73+
</Button>
74+
</Td>
5375
{isAdmin ? (
54-
<Td isNumeric>
55-
<ButtonGroup gap={0.1}>
76+
<Td>
77+
<ButtonGroup>
5678
<Link to={`/edit/${qn._id}`}>
5779
<IconButton
5880
aria-label="Edit question"
5981
icon={<EditIcon />}
60-
colorScheme="blue"
6182
></IconButton>
6283
</Link>
6384
<DeleteQnBtn
@@ -71,4 +92,4 @@ export function QuestionEntry(props: QuestionEntryProps) {
7192
)}
7293
</Tr>
7394
);
74-
}
95+
};

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)