1
- import React from "react" ;
1
+ "use client" ;
2
+
3
+ import React , { useState , useEffect } from "react" ;
2
4
import { Button } from "@/components/ui/button" ;
3
5
import { X } from "lucide-react" ;
4
6
import Chat from "./chat" ;
5
7
import QuestionDisplay from "./question-display" ;
6
8
import CodeEditor from "./code-editor" ;
9
+ import LoadingScreen from "@/components/common/loading-screen" ;
10
+ import { getQuestion } from "@/lib/api/question-service/get-question" ;
11
+ import { useAuth } from "@/app/auth/auth-context" ;
12
+ import { getQuestionId } from "@/lib/api/collab-service/get-questionId" ;
13
+ import { Question } from "@/lib/schemas/question-schema" ;
7
14
8
15
export default function CollabRoom ( { roomId } : { roomId : string } ) {
16
+ const auth = useAuth ( ) ;
17
+ const token = auth ?. token ;
18
+
19
+ const [ question , setQuestion ] = useState < Question | null > ( null ) ;
20
+ const [ loading , setLoading ] = useState ( true ) ;
21
+
22
+ useEffect ( ( ) => {
23
+ async function fetchQuestion ( ) {
24
+ try {
25
+ // Call to the collab microservice to get questionId by roomId
26
+ const response = await getQuestionId ( roomId ) ;
27
+ const data = await response . json ( ) ;
28
+
29
+ if ( data . questionId ) {
30
+ // Fetch the question details using the questionId
31
+ if ( token ) {
32
+ const questionResponse = await getQuestion ( token , data . questionId ) ;
33
+ const questionData = await questionResponse . json ( ) ;
34
+ setQuestion ( questionData ) ;
35
+ } else {
36
+ console . error ( "Token is not available" ) ;
37
+ }
38
+ }
39
+ } catch ( error ) {
40
+ console . error ( "Error fetching question:" , error ) ;
41
+ } finally {
42
+ setLoading ( false ) ;
43
+ }
44
+ }
45
+
46
+ fetchQuestion ( ) ;
47
+ } , [ roomId ] ) ;
48
+
9
49
return (
10
50
< div className = "h-full flex flex-col mx-4 p-4" >
11
51
< header className = "flex justify-between border-b" >
@@ -17,7 +57,11 @@ export default function CollabRoom({ roomId }: { roomId: string }) {
17
57
</ header >
18
58
< div className = "flex flex-1" >
19
59
< div className = "w-2/5 p-4 flex flex-col space-y-4" >
20
- < QuestionDisplay roomId = { roomId } />
60
+ { loading ? (
61
+ < LoadingScreen />
62
+ ) : (
63
+ < QuestionDisplay question = { question } />
64
+ ) }
21
65
< Chat roomId = { roomId } />
22
66
</ div >
23
67
< CodeEditor roomId = { roomId } />
0 commit comments