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
5
import PropTypes from "prop-types" ;
5
6
import Tooltip from "@mui/material/Tooltip" ;
6
7
import Icon from "@mui/material/Icon" ;
@@ -19,10 +20,9 @@ import { ConversationContext } from "@/contexts/conversation";
19
20
* @param {Object } chat
20
21
* @param {string } chat.id
21
22
* @param {string } chat.title
22
- * @param {boolean } isActive whether this chat is active
23
23
* @returns
24
24
*/
25
- const ChatTab = ( { chat, isActive , onShareClick, onDeleteClick } ) => {
25
+ const ChatTab = ( { chat, onShareClick, onDeleteClick } ) => {
26
26
const { dispatch } = useContext ( ConversationContext ) ;
27
27
const titleRef = useRef ( null ) ;
28
28
const [ titleEditable , setTitleEditable ] = useState ( "false" ) ;
@@ -34,7 +34,7 @@ const ChatTab = ({ chat, isActive, onShareClick, onDeleteClick }) => {
34
34
} , [ titleEditable ] ) ;
35
35
36
36
const handleKeyDown = async ( e ) => {
37
- // TODO: this will trigger in Chinese IME on OSX
37
+ // TODO: this will trigger in Chinese IME on OSX
38
38
if ( e . key === "Enter" ) {
39
39
e . preventDefault ( ) ;
40
40
await renameChat ( titleRef . current . innerText ) ;
@@ -96,7 +96,11 @@ const ChatTab = ({ chat, isActive, onShareClick, onDeleteClick }) => {
96
96
} ;
97
97
98
98
return (
99
- < >
99
+ < NavLink
100
+ to = { `conversations/${ chat . id } ` }
101
+ className = { ( { isActive, isPending } ) =>
102
+ `${ styles . sidebarButton } ${ isActive ? styles . active : isPending ? styles . pending : "" } ` }
103
+ >
100
104
< Tooltip title = { titleRef . current ?. innerText } >
101
105
{ /* contentEditable moves control out of react, so useState won't work correctly.
102
106
* I use ref to get the value instead.
@@ -113,53 +117,51 @@ const ChatTab = ({ chat, isActive, onShareClick, onDeleteClick }) => {
113
117
{ chat . title }
114
118
</ span >
115
119
</ Tooltip >
116
- { isActive && (
117
- < Dropdown className = { styles . chatOpMenu } >
118
- < DropdownButton className = { styles . chatOpMenuIcon } >
119
- < MoreVertIcon />
120
- </ DropdownButton >
121
- < DropdownMenu className = { styles . chatOpMenuList } >
122
- < li >
123
- < button className = { styles . chatOpMenuItem } onClick = { flipPin } >
124
- { chat . pinned ?
125
- < >
126
- < Icon baseClassName = "material-symbols-outlined" > keep_off</ Icon >
127
- < span className = { styles . chatOpMenuItemText } > Unpin</ span >
128
- </ > : < >
129
- < Icon baseClassName = "material-symbols-outlined" > keep</ Icon >
130
- < span className = { styles . chatOpMenuItemText } > Pin</ span >
131
- </ >
132
- }
133
- </ button >
134
- </ li >
135
- < li >
136
- < button className = { styles . chatOpMenuItem } onClick = { onSummarizeClick } >
137
- < AutoAwesomeIcon />
138
- < span className = { styles . chatOpMenuItemText } > Generate title</ span >
139
- </ button >
140
- </ li >
141
- < li >
142
- < button className = { styles . chatOpMenuItem } onClick = { onUpdateClick } >
143
- < DriveFileRenameOutlineIcon />
144
- < span className = { styles . chatOpMenuItemText } > Change title</ span >
145
- </ button >
146
- </ li >
147
- < li >
148
- < button className = { styles . chatOpMenuItem } onClick = { ( ) => onShareClick ( chat . id , chat . title ) } >
149
- < ShareIcon />
150
- < span className = { styles . chatOpMenuItemText } > Share</ span >
151
- </ button >
152
- </ li >
153
- < li >
154
- < button className = { styles . chatOpMenuItem } onClick = { ( ) => onDeleteClick ( chat . id , titleRef . current ?. innerText ) } >
155
- < DeleteOutlineIcon />
156
- < span className = { styles . chatOpMenuItemText } > Delete</ span >
157
- </ button >
158
- </ li >
159
- </ DropdownMenu >
160
- </ Dropdown >
161
- ) }
162
- </ >
120
+ < Dropdown className = { styles . chatOpMenu } >
121
+ < DropdownButton className = { styles . chatOpMenuIcon } >
122
+ < MoreVertIcon />
123
+ </ DropdownButton >
124
+ < DropdownMenu className = { styles . chatOpMenuList } >
125
+ < li >
126
+ < button className = { styles . chatOpMenuItem } onClick = { flipPin } >
127
+ { chat . pinned ?
128
+ < >
129
+ < Icon baseClassName = "material-symbols-outlined" > keep_off</ Icon >
130
+ < span className = { styles . chatOpMenuItemText } > Unpin</ span >
131
+ </ > : < >
132
+ < Icon baseClassName = "material-symbols-outlined" > keep</ Icon >
133
+ < span className = { styles . chatOpMenuItemText } > Pin</ span >
134
+ </ >
135
+ }
136
+ </ button >
137
+ </ li >
138
+ < li >
139
+ < button className = { styles . chatOpMenuItem } onClick = { onSummarizeClick } >
140
+ < AutoAwesomeIcon />
141
+ < span className = { styles . chatOpMenuItemText } > Generate title</ span >
142
+ </ button >
143
+ </ li >
144
+ < li >
145
+ < button className = { styles . chatOpMenuItem } onClick = { onUpdateClick } >
146
+ < DriveFileRenameOutlineIcon />
147
+ < span className = { styles . chatOpMenuItemText } > Change title</ span >
148
+ </ button >
149
+ </ li >
150
+ < li >
151
+ < button className = { styles . chatOpMenuItem } onClick = { ( ) => onShareClick ( chat . id , chat . title ) } >
152
+ < ShareIcon />
153
+ < span className = { styles . chatOpMenuItemText } > Share</ span >
154
+ </ button >
155
+ </ li >
156
+ < li >
157
+ < button className = { styles . chatOpMenuItem } onClick = { ( ) => onDeleteClick ( chat . id , titleRef . current ?. innerText ) } >
158
+ < DeleteOutlineIcon />
159
+ < span className = { styles . chatOpMenuItemText } > Delete</ span >
160
+ </ button >
161
+ </ li >
162
+ </ DropdownMenu >
163
+ </ Dropdown >
164
+ </ NavLink >
163
165
) ;
164
166
} ;
165
167
0 commit comments