@@ -24,6 +24,7 @@ import {
2424 Compose20Regular ,
2525 Delete20Regular ,
2626 Edit20Regular ,
27+ DismissCircle20Regular ,
2728} from '@fluentui/react-icons' ;
2829
2930interface ConversationSummary {
@@ -55,8 +56,30 @@ export function ChatHistory({
5556 const [ isLoading , setIsLoading ] = useState ( true ) ;
5657 const [ error , setError ] = useState < string | null > ( null ) ;
5758 const [ showAll , setShowAll ] = useState ( false ) ;
59+ const [ isClearAllDialogOpen , setIsClearAllDialogOpen ] = useState ( false ) ;
60+ const [ isClearing , setIsClearing ] = useState ( false ) ;
5861 const INITIAL_COUNT = 5 ;
5962
63+ const handleClearAllConversations = useCallback ( async ( ) => {
64+ setIsClearing ( true ) ;
65+ try {
66+ const response = await fetch ( '/api/conversations' , {
67+ method : 'DELETE' ,
68+ } ) ;
69+ if ( response . ok ) {
70+ setConversations ( [ ] ) ;
71+ onNewConversation ( ) ;
72+ setIsClearAllDialogOpen ( false ) ;
73+ } else {
74+ console . error ( 'Failed to clear all conversations' ) ;
75+ }
76+ } catch ( err ) {
77+ console . error ( 'Error clearing all conversations:' , err ) ;
78+ } finally {
79+ setIsClearing ( false ) ;
80+ }
81+ } , [ onNewConversation ] ) ;
82+
6083 const handleDeleteConversation = useCallback ( async ( conversationId : string ) => {
6184 try {
6285 const response = await fetch ( `/api/conversations/${ conversationId } ` , {
@@ -170,17 +193,51 @@ export function ChatHistory({
170193 backgroundColor : tokens . colorNeutralBackground3 ,
171194 overflow : 'hidden' ,
172195 } } >
173- < Text
174- weight = "semibold"
175- size = { 300 }
176- style = { {
177- marginBottom : '12px' ,
178- color : tokens . colorNeutralForeground1 ,
179- flexShrink : 0 ,
180- } }
181- >
182- Chat History
183- </ Text >
196+ < div style = { {
197+ display : 'flex' ,
198+ justifyContent : 'space-between' ,
199+ alignItems : 'center' ,
200+ marginBottom : '12px' ,
201+ flexShrink : 0 ,
202+ } } >
203+ < Text
204+ weight = "semibold"
205+ size = { 300 }
206+ style = { {
207+ color : tokens . colorNeutralForeground1 ,
208+ } }
209+ >
210+ Chat History
211+ </ Text >
212+ < Menu >
213+ < MenuTrigger disableButtonEnhancement >
214+ < Button
215+ appearance = "subtle"
216+ icon = { < MoreHorizontal20Regular /> }
217+ size = "small"
218+ title = "More options"
219+ disabled = { isGenerating }
220+ style = { {
221+ minWidth : '24px' ,
222+ height : '24px' ,
223+ padding : '2px' ,
224+ color : tokens . colorNeutralForeground3 ,
225+ } }
226+ />
227+ </ MenuTrigger >
228+ < MenuPopover >
229+ < MenuList >
230+ < MenuItem
231+ icon = { < DismissCircle20Regular /> }
232+ onClick = { ( ) => setIsClearAllDialogOpen ( true ) }
233+ disabled = { displayConversations . length === 0 }
234+ >
235+ Clear all chat history
236+ </ MenuItem >
237+ </ MenuList >
238+ </ MenuPopover >
239+ </ Menu >
240+ </ div >
184241
185242 < div style = { {
186243 borderBottom : `1px solid ${ tokens . colorNeutralStroke2 } ` ,
@@ -295,6 +352,28 @@ export function ChatHistory({
295352 </ Link >
296353 </ div >
297354 </ div >
355+
356+ { /* Clear All Confirmation Dialog */ }
357+ < Dialog open = { isClearAllDialogOpen } onOpenChange = { ( _ , data ) => ! isClearing && setIsClearAllDialogOpen ( data . open ) } >
358+ < DialogSurface >
359+ < DialogTitle > Clear all chat history</ DialogTitle >
360+ < DialogBody >
361+ < DialogContent >
362+ < Text >
363+ Are you sure you want to delete all chat history? This action cannot be undone and all conversations will be permanently removed.
364+ </ Text >
365+ </ DialogContent >
366+ </ DialogBody >
367+ < DialogActions >
368+ < Button appearance = "secondary" onClick = { ( ) => setIsClearAllDialogOpen ( false ) } disabled = { isClearing } >
369+ Cancel
370+ </ Button >
371+ < Button appearance = "primary" onClick = { handleClearAllConversations } disabled = { isClearing } >
372+ { isClearing ? 'Clearing...' : 'Clear All' }
373+ </ Button >
374+ </ DialogActions >
375+ </ DialogSurface >
376+ </ Dialog >
298377 </ div >
299378 ) ;
300379}
0 commit comments