Skip to content

Commit 796cd5f

Browse files
committed
Bug fixes and remove redundant features
1 parent f25206e commit 796cd5f

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

peerprep-fe/src/app/(main)/match/page.tsx

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,53 @@ import { User, Code } from 'lucide-react';
66
import { Button } from '@/components/ui/button';
77
import { useAuthStore } from '@/state/useAuthStore';
88
import { consumeMessageFromQueue, sendMessageToQueue } from '@/lib/rabbitmq';
9+
import { Match } from '@/types/types';
910

1011
export default function LoadingPage() {
1112
const [elapsedTime, setElapsedTime] = useState(0);
12-
const [usersWaiting, setUsersWaiting] = useState(0);
1313
const [matchStatus, setMatchStatus] = useState('searching');
1414
const router = useRouter();
1515
const { user } = useAuthStore();
1616
const listenerInitialized = useRef(false);
1717

1818
// Function to consume messages from the RabbitMQ queue
1919
const handleStartListening = () => {
20-
const onMessageReceived = (message: any) => {
20+
const onMessageReceived = (message: Match) => {
2121
if (message.status == "matched") {
22-
console.log('Match found, your partner is', message.match?.user);
22+
console.log('Match found, your partner is', message.match);
2323
setMatchStatus('matched');
2424
} else {
2525
console.log('Match failed');
2626
setMatchStatus('failed');
2727
}
2828
};
29-
consumeMessageFromQueue(user?.id!, onMessageReceived);
29+
if (user?.id) {
30+
consumeMessageFromQueue(user.id, onMessageReceived);
31+
} else {
32+
console.warn("User ID is undefined. This is not supposed to happen.");
33+
}
3034
};
3135

3236
useEffect(() => {
3337
if (!listenerInitialized.current) {
34-
setElapsedTime(0);
35-
setMatchStatus('searching');
36-
handleStartListening(); // Set up listener only once
37-
38+
handleStartListening();
3839
listenerInitialized.current = true; // Mark as initialized
40+
}
3941

40-
const interval = setInterval(() => {
41-
setElapsedTime((prevTime) => prevTime + 1);
42-
}, 1000);
42+
setElapsedTime(0);
43+
setMatchStatus('searching');
4344

44-
// Cleanup function
45-
return () => {
46-
clearInterval(interval); // Clean up interval on unmount
47-
};
48-
}
45+
const interval = setInterval(() => {
46+
setElapsedTime((prevTime) => prevTime + 1);
47+
}, 1000);
48+
49+
// Cleanup function
50+
return () => {
51+
clearInterval(interval); // Clean up interval on unmount
52+
};
4953
}, []);
5054

5155
useEffect(() => {
52-
console.log(usersWaiting);
5356
if (elapsedTime >= 60 && matchStatus === 'searching') {
5457
console.log('Elapsed time reached 60 seconds. Match timed out.');
5558
setMatchStatus('timeout');
@@ -95,10 +98,6 @@ export default function LoadingPage() {
9598
Time elapsed: {elapsedTime} seconds
9699
</div>
97100
</div>
98-
<div className="flex items-center space-x-2 text-sm">
99-
<User className="h-4 w-4" />
100-
<span>{usersWaiting} users waiting</span>
101-
</div>
102101
<Button
103102
onClick={handleCancel}
104103
className="w-full max-w-md bg-purple-600 hover:bg-purple-700"

peerprep-fe/src/types/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,18 @@ interface User {
4848
username: string;
4949
}
5050

51+
interface Match {
52+
status: string;
53+
match: string;
54+
55+
}
56+
5157
export type {
5258
Problem,
5359
ProblemDialogData,
5460
ProblemRequestData,
5561
FilterBadgeProps,
5662
FilterSelectProps,
5763
User,
64+
Match,
5865
};

0 commit comments

Comments
 (0)