@@ -7,6 +7,7 @@ import { Message } from './message'
77import { forComponent } from '@/lib/logger'
88import { ChatPeerList } from './chat-peer-list'
99import { ChevronLeftIcon } from '@heroicons/react/20/solid'
10+ import { UsersIcon } from '@heroicons/react/24/outline'
1011import Blockies from 'react-18-blockies'
1112import { peerIdFromString } from '@libp2p/peer-id'
1213
@@ -22,6 +23,7 @@ export default function ChatContainer() {
2223 const [ input , setInput ] = useState < string > ( '' )
2324 const fileRef = useRef < HTMLInputElement > ( null )
2425 const [ messages , setMessages ] = useState < ChatMessage [ ] > ( [ ] )
26+ const [ showMobilePeerList , setShowMobilePeerList ] = useState ( false )
2527
2628 // Send message to public chat over gossipsub
2729 const sendPublicMessage = useCallback ( async ( ) => {
@@ -183,6 +185,10 @@ export default function ChatContainer() {
183185 setMessages ( messageHistory )
184186 }
185187
188+ const toggleMobilePeerList = ( ) => {
189+ setShowMobilePeerList ( ! showMobilePeerList ) ;
190+ }
191+
186192 useEffect ( ( ) => {
187193 // assumes a chat room is a peerId thus a direct message
188194 if ( roomId === PUBLIC_CHAT_ROOM_ID ) {
@@ -193,26 +199,67 @@ export default function ChatContainer() {
193199 } , [ roomId , directMessages , messageHistory ] )
194200
195201 return (
196- < div className = "container mx-auto" >
197- < div className = "min-w-full border rounded lg:grid lg:grid-cols-6" >
198- < div className = "lg: col-span-5 lg:block " >
202+ < div className = "container mx-auto w-full px-0 " >
203+ < div className = "min-w-full border-0 rounded-none lg:rounded grid grid-cols-1 lg:grid-cols-6" >
204+ < div className = "col-span-1 lg:col-span-5 " >
199205 < div className = "w-full" >
200206 < div className = "relative flex items-center p-3 border-b border-gray-300" >
201207 { roomId === PUBLIC_CHAT_ROOM_ID && (
202- < span className = "block ml-2 font-bold text-gray-600" > { PUBLIC_CHAT_ROOM_NAME } </ span >
208+ < >
209+ < span className = "block ml-2 font-bold text-gray-600" > { PUBLIC_CHAT_ROOM_NAME } </ span >
210+ < button
211+ onClick = { toggleMobilePeerList }
212+ className = "ml-auto lg:hidden flex items-center text-gray-500 hover:text-gray-700"
213+ aria-label = "Toggle peer list"
214+ >
215+ < UsersIcon className = "h-5 w-5" />
216+ < span className = "ml-1 text-sm" > Peers</ span >
217+ </ button >
218+ </ >
203219 ) }
204220 { roomId !== PUBLIC_CHAT_ROOM_ID && (
205221 < >
206222 < Blockies seed = { roomId } size = { 8 } scale = { 3 } className = "rounded mr-2 max-h-10 max-w-10" />
207223 < span className = { `text-gray-500 flex` } > { roomId . toString ( ) . slice ( - 7 ) } </ span >
208- < button onClick = { handleBackToPublic } className = "text-gray-500 flex ml-auto" >
209- < ChevronLeftIcon className = "w-6 h-6 text-gray-500" />
210- < span > Back to Public Chat</ span >
211- </ button >
224+ < div className = "flex items-center ml-auto" >
225+ < button
226+ onClick = { toggleMobilePeerList }
227+ className = "lg:hidden flex items-center text-gray-500 hover:text-gray-700 mr-4"
228+ aria-label = "Toggle peer list"
229+ >
230+ < UsersIcon className = "h-5 w-5" />
231+ < span className = "ml-1 text-sm" > Peers</ span >
232+ </ button >
233+ < button onClick = { handleBackToPublic } className = "text-gray-500 flex" >
234+ < ChevronLeftIcon className = "w-6 h-6 text-gray-500" />
235+ < span className = "hidden sm:inline" > Back to Public Chat</ span >
236+ < span className = "sm:hidden" > Back</ span >
237+ </ button >
238+ </ div >
212239 </ >
213240 ) }
214241 </ div >
215- < div className = "relative w-full flex flex-col-reverse p-3 overflow-y-auto h-[40rem] bg-gray-100" >
242+
243+ { /* Show mobile peer list when toggled */ }
244+ { showMobilePeerList && (
245+ < div className = "lg:hidden border-b border-gray-300" >
246+ < div className = "flex items-center justify-between p-2 bg-gray-50" >
247+ < h2 className = "text-lg text-gray-600" > Peers</ h2 >
248+ < button
249+ onClick = { toggleMobilePeerList }
250+ className = "text-gray-500 hover:text-gray-700"
251+ aria-label = "Close peer list"
252+ >
253+ < svg xmlns = "http://www.w3.org/2000/svg" className = "h-5 w-5" viewBox = "0 0 20 20" fill = "currentColor" >
254+ < path fillRule = "evenodd" d = "M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clipRule = "evenodd" />
255+ </ svg >
256+ </ button >
257+ </ div >
258+ < ChatPeerList hideHeader = { true } />
259+ </ div >
260+ ) }
261+
262+ < div className = "relative w-full flex flex-col-reverse p-3 overflow-y-auto h-[calc(60vh-8rem)] sm:h-[40rem] bg-gray-100" >
216263 < ul className = "space-y-2" >
217264 { messages . map ( ( { msgId, msg, fileObjectUrl, peerId, read, receivedAt } : ChatMessage ) => (
218265 < Message
@@ -229,7 +276,7 @@ export default function ChatContainer() {
229276 </ ul >
230277 </ div >
231278
232- < div className = "flex items-center justify-between w-full p-3 border-t border-gray-300" >
279+ < div className = "flex items-center justify-between w-full p-2 sm:p- 3 border-t border-gray-300" >
233280 < input
234281 ref = { fileRef }
235282 className = "hidden"
@@ -241,7 +288,7 @@ export default function ChatContainer() {
241288 onClick = { handleFileSend }
242289 disabled = { roomId !== PUBLIC_CHAT_ROOM_ID }
243290 title = { roomId === PUBLIC_CHAT_ROOM_ID ? 'Upload file' : "Unsupported in DM's" }
244- className = { roomId === PUBLIC_CHAT_ROOM_ID ? '' : 'cursor-not-allowed' }
291+ className = { ` ${ roomId === PUBLIC_CHAT_ROOM_ID ? '' : 'cursor-not-allowed' } p-1` }
245292 >
246293 < svg
247294 xmlns = "http://www.w3.org/2000/svg"
@@ -265,7 +312,7 @@ export default function ChatContainer() {
265312 onChange = { handleInput }
266313 type = "text"
267314 placeholder = "Message"
268- className = "block w-full py-2 pl-4 mx-3 bg-gray-100 rounded-full outline-none focus:text-gray-700"
315+ className = "block w-full py-2 pl-2 sm:pl- 4 mx-2 sm:mx- 3 bg-gray-100 rounded-full outline-none focus:text-gray-700 text-sm sm:text-base "
269316 name = "message"
270317 required
271318 />
@@ -282,7 +329,9 @@ export default function ChatContainer() {
282329 </ div >
283330 </ div >
284331 </ div >
285- < ChatPeerList />
332+ < div className = "hidden lg:block" >
333+ < ChatPeerList />
334+ </ div >
286335 </ div >
287336 </ div >
288337 )
0 commit comments