From 60d3300a8d94bef51fb17c7cd404b50d3884a002 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Wed, 29 Mar 2023 13:16:01 -0700 Subject: [PATCH] Clear button --- components/ApplicationBar.tsx | 48 ++++++++++++++++++++++------------- components/ChatArea.tsx | 2 +- components/Conversation.tsx | 2 +- components/Message.tsx | 2 +- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/components/ApplicationBar.tsx b/components/ApplicationBar.tsx index fbeaf9752..f25ee1193 100644 --- a/components/ApplicationBar.tsx +++ b/components/ApplicationBar.tsx @@ -87,7 +87,7 @@ function ConfirmationDialog(props: { open: boolean, onClose: () => void, onPosit /** * FIXME - TEMPORARY - placeholder for a proper Pages Drawer */ -function PagesMenu(props: { pagesMenuAnchor: HTMLElement | null, onClose: () => void }) { +function PagesMenu(props: { pagesMenuAnchor: HTMLElement | null, onClose: () => void, onClearConversation: (e: React.MouseEvent, conversationId: string) => void }) { const conversationNames: { id: string; name: string, systemPurposeId: SystemPurposeId }[] = useConversationNames(); const setActiveConversation = useChatStore((state) => state.setActiveConversationId); @@ -95,7 +95,7 @@ function PagesMenu(props: { pagesMenuAnchor: HTMLElement | null, onClose: () => setActiveConversation(conversationId); return @@ -110,10 +110,17 @@ function PagesMenu(props: { pagesMenuAnchor: HTMLElement | null, onClose: () => key={'c-id-' + conversation.id} onClick={() => handleConversationClicked(conversation.id)} > - {SystemPurposes[conversation.systemPurposeId]?.symbol || ''} - + + {SystemPurposes[conversation.systemPurposeId]?.symbol || ''} + + {conversation.name} + props.onClearConversation(e, conversation.id)}> + + ))} @@ -146,16 +153,17 @@ function PagesMenu(props: { pagesMenuAnchor: HTMLElement | null, onClose: () => /** * The top bar of the application, with the model and purpose selection, and menu/settings icons */ -export function ApplicationBar(props: { onClearConversation: () => void, onShowSettings: () => void, sx?: SxProps }) { +export function ApplicationBar(props: { onClearConversation: (id: string) => void, onShowSettings: () => void, sx?: SxProps }) { // state const [pagesMenuAnchor, setPagesMenuAnchor] = React.useState(null); const [actionsMenuAnchor, setActionsMenuAnchor] = React.useState(null); - const [clearConfirmationOpen, setClearConfirmationOpen] = React.useState(false); + const [clearConfirmationId, setClearConfirmationId] = React.useState(null); // external state const { mode: colorMode, setMode: setColorMode } = useColorScheme(); const { wideMode, setWideMode, freeScroll, setFreeScroll } = useSettingsStore(); const { chatModelId, setChatModelId, setSystemPurposeId, systemPurposeId } = useActiveConfiguration(); + const activeConversationId = useChatStore((state) => state.activeConversationId); const handleChatModelChange = (event: any, value: ChatModelId | null) => value && setChatModelId(value); @@ -175,20 +183,21 @@ export function ApplicationBar(props: { onClearConversation: () => void, onShowS const handleScrollModeToggle = () => setFreeScroll(!freeScroll); const handleActionShowSettings = (e: React.MouseEvent) => { - e.preventDefault(); + e.stopPropagation(); props.onShowSettings(); closeActionsMenu(); }; - const handleActionClearConversation = (e: React.MouseEvent) => { - e.preventDefault(); - setClearConfirmationOpen(true); + const handleActionClearConversation = (e: React.MouseEvent, id: string | null) => { + e.stopPropagation(); + if (id) + setClearConfirmationId(id); }; const handleConfirmedClearConversation = () => { - closeActionsMenu(); - setClearConfirmationOpen(false); - props.onClearConversation(); + if (clearConfirmationId) + props.onClearConversation(clearConfirmationId); + setClearConfirmationId(null); }; @@ -220,11 +229,14 @@ export function ApplicationBar(props: { onClearConversation: () => void, onShowS {/* First Menu */} - {!!pagesMenuAnchor && } + {} {/* Second Menu */} @@ -240,7 +252,7 @@ export function ApplicationBar(props: { onClearConversation: () => void, onShowS - + Free scroll @@ -253,7 +265,7 @@ export function ApplicationBar(props: { onClearConversation: () => void, onShowS - + handleActionClearConversation(e, activeConversationId)}> Clear conversation @@ -261,7 +273,7 @@ export function ApplicationBar(props: { onClearConversation: () => void, onShowS {/* Confirmation Dialog */} setClearConfirmationOpen(false)} onPositive={handleConfirmedClearConversation} + open={!!clearConfirmationId} onClose={() => setClearConfirmationId(null)} onPositive={handleConfirmedClearConversation} confirmationText={'Are you sure you want to discard all the messages?'} positiveActionText={'Clear conversation'} /> ; diff --git a/components/ChatArea.tsx b/components/ChatArea.tsx index e94e115b6..3c70404e6 100644 --- a/components/ChatArea.tsx +++ b/components/ChatArea.tsx @@ -146,7 +146,7 @@ export function ChatArea(props: { onShowSettings: () => void, sx?: SxProps }) { const handleStopGeneration = () => abortController?.abort(); - const handleConversationClear = () => replaceMessages(activeConversationId, []); + const handleConversationClear = (conversationId: string) => replaceMessages(conversationId, []); return ( ))} - + {SystemPurposes[systemPurposeId].description} diff --git a/components/Message.tsx b/components/Message.tsx index 3648f0f95..64519540c 100644 --- a/components/Message.tsx +++ b/components/Message.tsx @@ -359,7 +359,7 @@ export function Message(props: { dMessage: DMessage, disableSend: boolean, onDel {/* message operations menu (floating) */} {!!menuAnchor && (