@@ -6,46 +6,42 @@ function App() {
66 const [ currentRoom , setCurrentRoom ] = useState < string | null > ( null ) ;
77 const [ isCreatingRoom , setIsCreatingRoom ] = useState ( false ) ;
88 const [ isJoiningFromLink , setIsJoiningFromLink ] = useState ( false ) ;
9+ const [ isHost , setIsHost ] = useState ( false ) ;
10+ const [ hostSessionId , setHostSessionId ] = useState ( '' ) ;
911
1012 useEffect ( ( ) => {
11- // Check for room ID in URL params when component mounts
1213 const checkUrlParams = ( ) => {
1314 const urlParams = new URLSearchParams ( window . location . search ) ;
1415 const roomId = urlParams . get ( 'room' ) ;
15-
16- console . log ( 'URL params check:' , { roomId, search : window . location . search } ) ;
17-
16+
1817 if ( roomId && roomId . trim ( ) ) {
19- console . log ( 'Found room ID in URL:' , roomId ) ;
2018 setIsJoiningFromLink ( true ) ;
21-
22- // Small delay to show joining state
19+ setIsHost ( false ) ;
20+ setHostSessionId ( '' ) ;
21+
2322 setTimeout ( ( ) => {
2423 setCurrentRoom ( roomId . trim ( ) . toUpperCase ( ) ) ;
2524 setIsJoiningFromLink ( false ) ;
2625 } , 1000 ) ;
2726 }
2827 } ;
2928
30- // Check immediately
3129 checkUrlParams ( ) ;
32-
33- // Also check after a small delay in case URL changes
3430 const timeoutId = setTimeout ( checkUrlParams , 100 ) ;
35-
3631 return ( ) => clearTimeout ( timeoutId ) ;
3732 } , [ ] ) ;
3833
39- // Listen for URL changes (back/forward navigation)
4034 useEffect ( ( ) => {
4135 const handlePopState = ( ) => {
4236 const urlParams = new URLSearchParams ( window . location . search ) ;
4337 const roomId = urlParams . get ( 'room' ) ;
44-
38+
4539 if ( roomId && roomId . trim ( ) ) {
4640 setCurrentRoom ( roomId . trim ( ) . toUpperCase ( ) ) ;
41+ setIsHost ( false ) ;
4742 } else {
4843 setCurrentRoom ( null ) ;
44+ setIsHost ( false ) ;
4945 }
5046 } ;
5147
@@ -57,12 +53,18 @@ function App() {
5753 return Math . random ( ) . toString ( 36 ) . substring ( 2 , 12 ) . toUpperCase ( ) ;
5854 } ;
5955
56+ const generateSessionId = ( ) : string => {
57+ return Math . random ( ) . toString ( 36 ) . substring ( 2 ) + Date . now ( ) . toString ( 36 ) ;
58+ } ;
59+
6060 const handleCreateRoom = ( ) => {
6161 setIsCreatingRoom ( true ) ;
6262 setTimeout ( ( ) => {
6363 const roomId = generateRoomId ( ) ;
64+ const sessionId = generateSessionId ( ) ;
6465 setCurrentRoom ( roomId ) ;
65- // Update URL without page reload
66+ setIsHost ( true ) ;
67+ setHostSessionId ( sessionId ) ;
6668 window . history . pushState ( { } , '' , `?room=${ roomId } ` ) ;
6769 setIsCreatingRoom ( false ) ;
6870 } , 1500 ) ;
@@ -72,29 +74,22 @@ function App() {
7274 if ( roomId && roomId . trim ( ) ) {
7375 const cleanRoomId = roomId . trim ( ) . toUpperCase ( ) ;
7476 setCurrentRoom ( cleanRoomId ) ;
75- // Update URL without page reload
77+ setIsHost ( false ) ;
78+ setHostSessionId ( '' ) ;
7679 window . history . pushState ( { } , '' , `?room=${ cleanRoomId } ` ) ;
7780 }
7881 } ;
7982
8083 const handleLeaveRoom = ( ) => {
8184 setCurrentRoom ( null ) ;
82- // Clear URL params
85+ setIsHost ( false ) ;
86+ setHostSessionId ( '' ) ;
8387 window . history . pushState ( { } , '' , window . location . pathname ) ;
8488 } ;
8589
86- // Debug logging
87- console . log ( 'App state:' , {
88- currentRoom,
89- isCreatingRoom,
90- isJoiningFromLink,
91- urlSearch : window . location . search
92- } ) ;
93-
94- // Show joining state when accessing via shared link
9590 if ( isJoiningFromLink ) {
9691 return (
97- < div className = "min-h-screen bg-gradient-to-br from-slate-900 via-purple-900 to-slate-900 flex items-center justify-center" >
92+ < div className = "min-h-screen bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900 flex items-center justify-center" >
9893 < div className = "text-center" >
9994 < div className = "inline-flex items-center justify-center w-16 h-16 bg-emerald-500/20 rounded-full mb-6" >
10095 < div className = "w-8 h-8 border-2 border-emerald-400/30 border-t-emerald-400 rounded-full animate-spin" > </ div >
@@ -107,10 +102,9 @@ function App() {
107102 ) ;
108103 }
109104
110- // Show creating room state
111105 if ( isCreatingRoom ) {
112106 return (
113- < div className = "min-h-screen bg-gradient-to-br from-slate-900 via-purple-900 to-slate-900 flex items-center justify-center" >
107+ < div className = "min-h-screen bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900 flex items-center justify-center" >
114108 < div className = "text-center" >
115109 < div className = "inline-flex items-center justify-center w-16 h-16 bg-blue-500/20 rounded-full mb-6" >
116110 < div className = "w-8 h-8 border-2 border-blue-400/30 border-t-blue-400 rounded-full animate-spin" > </ div >
@@ -122,13 +116,18 @@ function App() {
122116 ) ;
123117 }
124118
125- // Show chat room if user is in a room
126119 if ( currentRoom ) {
127- return < ChatRoom roomId = { currentRoom } onLeave = { handleLeaveRoom } /> ;
120+ return (
121+ < ChatRoom
122+ roomId = { currentRoom }
123+ isHost = { isHost }
124+ hostSessionId = { hostSessionId }
125+ onLeave = { handleLeaveRoom }
126+ />
127+ ) ;
128128 }
129129
130- // Show landing page
131130 return < Landing onCreateRoom = { handleCreateRoom } onJoinRoom = { handleJoinRoom } /> ;
132131}
133132
134- export default App ;
133+ export default App ;
0 commit comments