11import { Send , Code , Image , Play , Eye , LogOut , Mic , Video } from 'lucide-react' ;
2- import { useState } from 'react' ;
2+ import { useEffect , useState } from 'react' ;
33import ConfirmDialog from '../../components/ConfirmDialog' ;
4+ import { ChatPanel } from './ChatPanel' ;
5+ import YPartyKitProvider from 'y-partykit/provider' ;
6+ import type { AwarenessUser } from '../hooks/useCollabRoom' ;
47
58export default function SubmissionPanel ( {
69 isPenaltyOver,
710 handleLeaveRoom,
11+ provider,
812} : {
913 isPenaltyOver : boolean ;
1014 handleLeaveRoom : ( ) => void ;
15+ provider : YPartyKitProvider | null ;
1116} ) {
1217 const [ isDialogOpen , setIsDialogOpen ] = useState ( false ) ;
18+ const [ users , setUsers ] = useState < AwarenessUser [ ] > ( [ ] ) ;
1319
1420 function handleEndSession ( ) {
1521 setIsDialogOpen ( true ) ;
@@ -25,52 +31,67 @@ export default function SubmissionPanel({
2531 }
2632 handleLeaveRoom ( ) ;
2733 }
34+
35+ useEffect ( ( ) => {
36+ if ( ! provider ) {
37+ setUsers ( [ ] ) ;
38+ return ;
39+ }
40+
41+ const awareness = provider . awareness ; // Get awareness from the provider
42+
43+ const updateUsers = ( ) => {
44+ const states = Array . from ( awareness . getStates ( ) . values ( ) ) ;
45+ const userList = states . map ( state => state . user ) . filter ( Boolean ) as AwarenessUser [ ] ;
46+ setUsers ( userList ) ;
47+ } ;
48+
49+ awareness . on ( 'change' , updateUsers ) ;
50+ updateUsers ( ) ; // Initial load
51+
52+ return ( ) => {
53+ awareness . off ( 'change' , updateUsers ) ;
54+ setUsers ( [ ] ) ; // Cleanup state
55+ } ;
56+ } , [ provider ] ) ;
57+
58+ const localUser = provider ?. awareness . getLocalState ( ) ?. user as AwarenessUser | undefined ;
59+
60+ // Find the first user in the list who is not the local user
61+ const otherUser = users . find ( u => u . name !== localUser ?. name ) ;
62+
2863 return (
2964 < div className = "w-96 bg-white border-l border-gray-200 flex flex-col" >
3065 { /* User Avatars */ }
3166 < div className = "p-4 border-b border-gray-200 flex space-x-3" >
32- < div className = "flex-1 bg-blue-500 rounded-lg p-4 text-white flex flex-col items-center justify-center" >
33- < Mic size = { 20 } className = "mb-1" />
34- < Video size = { 20 } className = "mb-2" />
35- < span className = "font-semibold text-lg" > You</ span >
36- </ div >
37- < div className = "flex-1 bg-green-500 rounded-lg p-4 text-white flex items-center justify-center" >
38- < span className = "font-semibold text-lg" > Alex</ span >
39- </ div >
40- </ div >
41-
42- { /* Chat Header */ }
43- < div className = "px-4 py-3 border-b border-gray-200" >
44- < h2 className = "font-semibold text-lg" > Chat</ h2 >
45- </ div >
46-
47- { /* Messages */ }
48- < div className = "flex-1 overflow-y-auto p-4 space-y-4" >
49- < div className = "text-left" >
50- < div className = "text-xs text-gray-500 mb-1" > Alex · 2:14 PM</ div >
51- < div className = "inline-block bg-gray-100 rounded-lg px-3 py-2 text-sm" >
52- Hey! Ready to chat?
67+ { localUser && (
68+ < div
69+ className = "flex-1 rounded-lg p-4 text-white flex flex-col items-center justify-center"
70+ style = { { backgroundColor : localUser . color } }
71+ >
72+ < Mic size = { 20 } className = "mb-1" />
73+ < Video size = { 20 } className = "mb-2" />
74+ < span className = "font-semibold text-lg" > { localUser . name } (You)</ span >
5375 </ div >
54- </ div >
55-
56- < div className = "text-right" >
57- < div className = "text-xs text-gray-500 mb-1 text-right" > You · 2:15 PM</ div >
58- < div className = "inline-block bg-blue-500 text-white rounded-lg px-3 py-2 text-sm" >
59- Nope! This feature is under construction
76+ ) }
77+ { otherUser && (
78+ < div
79+ className = "flex-1 rounded-lg p-4 text-white flex items-center justify-center"
80+ style = { { backgroundColor : otherUser . color } }
81+ >
82+ < span className = "font-semibold text-lg" > { otherUser . name } </ span >
6083 </ div >
61- </ div >
84+ ) }
85+ { ! otherUser && (
86+ < div className = "flex-1 bg-gray-200 rounded-lg p-4 text-gray-500 flex items-center justify-center" >
87+ < span className = "font-semibold text-lg" > Waiting...</ span >
88+ </ div >
89+ ) }
6290 </ div >
6391
64- { /* Message Input */ }
65- < div className = "flex items-center space-x-2 mb-3" >
66- < input
67- type = "text"
68- placeholder = "Type a message..."
69- className = "flex-1 border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
70- />
71- < button className = "bg-blue-500 hover:bg-blue-600 text-white p-2 rounded-lg" >
72- < Send size = { 18 } />
73- </ button >
92+ { /*Chat Panel*/ }
93+ < div className = "flex-1 flex flex-col h-0" >
94+ < ChatPanel provider = { provider } />
7495 </ div >
7596
7697 < div className = "p-4 border-t border-gray-200" >
0 commit comments