1
1
"use client" ;
2
2
3
- import React , { useState , useEffect } from "react" ;
3
+ import React , { useState } from "react" ;
4
4
import { Button } from "@/components/ui/button" ;
5
5
import { X } from "lucide-react" ;
6
6
import Chat from "./chat" ;
7
7
import QuestionDisplay from "./question-display" ;
8
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" ;
14
- import { useToast } from "@/components/hooks/use-toast" ;
15
9
import Link from "next/link" ;
10
+ import { Question } from "@/lib/schemas/question-schema" ;
16
11
17
12
export default function CollabRoom ( { roomId } : { roomId : string } ) {
18
- const auth = useAuth ( ) ;
19
- const token = auth ?. token ;
20
- const { toast } = useToast ( ) ;
21
-
22
- const [ question , setQuestion ] = useState < Question | null > ( null ) ;
23
- const [ loading , setLoading ] = useState ( true ) ;
24
13
const [ code , setCode ] = useState < string > ( "" ) ;
25
-
26
- useEffect ( ( ) => {
27
- async function fetchQuestion ( ) {
28
- try {
29
- if ( ! auth || ! auth . token ) {
30
- toast ( {
31
- title : "Access denied" ,
32
- description : "No authentication token found" ,
33
- variant : "destructive" ,
34
- } ) ;
35
- return ;
36
- }
37
-
38
- // Call to the collab microservice to get questionId by roomId
39
- const response = await getQuestionId ( auth . token , roomId ) ;
40
- const data = await response . json ( ) ;
41
-
42
- if ( data . questionId ) {
43
- // Fetch the question details using the questionId
44
- if ( token ) {
45
- const questionResponse = await getQuestion ( token , data . questionId ) ;
46
- const questionData = await questionResponse . json ( ) ;
47
- setQuestion ( questionData ) ;
48
- } else {
49
- console . error ( "Token is not available" ) ;
50
- }
51
- }
52
- } catch ( error ) {
53
- console . error ( "Error fetching question:" , error ) ;
54
- } finally {
55
- setLoading ( false ) ;
56
- }
57
- }
58
-
59
- fetchQuestion ( ) ;
60
- } , [ roomId ] ) ;
61
-
14
+ const [ exposedQuestion , setExposedQuestion ] = useState < Question | null > ( null ) ;
62
15
return (
63
16
< div className = "h-screen flex flex-col mx-4 p-4 overflow-hidden" >
64
17
< header className = "flex justify-between border-b" >
@@ -72,12 +25,11 @@ export default function CollabRoom({ roomId }: { roomId: string }) {
72
25
</ header >
73
26
< div className = "flex flex-1 overflow-hidden" >
74
27
< div className = "w-2/5 p-4 flex flex-col space-y-4 overflow-hidden" >
75
- { loading ? (
76
- < LoadingScreen />
77
- ) : (
78
- < QuestionDisplay question = { question } />
79
- ) }
80
- < Chat roomId = { roomId } question = { question } code = { code } />
28
+ < QuestionDisplay
29
+ roomId = { roomId }
30
+ setExposedQuestion = { setExposedQuestion }
31
+ />
32
+ < Chat roomId = { roomId } question = { exposedQuestion } code = { code } />
81
33
</ div >
82
34
< CodeEditor roomId = { roomId } setCode = { setCode } />
83
35
</ div >
0 commit comments