Skip to content

Commit c3714e1

Browse files
committed
Integrate with new matchmaking changes
Also some fixes for timer display
1 parent b0d0726 commit c3714e1

File tree

7 files changed

+32
-67
lines changed

7 files changed

+32
-67
lines changed

apps/frontend/src/app/match/page.tsx

Lines changed: 0 additions & 55 deletions
This file was deleted.

apps/frontend/src/app/match/styles.scss

Lines changed: 0 additions & 1 deletion
This file was deleted.

apps/frontend/src/app/matching/MatchingModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const MatchingModal: React.FC<MatchingModalProps> = ({ isOpen, close: _close })
7979
}}
8080
/>
8181
case 'timeout':
82-
return <MatchNotFoundContent reselect={matchingState.ok} retry={() => {}} timedOutIn={timeoutAfter}/>;
82+
return <MatchNotFoundContent reselect={matchingState.ok} retry={() => {}} timedOutIn={10}/>;
8383
default:
8484
throw new Error('Invalid matching state.');
8585
}

apps/frontend/src/app/matching/modalContent/FindMatchContent.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
import type { SelectProps } from 'antd';
1212
import 'typeface-montserrat';
1313
import './styles.scss';
14-
import { handleFindMatch } from '../handlers';
15-
import useMatching, { type MatchRequestParams } from '@/app/services/use-matching';
14+
import { ValidateUser } from "@/app/services/user"
15+
import { type MatchRequestParams } from '@/app/services/use-matching';
1616

1717
interface DifficultySelectorProps {
1818
className?: string;
@@ -33,6 +33,7 @@ interface Props {
3333
const FindMatchContent: React.FC<Props> = ({ beginMatch }) => {
3434
const [selectedDifficulties, setSelectedDifficulties] = useState<string[]>([]);
3535
const [selectedTopics, setSelectedTopics] = useState<string[]>([]);
36+
const [isLoading, setIsLoading] = useState(false);
3637

3738
const handleDifficultyChange = (difficulties: string[]) => {
3839
setSelectedDifficulties(difficulties);
@@ -60,13 +61,28 @@ const FindMatchContent: React.FC<Props> = ({ beginMatch }) => {
6061
/>
6162
</div>
6263
<button className="find-match-button"
63-
onClick={() => {
64+
onClick={async () => {
65+
66+
async function ValidateUser() {
67+
return {
68+
data: {
69+
email: "asda",
70+
username: "sajdhkas"
71+
}
72+
}
73+
}
74+
75+
setIsLoading(true);
76+
const user = await ValidateUser();
6477
beginMatch({
78+
email: user.data.email,
79+
username: user.data.username,
6580
type: "match_request",
6681
difficulties: selectedDifficulties,
6782
topics: selectedTopics,
6883
})
6984
}}
85+
disabled={isLoading}
7086
>
7187
Find Match
7288
</button>

apps/frontend/src/app/matching/modalContent/MatchFoundContent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const TIMEOUT = 10;
1616

1717
const MatchFoundContent: React.FC<Props> = ({join, cancel}) => {
1818
const { totalSeconds } = useTimer({
19-
expiryTimestamp: new Date(TIMEOUT * 1000),
19+
expiryTimestamp: new Date(Date.now() + 10 * 1000),
20+
onExpire: join
2021
});
2122

2223
return (

apps/frontend/src/app/matching/modalContent/MatchingInProgressContent.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ interface Props {
1414
}
1515

1616
const MatchingInProgressContent: React.FC<Props> = ({cancelMatch: cancel, timeout}) => {
17-
const time = new Date();
18-
time.setSeconds(time.getSeconds() + TIMEOUT);
1917
const { totalSeconds } = useTimer({
20-
expiryTimestamp: time,
21-
onExpire: () => timeout(TIMEOUT),
18+
expiryTimestamp: new Date(Date.now() + 10 * 1000),
19+
onExpire: () => timeout(TIMEOUT - totalSeconds),
2220
});
2321

2422
return (
@@ -31,7 +29,7 @@ const MatchingInProgressContent: React.FC<Props> = ({cancelMatch: cancel, timeou
3129
</div>
3230
<button className="cancel-match-button"
3331
onClick={() => {
34-
timeout(TIMEOUT);
32+
cancel(TIMEOUT - totalSeconds);
3533
}}
3634
>
3735
Cancel

apps/frontend/src/app/services/use-matching.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ if (MATCHING_SERVICE_URL == undefined) {
1010

1111
export type MatchRequestParams = {
1212
type: "match_request",
13+
username: string,
14+
email: string,
1315
topics: string[],
1416
difficulties: string[],
1517
}
@@ -26,6 +28,11 @@ export type MatchTimeoutResponse = {
2628
message: string,
2729
}
2830

31+
export type MatchRejectedResponse = {
32+
type: "match_rejected",
33+
message: string,
34+
}
35+
2936
type MatchResponse = MatchFoundResponse | MatchTimeoutResponse;
3037

3138
export default function useMatching(): MatchState {
@@ -41,7 +48,6 @@ export default function useMatching(): MatchState {
4148
},
4249
onMessage({data: response}) {
4350
const responseJson: MatchResponse = JSON.parse(response);
44-
console.log("got here");
4551
if (responseJson.type == "timeout") {
4652
timeout();
4753
return;

0 commit comments

Comments
 (0)