11import React , { useState } from 'react' ;
22import { Link , useLocation } from 'react-router-dom' ;
33
4- const Navbar = ( { activeChats } ) => {
4+ const Navbar = ( { activeChats, isMobile , onClose } ) => {
55 const location = useLocation ( ) ;
6- const [ sidebarWidth , setSidebarWidth ] = useState ( 250 ) ; // Default width
6+ const [ sidebarWidth , setSidebarWidth ] = useState ( 250 ) ;
77
8- // Handle drag to resize
8+ /* ---------- desktop‑only drag‑resize ---------- */
99 const handleMouseMove = ( e ) => {
10- // const newWidth = e.clientX < 180 ? 180 : e.clientX ; // min 180px
11- // setSidebarWidth(newWidth);
10+ const newWidth = Math . max ( e . clientX , 180 ) ; // min 180 px
11+ setSidebarWidth ( newWidth ) ;
1212 } ;
13-
14- const handleMouseUp = ( ) => {
13+ const stopResize = ( ) => {
1514 document . removeEventListener ( 'mousemove' , handleMouseMove ) ;
16- document . removeEventListener ( 'mouseup' , handleMouseUp ) ;
15+ document . removeEventListener ( 'mouseup' , stopResize ) ;
1716 } ;
18-
19- const handleMouseDown = ( e ) => {
17+ const startResize = ( e ) => {
18+ if ( isMobile ) return ;
2019 e . preventDefault ( ) ;
2120 document . addEventListener ( 'mousemove' , handleMouseMove ) ;
22- document . addEventListener ( 'mouseup' , handleMouseUp ) ;
21+ document . addEventListener ( 'mouseup' , stopResize ) ;
2322 } ;
2423
24+ /* ---------- positioning ---------- */
25+ const navStyle = isMobile
26+ ? {
27+ width : sidebarWidth ,
28+ position : 'absolute' ,
29+ top : 0 ,
30+ left : 0 ,
31+ height : '100%' ,
32+ /* NOTHING ELSE OVERRIDDEN → inherits the same background,
33+ padding, fonts, etc., as the desktop bar */
34+ zIndex : 15 ,
35+ }
36+ : {
37+ width : sidebarWidth ,
38+ position : 'relative' ,
39+ } ;
40+
2541 return (
26- < div className = "navbar" style = { { width : sidebarWidth } } >
27- { /* Suggestions link */ }
28- < div style = { { marginBottom : '20px' } } >
42+ < div className = "navbar" style = { navStyle } >
43+ { /* mobile close (×) */ }
44+ { isMobile && (
45+ < button
46+ aria-label = "Close sidebar"
47+ onClick = { onClose }
48+ style = { {
49+ position : 'absolute' ,
50+ top : 10 ,
51+ right : 10 ,
52+ background : 'none' ,
53+ border : 'none' ,
54+ fontSize : '1.8rem' ,
55+ color : '#d6ceba' ,
56+ cursor : 'pointer' ,
57+ } }
58+ >
59+ ×
60+ </ button >
61+ ) }
62+
63+ { /* suggestions link */ }
64+ < div style = { { marginBottom : 20 , marginTop : isMobile ? 50 : 0 } } >
2965 < Link
3066 to = "/"
3167 className = { `nav-link ${
@@ -36,13 +72,13 @@ const Navbar = ({ activeChats }) => {
3672 </ Link >
3773 </ div >
3874
39- { /* Active Chats */ }
40- < div style = { { fontSize : '.8rem' , marginBottom : '10px' } } > Active Chats</ div >
75+ { /* active chats */ }
76+ < div style = { { fontSize : '.8rem' , marginBottom : 10 } } > Active Chats</ div >
4177 < ul style = { { listStyle : 'none' , paddingLeft : 0 , margin : 0 } } >
4278 { activeChats . map ( ( chat ) => {
4379 const isActive = location . pathname === `/chat/${ chat . id } ` ;
4480 return (
45- < li key = { chat . id } style = { { marginBottom : '8px' } } >
81+ < li key = { chat . id } style = { { marginBottom : 8 } } >
4682 < Link
4783 to = { `/chat/${ chat . id } ` }
4884 className = { `nav-link ${ isActive ? 'nav-link-active' : '' } ` }
@@ -54,8 +90,22 @@ const Navbar = ({ activeChats }) => {
5490 } ) }
5591 </ ul >
5692
57- { /* Draggable resizer handle */ }
58- < div className = "resizer" onMouseDown = { handleMouseDown } > </ div >
93+ { /* desktop resizer handle */ }
94+ { ! isMobile && (
95+ < div
96+ className = "resizer"
97+ onMouseDown = { startResize }
98+ style = { {
99+ width : 2 ,
100+ cursor : 'col-resize' ,
101+ position : 'absolute' ,
102+ top : 0 ,
103+ right : 0 ,
104+ bottom : 0 ,
105+ background : '#444' ,
106+ } }
107+ />
108+ ) }
59109 </ div >
60110 ) ;
61111} ;
0 commit comments