1
1
'use client' ;
2
2
3
3
import { useState , useEffect } from 'react' ;
4
- import { useRouter } from 'next/router ' ;
4
+ import { useRouter } from 'next/navigation ' ;
5
5
import { User , Code } from 'lucide-react' ;
6
6
import { consumeMessageFromQueue } from '@/lib/rabbitmq' ;
7
7
@@ -10,7 +10,25 @@ export default function LoadingPage() {
10
10
const [ usersWaiting , setUsersWaiting ] = useState ( 4 ) ;
11
11
const router = useRouter ( ) ;
12
12
13
+ const startConsumingMessages = async ( ) => {
14
+ try {
15
+ await consumeMessageFromQueue ( ) . then ( ( message ) => {
16
+ // This function is called when a message is consumed
17
+ if ( message . status == 'matched' ) {
18
+ console . log ( 'Match found, your partner is' ) ;
19
+ router . push ( '/' ) ;
20
+ } else {
21
+ console . log ( 'Match failed' ) ;
22
+ router . push ( '/' ) ;
23
+ }
24
+ } ) ;
25
+ } catch ( error ) {
26
+ console . error ( 'Error consuming message:' , error ) ;
27
+ }
28
+ } ;
29
+
13
30
useEffect ( ( ) => {
31
+ startConsumingMessages ( ) ;
14
32
const timer = setInterval ( ( ) => {
15
33
setElapsedTime ( ( prevTime ) => prevTime + 1 ) ;
16
34
} , 1000 ) ;
@@ -26,28 +44,6 @@ export default function LoadingPage() {
26
44
}
27
45
} , [ elapsedTime ] ) ;
28
46
29
- useEffect ( ( ) => {
30
- // Start consuming messages from the queue when the component mounts
31
- const startConsumingMessages = async ( ) => {
32
- try {
33
- await consumeMessageFromQueue ( ) . then ( ( message ) => {
34
- // This function is called when a message is consumed
35
- if ( message . status == 'matched' ) {
36
- console . log ( 'Match found, your partner is' ) ;
37
- router . push ( '/' ) ;
38
- } else {
39
- console . log ( 'Match failed' ) ;
40
- router . push ( '/' ) ;
41
- }
42
- } ) ;
43
- } catch ( error ) {
44
- console . error ( 'Error consuming message:' , error ) ;
45
- }
46
- } ;
47
-
48
- startConsumingMessages ( ) ;
49
- } , [ ] ) ;
50
-
51
47
return (
52
48
< div className = "flex min-h-screen flex-col bg-[#1a1f2e] text-gray-300" >
53
49
< header className = "flex items-center justify-between border-b border-gray-700 p-4" >
0 commit comments