From 002df7b0f9ab73f60bcbf4f560a5cdc717ffc025 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Mon, 13 May 2024 14:00:43 -0700 Subject: [PATCH] Hold Shift to delete without confirmation: fixes #537 --- src/apps/chat/components/ChatDrawer.tsx | 2 +- src/apps/chat/components/ChatDrawerItem.tsx | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/apps/chat/components/ChatDrawer.tsx b/src/apps/chat/components/ChatDrawer.tsx index 4692eee0a..ccc998411 100644 --- a/src/apps/chat/components/ChatDrawer.tsx +++ b/src/apps/chat/components/ChatDrawer.tsx @@ -310,7 +310,7 @@ function ChatDrawer(props: { bottomBarBasis={filteredChatsBarBasis} onConversationActivate={handleConversationActivate} onConversationBranch={onConversationBranch} - onConversationDelete={handleConversationDeleteNoConfirmation} + onConversationDeleteNoConfirmation={handleConversationDeleteNoConfirmation} onConversationExport={onConversationsExportDialog} onConversationFolderChange={handleConversationFolderChange} /> diff --git a/src/apps/chat/components/ChatDrawerItem.tsx b/src/apps/chat/components/ChatDrawerItem.tsx index cf2c83cfc..b99d9f17a 100644 --- a/src/apps/chat/components/ChatDrawerItem.tsx +++ b/src/apps/chat/components/ChatDrawerItem.tsx @@ -42,7 +42,7 @@ export const ChatDrawerItemMemo = React.memo(ChatDrawerItem, (prev, next) => prev.bottomBarBasis === next.bottomBarBasis && prev.onConversationActivate === next.onConversationActivate && prev.onConversationBranch === next.onConversationBranch && - prev.onConversationDelete === next.onConversationDelete && + prev.onConversationDeleteNoConfirmation === next.onConversationDeleteNoConfirmation && prev.onConversationExport === next.onConversationExport && prev.onConversationFolderChange === next.onConversationFolderChange, ); @@ -76,7 +76,7 @@ function ChatDrawerItem(props: { bottomBarBasis: number, onConversationActivate: (conversationId: DConversationId, closeMenu: boolean) => void, onConversationBranch: (conversationId: DConversationId, messageId: string | null) => void, - onConversationDelete: (conversationId: DConversationId) => void, + onConversationDeleteNoConfirmation: (conversationId: DConversationId) => void, onConversationExport: (conversationId: DConversationId, exportAll: boolean) => void, onConversationFolderChange: (folderChangeRequest: FolderChangeRequest) => void, }) { @@ -155,7 +155,16 @@ function ChatDrawerItem(props: { // Delete - const handleDeleteButtonShow = React.useCallback(() => setDeleteArmed(true), []); + const { onConversationDeleteNoConfirmation } = props; + const handleDeleteButtonShow = React.useCallback((event: React.MouseEvent) => { + // special case: if 'Shift' is pressed, delete immediately + if (event.shiftKey) { + event.stopPropagation(); + onConversationDeleteNoConfirmation(conversationId); + return; + } + setDeleteArmed(true); + }, [conversationId, onConversationDeleteNoConfirmation]); const handleDeleteButtonHide = React.useCallback(() => setDeleteArmed(false), []); @@ -163,9 +172,9 @@ function ChatDrawerItem(props: { if (deleteArmed) { setDeleteArmed(false); event.stopPropagation(); - props.onConversationDelete(conversationId); + onConversationDeleteNoConfirmation(conversationId); } - }, [conversationId, deleteArmed, props]); + }, [conversationId, deleteArmed, onConversationDeleteNoConfirmation]); const textSymbol = SystemPurposes[systemPurposeId]?.symbol || '❓';