Skip to content

Commit

Permalink
Merge pull request #73 from cheehongw/match-buttons
Browse files Browse the repository at this point in the history
match buttons
  • Loading branch information
Eclipse-Dominator authored Nov 15, 2023
2 parents 27390ba + 5239a14 commit c1b6049
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion frontend/src/api/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export const apiGatewayClient = axios.create({


export const wsMatchMakeURL = process.env.NODE_ENV === 'production'? 'http://peerprep-g10.com:7999' : 'http://localhost:7999'
export const wsCollabUrl = process.env.NODE_ENV === 'production'? 'ws://peerprep-g10.com:8083' :'ws://localhost:7998'
export const wsCollabUrl = process.env.NODE_ENV === 'production'? 'ws://peerprep-g10.com:8083' :'ws://localhost:8083'
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ const MatchMakeBtn = () => {
icon={<Icon as={DisconnectIcon} />}
/>
</Tooltip>
<Tooltip label="Open Chat" aria-label="collaborate">
<IconButton
aria-label="open_chat"
colorScheme="teal"
icon={<ChatIcon />}
/>
</Tooltip>
</ButtonGroup>
) : (
<Menu>
Expand All @@ -61,13 +54,15 @@ const MatchMakeBtn = () => {
<MenuButton as={Button} isLoading={isMatching}>
Collaborate
</MenuButton>
<Tooltip label="Reconnect" aria-label="collaborate">
<IconButton
aria-label="reconnect"
icon={<RepeatClockIcon />}
variant="outline"
onClick={restoreRoom}
isLoading={isMatching}
/>
</Tooltip>
</ButtonGroup>
)}

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/QnTable/QnTable.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function QnTable(pp: TableProp) {
boxShadow: "xl",
}}
width="80%"
sx={{ tableLayout: "fixed" }}
sx={{ tableLayout: "auto" }}
>
<TableCaption>
<Center>
Expand All @@ -70,6 +70,7 @@ export function QnTable(pp: TableProp) {
<Th>
<Center>Difficulty</Center>
</Th>
<Th> Match </Th>
{isAdmin ? <Th isNumeric>Modify/Delete</Th> : <></>}
</Tr>
</Thead>
Expand Down
29 changes: 25 additions & 4 deletions frontend/src/components/QnTable/QuestionEntry.component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Button,
ButtonGroup,
Center,
HStack,
Expand All @@ -15,6 +16,7 @@ import { EditIcon } from "@chakra-ui/icons";
import { useDispatch } from "react-redux";
import { delQuestion } from "../../api/questions";
import { deleteQuestion } from "../../reducers/questionsSlice";
import { useMatchmake } from "../../contexts/matchmake.context";
import { rangeToScheme } from "../../helper/DifficultyFilterHelper";

interface QuestionEntryProps {
Expand All @@ -23,7 +25,18 @@ interface QuestionEntryProps {
}

export function QuestionEntry(props: QuestionEntryProps) {

const { qn, isAdmin } = props;
const {
findMatch,
isMatching,
matchedRoom,
timeLeft,
cancelMatch,
restoreRoom,
quitRoom,
} = useMatchmake();

const dispatch = useDispatch();

const onDelete = async (_id: string) => {
Expand All @@ -38,6 +51,7 @@ export function QuestionEntry(props: QuestionEntryProps) {
<Text>{qn.displayedQuestion}</Text>
</Link>
</Td>

<Td>
<HStack spacing={1}>
{qn.topics.map((qntype) => (
Expand All @@ -50,14 +64,21 @@ export function QuestionEntry(props: QuestionEntryProps) {
<Tag colorScheme={rangeToScheme(qn.difficulty)}>{qn.difficulty}</Tag>
</Center>
</Td>
<Td>
<Button colorScheme="teal"
size='sm'
isLoading={isMatching}
onClick={() => findMatch(qn.difficulty, qn.difficulty, qn._id)}>
Look for Match
</Button>
</Td>
{isAdmin ? (
<Td isNumeric>
<ButtonGroup gap={0.1}>
<Td>
<ButtonGroup>
<Link to={`/edit/${qn._id}`}>
<IconButton
aria-label="Edit question"
icon={<EditIcon />}
colorScheme="blue"
></IconButton>
</Link>
<DeleteQnBtn
Expand All @@ -71,4 +92,4 @@ export function QuestionEntry(props: QuestionEntryProps) {
)}
</Tr>
);
}
};
5 changes: 3 additions & 2 deletions frontend/src/contexts/matchmake.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface RoomCloseResponse {
}

interface MatchmakeContextInterface {
findMatch: (diffStart: number, diffEnd: number) => void;
findMatch: (diffStart: number, diffEnd: number, qn__id?: string) => void;
cancelMatch: () => void;
quitRoom: () => void;
disconnectRoom: () => void;
Expand Down Expand Up @@ -192,7 +192,7 @@ export const MatchmakeProvider = ({
};
}, [navigate, user]);

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

Expand All @@ -205,6 +205,7 @@ export const MatchmakeProvider = ({
});
socket.emit("findMatch", {
username: user.username,
preferredQn: qn__id,
from: diffStart,
to: diffEnd,
});
Expand Down

0 comments on commit c1b6049

Please sign in to comment.