Skip to content

Commit 41dd2d6

Browse files
committed
Fix linting errors
1 parent c677a81 commit 41dd2d6

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

frontend/src/app/dashboard/_components/FindMatch/ConfirmationDialog.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ import { Ellipsis } from "lucide-react";
1818
import { UserProfile } from "@/types/User";
1919
import { getInitialsFromName } from "@/lib/utils";
2020
import { useCountdown } from "usehooks-ts";
21-
import { useEffect } from "react";
21+
import { useCallback, useEffect, useState } from "react";
2222

2323
interface ConfirmationDialogProps {
2424
user: UserProfile;
25-
2625
}
2726

2827
export default function ConfirmationDialog({ user }: ConfirmationDialogProps) {
@@ -33,36 +32,47 @@ export default function ConfirmationDialog({ user }: ConfirmationDialogProps) {
3332
handleDeclineMatch,
3433
handleAcceptMatch,
3534
} = useFindMatchContext();
36-
35+
36+
const [accepted, setAccepted] = useState(false);
37+
3738
const [counter, { startCountdown, stopCountdown, resetCountdown }] =
3839
useCountdown({
3940
countStart: 10,
4041
intervalMs: 1000,
4142
isIncrement: false,
4243
});
4344

45+
const handleAcceptClick = useCallback(() => {
46+
stopCountdown();
47+
resetCountdown();
48+
handleAcceptMatch();
49+
setAccepted(true);
50+
}, [stopCountdown, resetCountdown, handleAcceptMatch]);
51+
4452
// onComplete logic here
4553
useEffect(() => {
4654
if (counter === 0) {
4755
handleDeclineMatch();
4856
}
49-
}, [counter]);
57+
}, [counter, handleDeclineMatch]);
5058

5159
useEffect(() => {
5260
if (matchFound) {
5361
startCountdown();
62+
setAccepted(false);
5463
} else {
5564
stopCountdown();
5665
resetCountdown();
5766
}
58-
}, [matchFound]);
67+
}, [matchFound, startCountdown, stopCountdown, resetCountdown]);
5968

6069
return (
6170
<AlertDialog open={matchFound}>
6271
<AlertDialogContent className="flex flex-col gap-12">
6372
<AlertDialogHeader>
6473
<AlertDialogTitle>
65-
You have found a match ({counter}s)
74+
You have{" "}
75+
{accepted ? "accepted the match" : `found a match (${counter}s)`}
6676
</AlertDialogTitle>
6777
<AlertDialogDescription>
6878
Once you have accepted the match, you will be redirected to another
@@ -90,7 +100,7 @@ export default function ConfirmationDialog({ user }: ConfirmationDialogProps) {
90100
</AlertDialogCancel>
91101
<AlertDialogAction
92102
disabled={isAwaitingConfirmation}
93-
onClick={handleAcceptMatch}
103+
onClick={handleAcceptClick}
94104
>
95105
{isAwaitingConfirmation
96106
? "Waiting for other user to accept"

frontend/src/app/dashboard/_components/FindMatch/ContinueDialog.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ export default function ContinueDialog() {
3535
handleCancelMatch();
3636
setShowContinueDialog(false);
3737
stopCountdown();
38-
}, []);
38+
}, [handleCancelMatch, setShowContinueDialog, stopCountdown]);
3939

4040
const handleContinue = useCallback(() => {
4141
handleFindMatch();
4242
setShowContinueDialog(false);
43-
}, []);
43+
}, [handleFindMatch, setShowContinueDialog]);
4444

4545
// onComplete logic here
4646
useEffect(() => {
4747
if (counter === 0) {
4848
handleCancel();
4949
}
50-
}, [counter]);
50+
}, [counter, handleCancel]);
5151

5252
useEffect(() => {
5353
if (showContinueDialog) {
@@ -56,7 +56,7 @@ export default function ContinueDialog() {
5656
stopCountdown();
5757
resetCountdown();
5858
}
59-
}, [showContinueDialog]);
59+
}, [showContinueDialog, startCountdown, stopCountdown, resetCountdown]);
6060

6161
return (
6262
<AlertDialog open={showContinueDialog}>

frontend/src/contexts/FindMatchContext.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ export function FindMatchProvider({
5454
children,
5555
}: PropsWithChildren<FindMatchProviderProps>) {
5656
const { toast } = useToast();
57-
58-
const [difficulty, setDifficulty] = useState<Difficulty>(DifficultyEnum.enum.Medium);
57+
58+
const [difficulty, setDifficulty] = useState<Difficulty>(
59+
DifficultyEnum.enum.Medium
60+
);
5961

6062
const [topics, setTopics] = useState<Category[]>(["Array"]);
6163

@@ -250,7 +252,7 @@ export function FindMatchProvider({
250252
clearTimeout(timer);
251253
};
252254
}
253-
}, [findingMatch]);
255+
}, [findingMatch, handleCancelMatch]);
254256

255257
// Reset state
256258
function reset() {

0 commit comments

Comments
 (0)