Skip to content

Commit b1653d0

Browse files
committed
add collab page
1 parent 82d5267 commit b1653d0

File tree

6 files changed

+35
-28
lines changed

6 files changed

+35
-28
lines changed

peerprep-fe/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"zustand": "5.0.0-rc.2"
3838
},
3939
"devDependencies": {
40+
"@types/amqplib": "^0.10.5",
4041
"@types/node": "^20",
4142
"@types/react": "^18",
4243
"@types/react-dom": "^18",

peerprep-fe/pnpm-lock.yaml

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,32 @@ import { useRouter } from 'next/navigation';
55
import { User, Code } from 'lucide-react';
66
import { consumeMessageFromQueue } from '@/lib/rabbitmq';
77
import { Button } from '@/components/ui/button';
8+
import { useAuthStore } from '@/state/useAuthStore';
89

910
export default function LoadingPage() {
1011
const [elapsedTime, setElapsedTime] = useState(0);
1112
const [usersWaiting, setUsersWaiting] = useState(4);
1213
const [matchStatus, setMatchStatus] = useState('searching');
1314
const router = useRouter();
15+
const { user } = useAuthStore();
1416

1517
const startConsumingMessages = async () => {
1618
try {
17-
await consumeMessageFromQueue().then((message) => {
19+
await consumeMessageFromQueue(user?.id!).then((message) => {
1820
if (message.status === 'matched') {
1921
console.log('Match found, your partner is', message.partner);
2022
setMatchStatus('matched');
21-
// Redirect to the collaboration page after a short delay
23+
2224
setTimeout(() => {
23-
router.push(`/collaboration/${message.roomId}`);
25+
router.push(`/collaboration`);
2426
}, 2000);
2527
} else {
2628
console.log('Match failed');
2729
setMatchStatus('failed');
30+
31+
setTimeout(() => {
32+
router.push(`/`);
33+
}, 2000);
2834
}
2935
});
3036
} catch (error) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
3+
type Props = {};
4+
5+
const page = (props: Props) => {
6+
return <div>This is the collaboration page</div>;
7+
};
8+
9+
export default page;

peerprep-fe/src/components/navbar/Navbar.tsx

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,6 @@ export default function Navbar() {
2626
}
2727
};
2828

29-
// const getProfileDetails = async () => {
30-
// const result = await axiosAuthClient.get('/auth/verify-token');
31-
// return result.data.data;
32-
// };
33-
34-
// const handleMatchClick = async () => {
35-
// try {
36-
// const profileDetails = await getProfileDetails();
37-
// const message = {
38-
// _id: profileDetails.id,
39-
// name: profileDetails.username,
40-
// topic: 'TO BE ADDED',
41-
// difficulty: 'TO BE ADDED',
42-
// };
43-
// await sendMessageToQueue(message);
44-
// } catch (err) {
45-
// console.error('Error in handleMatchClick:', err);
46-
// }
47-
// };
48-
4929
return (
5030
<nav className="fixed top-0 z-10 w-full bg-gray-800 p-4">
5131
<div className="mx-auto flex max-w-7xl items-center justify-between">

peerprep-fe/src/lib/rabbitmq.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'use server';
33

44
import { connect } from 'amqplib';
5+
import { redirect } from 'next/navigation';
56

67
export const sendMessageToQueue = async (message: Record<string, any>) => {
78
try {
@@ -36,14 +37,14 @@ export const sendMessageToQueue = async (message: Record<string, any>) => {
3637
}
3738
};
3839

39-
export const consumeMessageFromQueue = async () => {
40+
export const consumeMessageFromQueue = async (queue: string) => {
4041
return new Promise<any>((resolve, reject) => {
4142
(async () => {
4243
try {
4344
// Connect to RabbitMQ server
4445
const connection = await connect(process.env.RABBITMQ_URL!);
4546
const channel = await connection.createChannel();
46-
const queue = process.env.MATCHING_SERVICE_QUEUE!;
47+
// const queue = process.env.MATCHING_SERVICE_QUEUE!;
4748

4849
// Ensure the queue exists
4950
await channel.assertQueue(queue, { durable: true });

0 commit comments

Comments
 (0)