@@ -3,13 +3,17 @@ import { getServerConfig, saveServerConfig, ServerConfig } from '../lib/api';
33import './ConnectionDialog.css' ;
44
55interface ConnectionDialogProps {
6- onConnect : ( config : ServerConfig ) => void ;
6+ onConnect : ( config : ServerConfig , roomId ?: string ) => void ;
77 onClose : ( ) => void ;
8+ currentRoomId ?: string ;
9+ isConnected ?: boolean ;
810}
911
10- export function ConnectionDialog ( { onConnect, onClose } : ConnectionDialogProps ) {
12+ export function ConnectionDialog ( { onConnect, onClose, currentRoomId , isConnected } : ConnectionDialogProps ) {
1113 const [ serverUrl , setServerUrl ] = useState ( ( ) => getServerConfig ( ) . url ) ;
14+ const [ roomId , setRoomId ] = useState ( currentRoomId || '' ) ;
1215 const [ isConnecting , setIsConnecting ] = useState ( false ) ;
16+ const [ copied , setCopied ] = useState ( false ) ;
1317
1418 const handleConnect = async ( ) => {
1519 setIsConnecting ( true ) ;
@@ -19,7 +23,7 @@ export function ConnectionDialog({ onConnect, onClose }: ConnectionDialogProps)
1923 enabled : true ,
2024 } ;
2125 saveServerConfig ( config ) ;
22- onConnect ( config ) ;
26+ onConnect ( config , roomId || undefined ) ;
2327 } catch ( error ) {
2428 console . error ( 'Failed to connect:' , error ) ;
2529 alert ( 'Failed to connect to server' ) ;
@@ -37,12 +41,39 @@ export function ConnectionDialog({ onConnect, onClose }: ConnectionDialogProps)
3741 onConnect ( config ) ;
3842 } ;
3943
44+ const copyRoomId = async ( ) => {
45+ if ( currentRoomId ) {
46+ await navigator . clipboard . writeText ( currentRoomId ) ;
47+ setCopied ( true ) ;
48+ setTimeout ( ( ) => setCopied ( false ) , 2000 ) ;
49+ }
50+ } ;
51+
4052 return (
41- < div className = "connection-dialog-overlay" >
42- < div className = "connection-dialog" >
43- < h2 > Excalidraw </ h2 >
53+ < div className = "connection-dialog-overlay" onClick = { onClose } >
54+ < div className = "connection-dialog" onClick = { ( e ) => e . stopPropagation ( ) } >
55+ < h2 > Server Settings </ h2 >
4456 < p > Connect to a collaboration server or work offline</ p >
4557
58+ { isConnected && currentRoomId && (
59+ < div className = "room-info" >
60+ < div className = "room-id-display" >
61+ < label > Current Room ID:</ label >
62+ < div className = "room-id-box" >
63+ < code > { currentRoomId } </ code >
64+ < button
65+ onClick = { copyRoomId }
66+ className = "btn-copy"
67+ title = "Copy room ID"
68+ >
69+ { copied ? '✓ Copied!' : '📋 Copy' }
70+ </ button >
71+ </ div >
72+ < small > Share this ID with friends to collaborate</ small >
73+ </ div >
74+ </ div >
75+ ) }
76+
4677 < div className = "input-group" >
4778 < label htmlFor = "server-url" > Server URL:</ label >
4879 < input
@@ -51,25 +82,59 @@ export function ConnectionDialog({ onConnect, onClose }: ConnectionDialogProps)
5182 value = { serverUrl }
5283 onChange = { ( e ) => setServerUrl ( e . target . value ) }
5384 placeholder = "http://localhost:3002"
85+ disabled = { isConnecting || isConnected }
86+ />
87+ </ div >
88+
89+ < div className = "input-group" >
90+ < label htmlFor = "room-id" >
91+ { isConnected ? 'Switch to Room ID:' : 'Room ID (leave blank for new room):' }
92+ </ label >
93+ < input
94+ id = "room-id"
95+ type = "text"
96+ value = { roomId }
97+ onChange = { ( e ) => setRoomId ( e . target . value ) }
98+ placeholder = { isConnected ? 'Enter room ID to switch' : 'Enter room ID or leave blank' }
5499 disabled = { isConnecting }
55100 />
56101 </ div >
57102
58103 < div className = "button-group" >
59- < button
60- onClick = { handleConnect }
61- disabled = { isConnecting || ! serverUrl }
62- className = "btn-primary"
63- >
64- { isConnecting ? 'Connecting...' : 'Connect to Server' }
65- </ button >
66- < button
67- onClick = { handleOffline }
68- disabled = { isConnecting }
69- className = "btn-secondary"
70- >
71- Work Offline
72- </ button >
104+ { ! isConnected ? (
105+ < >
106+ < button
107+ onClick = { handleConnect }
108+ disabled = { isConnecting || ! serverUrl }
109+ className = "btn-primary"
110+ >
111+ { isConnecting ? 'Connecting...' : 'Connect to Server' }
112+ </ button >
113+ < button
114+ onClick = { handleOffline }
115+ disabled = { isConnecting }
116+ className = "btn-secondary"
117+ >
118+ Work Offline
119+ </ button >
120+ </ >
121+ ) : (
122+ < >
123+ < button
124+ onClick = { handleConnect }
125+ disabled = { isConnecting || ! roomId || roomId === currentRoomId }
126+ className = "btn-primary"
127+ >
128+ Switch Room
129+ </ button >
130+ < button
131+ onClick = { onClose }
132+ className = "btn-secondary"
133+ >
134+ Close
135+ </ button >
136+ </ >
137+ ) }
73138 </ div >
74139 </ div >
75140 </ div >
0 commit comments