@@ -19,26 +19,34 @@ import React, { useCallback, useEffect, useRef, useState } from 'react';
1919import { useSearchParams } from 'next/navigation' ;
2020import * as Y from 'yjs' ;
2121import { WebsocketProvider } from 'y-websocket' ;
22- import { MonacoBinding } from 'y-monaco'
22+ import { MonacoBinding } from 'y-monaco' ;
2323import { editor as MonacoEditor } from 'monaco-editor' ;
2424
2525const CollaborationPage = ( ) => {
26- const [ selectionProblem , setSelectionProblem ] = useState < Problem | null > ( null ) ;
26+ const [ selectionProblem , setSelectionProblem ] = useState < Problem | null > (
27+ null ,
28+ ) ;
2729 const searchParams = useSearchParams ( ) ;
2830 const matchId = searchParams . get ( 'matchId' ) ;
2931 const [ language , setLanguage ] = useState ( SUPPORTED_PROGRAMMING_LANGUAGES [ 0 ] ) ;
3032 const { problems, isLoading } = useFilteredProblems ( ) ;
31- const [ connectedClients , setConnectedClients ] = useState < Set < number > > ( new Set ( ) ) ;
32- const [ disconnectionAlert , setDisconnectionAlert ] = useState < string | null > ( null ) ;
33+ const [ connectedClients , setConnectedClients ] = useState < Set < number > > (
34+ new Set ( ) ,
35+ ) ;
36+ const [ disconnectionAlert , setDisconnectionAlert ] = useState < string | null > (
37+ null ,
38+ ) ;
3339
3440 // Layout states
3541 const [ leftWidth , setLeftWidth ] = useState ( 50 ) ;
3642 const isDragging = useRef ( false ) ;
3743 const containerRef = useRef < HTMLDivElement > ( null ) ;
3844 const providerRef = useRef < WebsocketProvider | null > ( null ) ;
3945 const bindingRef = useRef < MonacoBinding | null > ( null ) ;
40- const editorRef = React . useRef < MonacoEditor . IStandaloneCodeEditor | null > ( null ) ;
41- const sockServerURI = process . env . SOCK_SERVER_URL || "ws://localhost:4444" ;
46+ const editorRef = React . useRef < MonacoEditor . IStandaloneCodeEditor | null > (
47+ null ,
48+ ) ;
49+ const sockServerURI = process . env . SOCK_SERVER_URL || 'ws://localhost:4444' ;
4250
4351 // Handle dragging of the divider
4452 const handleMouseDown = useCallback ( ( ) => {
@@ -68,21 +76,21 @@ const CollaborationPage = () => {
6876
6977 const handleEditorMount = ( editor : any , monaco : any ) => {
7078 if ( ! matchId ) {
71- console . error ( " Cannot mount editor: Match ID is undefined" ) ;
79+ console . error ( ' Cannot mount editor: Match ID is undefined' ) ;
7280 return ;
7381 }
7482 editorRef . current = editor ;
7583 const doc = new Y . Doc ( ) ;
7684 providerRef . current = new WebsocketProvider ( sockServerURI , matchId , doc ) ;
77- const type = doc . getText ( " monaco" ) ;
85+ const type = doc . getText ( ' monaco' ) ;
7886
7987 // Set up awareness handling
8088 providerRef . current . awareness . setLocalState ( {
8189 client : Math . floor ( Math . random ( ) * 1000000 ) , // Generate random client ID
8290 user : {
8391 name : `User ${ Math . floor ( Math . random ( ) * 100 ) } ` , // You can replace this with actual user info
84- color : `#${ Math . floor ( Math . random ( ) * 16777215 ) . toString ( 16 ) } ` // Random color
85- }
92+ color : `#${ Math . floor ( Math . random ( ) * 16777215 ) . toString ( 16 ) } ` , // Random color
93+ } ,
8694 } ) ;
8795
8896 // Handle client updates
@@ -111,13 +119,13 @@ const CollaborationPage = () => {
111119 const model = editorRef . current ?. getModel ( ) ;
112120 if ( editorRef . current && model ) {
113121 bindingRef . current = new MonacoBinding (
114- type ,
115- model ,
116- new Set ( [ editorRef . current ] ) ,
117- providerRef . current . awareness
122+ type ,
123+ model ,
124+ new Set ( [ editorRef . current ] ) ,
125+ providerRef . current . awareness ,
118126 ) ;
119127 } else {
120- console . error ( " Monaco editor model is null" ) ;
128+ console . error ( ' Monaco editor model is null' ) ;
121129 }
122130 } ;
123131
@@ -212,12 +220,10 @@ const CollaborationPage = () => {
212220 </ div >
213221 </ div >
214222
215- < ProblemCodeEditor
216- onMount = { handleEditorMount }
217- />
223+ < ProblemCodeEditor onMount = { handleEditorMount } />
218224 </ div >
219225 </ div >
220226 ) ;
221227} ;
222228
223- export default CollaborationPage ;
229+ export default CollaborationPage ;
0 commit comments