1- import { Check , X } from 'lucide-react' ;
2- import type { FocusEvent , KeyboardEvent , MouseEvent } from 'react' ;
3- import { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
4- import { useNavigate , useParams } from 'react-router-dom' ;
5- import { useRecoilValue } from 'recoil' ;
6- import { NotificationSeverity } from '~/common' ;
7- import { useGetEndpointsQuery , useUpdateConversationMutation } from '~/data-provider' ;
8- import type { TConversation } from '~/data-provider/data-provider/src' ;
9- import { Constants } from '~/data-provider/data-provider/src' ;
10- import { useLocalize , useMediaQuery , useNavigateToConvo } from '~/hooks' ;
11- import { useToastContext } from '~/Providers' ;
12- import store from '~/store' ;
13- import { cn } from '~/utils' ;
14- import { ConvoOptions } from './ConvoOptions' ;
1+ import { Check , X } from "lucide-react" ;
2+ import type { FocusEvent , KeyboardEvent , MouseEvent } from "react" ;
3+ import { useCallback , useEffect , useMemo , useRef , useState } from "react" ;
4+ import { useNavigate , useParams } from "react-router-dom" ;
5+ import { useRecoilValue } from "recoil" ;
6+ import { NotificationSeverity } from "~/common" ;
7+ import {
8+ useGetEndpointsQuery ,
9+ useUpdateConversationMutation ,
10+ } from "~/data-provider" ;
11+ import type { TConversation } from "~/data-provider/data-provider/src" ;
12+ import { Constants } from "~/data-provider/data-provider/src" ;
13+ import { useLocalize , useMediaQuery , useNavigateToConvo } from "~/hooks" ;
14+ import { useToastContext } from "~/Providers" ;
15+ import store from "~/store" ;
16+ import { cn } from "~/utils" ;
17+ import { ConvoOptions } from "./ConvoOptions" ;
1518
1619type KeyEvent = KeyboardEvent < HTMLInputElement > ;
1720
@@ -30,8 +33,13 @@ export default function Conversation({
3033} : ConversationProps ) {
3134 const params = useParams ( ) ;
3235
33- const currentConvoId = useMemo ( ( ) => params . conversationId , [ params . conversationId ] ) ;
34- const updateConvoMutation = useUpdateConversationMutation ( currentConvoId ?? '' ) ;
36+ const currentConvoId = useMemo (
37+ ( ) => params . conversationId ,
38+ [ params . conversationId ]
39+ ) ;
40+ const updateConvoMutation = useUpdateConversationMutation (
41+ currentConvoId ?? ""
42+ ) ;
3543 const activeConvos = useRecoilValue ( store . allConversationsSelector ) ;
3644 const { data : endpointsConfig } = useGetEndpointsQuery ( ) ;
3745 const { navigateWithLastTools } = useNavigateToConvo ( ) ;
@@ -41,7 +49,7 @@ export default function Conversation({
4149 const [ titleInput , setTitleInput ] = useState ( title ) ;
4250 const [ renaming , setRenaming ] = useState ( false ) ;
4351 const [ isPopoverActive , setIsPopoverActive ] = useState ( false ) ;
44- const isSmallScreen = useMediaQuery ( ' (max-width: 768px)' ) ;
52+ const isSmallScreen = useMediaQuery ( " (max-width: 768px)" ) ;
4553 const localize = useLocalize ( ) ;
4654 const navigate = useNavigate ( ) ;
4755
@@ -60,14 +68,14 @@ export default function Conversation({
6068 toggleNav ( ) ;
6169
6270 // set document title
63- if ( typeof title === ' string' && title . length > 0 ) {
71+ if ( typeof title === " string" && title . length > 0 ) {
6472 // document.title = title;
6573 }
6674
6775 /* Note: Latest Message should not be reset if existing convo */
6876 navigateWithLastTools (
6977 conversation ,
70- ! ( conversationId ?? '' ) || conversationId === Constants . NEW_CONVO ,
78+ ! ( conversationId ?? "" ) || conversationId === Constants . NEW_CONVO
7179 ) ;
7280 } ;
7381
@@ -84,43 +92,57 @@ export default function Conversation({
8492 } , [ renaming ] ) ;
8593
8694 const onRename = useCallback (
87- ( e : MouseEvent < HTMLButtonElement > | FocusEvent < HTMLInputElement > | KeyEvent ) => {
95+ (
96+ e : MouseEvent < HTMLButtonElement > | FocusEvent < HTMLInputElement > | KeyEvent
97+ ) => {
8898 e . preventDefault ( ) ;
8999 setRenaming ( false ) ;
90100 if ( titleInput === title ) {
91101 return ;
92102 }
93- if ( typeof conversationId !== ' string' || conversationId === '' ) {
103+ if ( typeof conversationId !== " string" || conversationId === "" ) {
94104 return ;
95105 }
96106
97107 updateConvoMutation . mutate (
98- { conversationId, title : titleInput ?? '' , flowType : conversation . flowType } ,
108+ {
109+ conversationId,
110+ title : titleInput ?? "" ,
111+ flowId : conversation . flowId ,
112+ flowType : conversation . flowType ,
113+ } ,
99114 {
100115 onError : ( ) => {
101116 setTitleInput ( title ) ;
102117 showToast ( {
103- message : ' Failed to rename conversation' ,
118+ message : " Failed to rename conversation" ,
104119 severity : NotificationSeverity . ERROR ,
105120 showIcon : true ,
106121 } ) ;
107122 } ,
108- } ,
123+ }
109124 ) ;
110125 } ,
111- [ title , titleInput , conversationId , showToast , conversation , updateConvoMutation ] ,
126+ [
127+ title ,
128+ titleInput ,
129+ conversationId ,
130+ showToast ,
131+ conversation ,
132+ updateConvoMutation ,
133+ ]
112134 ) ;
113135
114136 const handleKeyDown = useCallback (
115137 ( e : KeyEvent ) => {
116- if ( e . key === ' Escape' ) {
138+ if ( e . key === " Escape" ) {
117139 setTitleInput ( title ) ;
118140 setRenaming ( false ) ;
119- } else if ( e . key === ' Enter' ) {
141+ } else if ( e . key === " Enter" ) {
120142 onRename ( e ) ;
121143 }
122144 } ,
123- [ title , onRename ] ,
145+ [ title , onRename ]
124146 ) ;
125147
126148 const cancelRename = useCallback (
@@ -129,25 +151,25 @@ export default function Conversation({
129151 setTitleInput ( title ) ;
130152 setRenaming ( false ) ;
131153 } ,
132- [ title ] ,
154+ [ title ]
133155 ) ;
134156
135157 const isActiveConvo : boolean = useMemo (
136158 ( ) =>
137159 currentConvoId === conversationId ||
138160 ( isLatestConvo &&
139- currentConvoId === ' new' &&
161+ currentConvoId === " new" &&
140162 activeConvos [ 0 ] != null &&
141- activeConvos [ 0 ] !== ' new' ) ,
142- [ currentConvoId , conversationId , isLatestConvo , activeConvos ] ,
163+ activeConvos [ 0 ] !== " new" ) ,
164+ [ currentConvoId , conversationId , isLatestConvo , activeConvos ]
143165 ) ;
144166
145167 return (
146168 < div
147169 className = { cn (
148- ' group relative mt-2 flex h-10 w-full items-center rounded-lg hover:bg-[#EBEFF8]' ,
149- isActiveConvo ? ' bg-[#EBEFF8]' : '' ,
150- isSmallScreen ? ' h-12' : '' ,
170+ " group relative mt-2 flex h-10 w-full items-center rounded-lg hover:bg-[#EBEFF8]" ,
171+ isActiveConvo ? " bg-[#EBEFF8]" : "" ,
172+ isSmallScreen ? " h-12" : ""
151173 ) }
152174 >
153175 { renaming ? (
@@ -156,15 +178,19 @@ export default function Conversation({
156178 ref = { inputRef }
157179 type = "text"
158180 className = "w-full rounded bg-transparent p-0.5 text-sm leading-tight focus-visible:outline-none"
159- value = { titleInput ?? '' }
181+ value = { titleInput ?? "" }
160182 onChange = { ( e ) => setTitleInput ( e . target . value ) }
161183 onKeyDown = { handleKeyDown }
162- aria-label = { `${ localize ( 'com_ui_rename' ) } ${ localize ( 'com_ui_chat' ) } ` }
184+ aria-label = { `${ localize ( "com_ui_rename" ) } ${ localize (
185+ "com_ui_chat"
186+ ) } `}
163187 />
164188 < div className = "flex gap-1" >
165189 < button
166190 onClick = { cancelRename }
167- aria-label = { `${ localize ( 'com_ui_cancel' ) } ${ localize ( 'com_ui_rename' ) } ` }
191+ aria-label = { `${ localize ( "com_ui_cancel" ) } ${ localize (
192+ "com_ui_rename"
193+ ) } `}
168194 >
169195 < X
170196 aria-hidden = { true }
@@ -173,7 +199,9 @@ export default function Conversation({
173199 </ button >
174200 < button
175201 onClick = { onRename }
176- aria-label = { `${ localize ( 'com_ui_submit' ) } ${ localize ( 'com_ui_rename' ) } ` }
202+ aria-label = { `${ localize ( "com_ui_submit" ) } ${ localize (
203+ "com_ui_rename"
204+ ) } `}
177205 >
178206 < Check
179207 aria-hidden = { true }
@@ -189,10 +217,10 @@ export default function Conversation({
189217 data-testid = "convo-item"
190218 onClick = { clickHandler }
191219 className = { cn (
192- ' flex grow cursor-pointer items-center gap-2 overflow-hidden whitespace-nowrap break-all rounded-lg px-2 py-2' ,
193- isActiveConvo ? ' bg-[#EBEFF8]' : '' ,
220+ " flex grow cursor-pointer items-center gap-2 overflow-hidden whitespace-nowrap break-all rounded-lg px-2 py-2" ,
221+ isActiveConvo ? " bg-[#EBEFF8]" : ""
194222 ) }
195- title = { title ?? '' }
223+ title = { title ?? "" }
196224 >
197225 { /* <EndpointIcon
198226 conversation={conversation}
@@ -210,7 +238,16 @@ export default function Conversation({
210238 } }
211239 alt = { conversation ?. flowType }
212240 >
213- < img src = { __APP_ENV__ . BASE_URL + ( conversation ?. flowType === 20 ? "/assets/linsi.png" : "/assets/talk.png" ) } className = 'size-6 inline-block mr-2.5' alt = "" />
241+ < img
242+ src = {
243+ __APP_ENV__ . BASE_URL +
244+ ( conversation ?. flowType === 20
245+ ? "/assets/linsi.png"
246+ : "/assets/talk.png" )
247+ }
248+ className = "size-6 inline-block mr-2.5"
249+ alt = ""
250+ />
214251 { title }
215252 </ div >
216253 { isActiveConvo ? (
@@ -222,10 +259,10 @@ export default function Conversation({
222259 ) }
223260 < div
224261 className = { cn (
225- ' mr-2' ,
262+ " mr-2" ,
226263 isPopoverActive || isActiveConvo
227- ? ' flex'
228- : ' hidden group-focus-within:flex group-hover:flex' ,
264+ ? " flex"
265+ : " hidden group-focus-within:flex group-hover:flex"
229266 ) }
230267 >
231268 { ! renaming && (
0 commit comments