1
+ "use client"
2
+
1
3
import React , { useState , useEffect } from 'react' ;
2
4
import {
3
5
Form ,
@@ -15,7 +17,7 @@ import MatchCancelledContent from './modalContent/MatchCancelledContent';
15
17
import useMatching from '../services/use-matching' ;
16
18
import { ValidateUser } from '../services/user' ;
17
19
import { useTimer } from 'react-timer-hook' ;
18
- import { useRouter } from 'next/router ' ;
20
+ import { useRouter } from 'next/navigation ' ;
19
21
20
22
interface MatchingModalProps {
21
23
isOpen : boolean ;
@@ -43,23 +45,22 @@ const MatchingModal: React.FC<MatchingModalProps> = ({ isOpen, close: _close })
43
45
return ;
44
46
}
45
47
if ( matchingState . state === "found" ) {
46
- matchingState . ok ( ) ;
47
- setClosedType ( "joined" ) ;
48
+ join ( ) ;
48
49
return ;
49
50
}
50
51
console . warn ( `matching is in ${ matchingState . state } ` )
51
52
} ,
52
53
} ) ;
53
54
const passed = MATCH_TIMEOUT - totalSeconds ;
54
55
55
- function close ( ) {
56
- // clean up matching and closedType State
57
- if ( matchingState . state === "timeout" ) {
58
- matchingState . ok ( ) ;
56
+ function close ( ) {
57
+ // clean up matching and closedType State
58
+ if ( matchingState . state === "timeout" ) {
59
+ matchingState . ok ( ) ;
60
+ }
61
+ setClosedType ( "finding" ) ;
62
+ _close ( ) ;
59
63
}
60
- setClosedType ( "finding" ) ;
61
- _close ( ) ;
62
- }
63
64
64
65
const startMatch = matchingState . state == "closed" || matchingState . state == "timeout" ? async ( params : MatchParams ) : Promise < void > => {
65
66
const user = await ValidateUser ( ) ;
@@ -75,6 +76,22 @@ const MatchingModal: React.FC<MatchingModalProps> = ({ isOpen, close: _close })
75
76
...params
76
77
} ) ;
77
78
} : undefined ;
79
+
80
+ const join = matchingState . state == "found" ? ( ( ) => {
81
+ matchingState . ok ( ) ;
82
+ setClosedType ( "joined" ) ;
83
+ localStorage . setItem ( "user" , matchingState . info . user ) ;
84
+ localStorage . setItem (
85
+ "matchedUser" ,
86
+ matchingState . info . matchedUser
87
+ ) ;
88
+ localStorage . setItem ( "collabId" , matchingState . info . matchId ) ;
89
+ localStorage . setItem ( "questionDocRefId" , matchingState . info . questionDocRefId ) ;
90
+ localStorage . setItem ( "matchedTopics" , matchingState . info . matchedTopics . join ( "," ) ) ;
91
+
92
+ // Redirect to collaboration page
93
+ router . push ( `/collaboration/${ matchingState . info . matchId } ` ) ;
94
+ } ) : ( ) => { throw new Error ( "join called when not found" ) ; }
78
95
79
96
useEffect ( ( ) => {
80
97
if ( matchingState . state === "cancelling" || matchingState . state === "timeout" ) {
@@ -129,21 +146,7 @@ const MatchingModal: React.FC<MatchingModalProps> = ({ isOpen, close: _close })
129
146
matchingState . ok ( ) ;
130
147
setClosedType ( "cancelled" ) ;
131
148
} }
132
- join = { ( ) => {
133
- matchingState . ok ( ) ;
134
- setClosedType ( "joined" ) ;
135
- localStorage . setItem ( "user" , matchingState . info . user ) ;
136
- localStorage . setItem (
137
- "matchedUser" ,
138
- matchingState . info . matchedUser
139
- ) ;
140
- localStorage . setItem ( "collabId" , matchingState . info . matchId ) ;
141
- localStorage . setItem ( "questionDocRefId" , matchingState . info . questionDocRefId ) ;
142
- localStorage . setItem ( "matchedTopics" , matchingState . info . matchedTopics . join ( "," ) ) ;
143
-
144
- // Redirect to collaboration page
145
- router . push ( `/collaboration/${ matchingState . info . matchId } ` ) ;
146
- } }
149
+ join = { join }
147
150
name1 = { matchingState . info . user }
148
151
name2 = { matchingState . info . matchedUser }
149
152
joiningIn = { totalSeconds }
0 commit comments