1
1
import styles from "./index.module.css" ;
2
2
3
3
import { useContext , useEffect , useState , useRef } from "react" ;
4
- import { NavLink } from "react-router-dom" ;
4
+ import { useNavigate , useParams } from "react-router-dom" ;
5
5
import PropTypes from "prop-types" ;
6
6
import Tooltip from "@mui/material/Tooltip" ;
7
7
import Icon from "@mui/material/Icon" ;
@@ -23,6 +23,9 @@ import { ConversationContext } from "@/contexts/conversation";
23
23
* @returns
24
24
*/
25
25
const ChatTab = ( { chat, onShareClick, onDeleteClick } ) => {
26
+ const navigate = useNavigate ( ) ;
27
+ const params = useParams ( ) ;
28
+
26
29
const { dispatch } = useContext ( ConversationContext ) ;
27
30
const titleRef = useRef ( null ) ;
28
31
const [ titleEditable , setTitleEditable ] = useState ( "false" ) ;
@@ -101,26 +104,29 @@ const ChatTab = ({ chat, onShareClick, onDeleteClick }) => {
101
104
} ;
102
105
103
106
return (
104
- < NavLink
105
- to = { `conversations/${ chat . id } ` }
106
- className = { ( { isActive, isPending } ) =>
107
- `${ styles . sidebarButton } ${ isActive ? styles . active : isPending ? styles . pending : "" } ` }
107
+ < div
108
+ className = { `${ styles . sidebarButton } ${ params . convId === chat . id ? styles . active : "" } ` }
108
109
>
109
110
< Tooltip title = { titleRef . current ?. innerText } >
110
- { /* contentEditable moves control out of react, so useState won't work correctly.
111
- * I use ref to get the value instead.
112
- */ }
113
- < span
114
- aria-label = "chat title"
115
- ref = { titleRef }
116
- className = { styles . chatTitle }
117
- contentEditable = { titleEditable }
118
- suppressContentEditableWarning = { true } // TODO: I'm not sure whether I can ignore this warning
119
- onKeyDown = { handleKeyDown }
120
- onBlur = { ( ) => setTitleEditable ( "false" ) }
111
+ < div
112
+ className = { styles . titleContainer }
113
+ onClick = { ( ) => navigate ( `/conversations/${ chat . id } ` ) }
121
114
>
122
- { chat . title }
123
- </ span >
115
+ { /* contentEditable moves control out of react, so useState won't work correctly.
116
+ * I use ref to get the value instead.
117
+ */ }
118
+ < span
119
+ aria-label = "chat title"
120
+ ref = { titleRef }
121
+ className = { styles . chatTitle }
122
+ contentEditable = { titleEditable }
123
+ suppressContentEditableWarning = { true } // TODO: I'm not sure whether I can ignore this warning
124
+ onKeyDown = { handleKeyDown }
125
+ onBlur = { ( ) => setTitleEditable ( "false" ) }
126
+ >
127
+ { chat . title }
128
+ </ span >
129
+ </ div >
124
130
</ Tooltip >
125
131
< Dropdown className = { styles . chatOpMenu } >
126
132
< DropdownButton ref = { buttonRef } className = { styles . chatOpMenuIcon } >
@@ -166,7 +172,7 @@ const ChatTab = ({ chat, onShareClick, onDeleteClick }) => {
166
172
</ li >
167
173
</ DropdownMenu >
168
174
</ Dropdown >
169
- </ NavLink >
175
+ </ div >
170
176
) ;
171
177
} ;
172
178
0 commit comments