+
+ {title}
+ +
+ {#if asHtml}{@html message}{:else}{message}{/if}
+
+
+
+
+
+
+
+
+
+
+
+
+ diff --git a/src/lib/ChatOptionMenu.svelte b/src/lib/ChatOptionMenu.svelte index 39b1540..2e3bbbf 100644 --- a/src/lib/ChatOptionMenu.svelte +++ b/src/lib/ChatOptionMenu.svelte @@ -17,11 +17,13 @@ faEye, faEyeSlash } from '@fortawesome/free-solid-svg-icons/index' - import { apiKeyStorage, addChatFromJSON, chatsStorage, checkStateChange, clearChats, clearMessages, copyChat, globalStorage, setGlobalSettingValueByKey, showSetChatSettings, pinMainMenu } from './Storage.svelte' + import { apiKeyStorage, addChatFromJSON, chatsStorage, checkStateChange, clearChats, clearMessages, copyChat, globalStorage, setGlobalSettingValueByKey, showSetChatSettings, pinMainMenu, getChat, deleteChat } from './Storage.svelte' import { exportAsMarkdown, exportChatAsJSON } from './Export.svelte' import { restartProfile } from './Profiles.svelte' import { replace } from 'svelte-spa-router' import { clickOutside } from 'svelte-use-click-outside' + import { openModal } from 'svelte-modals' + import PromptConfirm from './PromptConfirm.svelte' export let chatId export const show = (showHide:boolean = true) => { @@ -29,6 +31,8 @@ } export let style: string = 'is-right' + $: sortedChats = $chatsStorage.sort((a, b) => b.id - a.id) + let showChatMenu = false let chatFileInput @@ -43,20 +47,45 @@ } } - const deleteChat = () => { + const delChat = () => { close() - if (window.confirm('Are you sure you want to delete this chat?')) { - replace('/').then(() => { - chatsStorage.update((chats) => chats.filter((chat) => chat.id !== chatId)) - }) - } + openModal(PromptConfirm, { + title: 'Delete Chat', + message: 'Are you sure you want to delete this chat?', + class: 'is-warning', + confirmButtonClass: 'is-warning', + confirmButton: 'Delete Chat', + onConfirm: () => { + const thisChat = getChat(chatId) + const thisIndex = sortedChats.indexOf(thisChat) + const prevChat = sortedChats[thisIndex - 1] + const nextChat = sortedChats[thisIndex + 1] + const newChat = nextChat || prevChat + if (!newChat) { + // No other chats, clear all and go to home + replace('/').then(() => { deleteChat(chatId) }) + } else { + // Delete the current chat and go to the max chatId + replace(`/chat/${newChat.id}`).then(() => { deleteChat(chatId) }) + } + }, + onCancel: () => {} + }) } const confirmClearChats = () => { close() - if (window.confirm('Are you sure you want to delete ALL of your chats?')) { - clearChats() - } + openModal(PromptConfirm, { + title: 'Delete ALL Chat', + message: 'Are you sure you want to delete ALL of your chats?', + class: 'is-danger', + confirmButtonClass: 'is-danger', + confirmButton: 'Delete ALL', + onConfirm: () => { + clearChats() + }, + onCancel: () => {} + }) } const close = () => { @@ -116,7 +145,7 @@
Export Chat MarkdownAre you sure you want to delete this summary?
Your session may be too long to submit again after you do.
', + asHtml: true, + class: 'is-warning', + confirmButtonClass: 'is-warning', + confirmButton: 'Delete Summary', + onConfirm: () => { + try { + deleteSummaryMessage(chatId, message.uuid) + } catch (e) { + openModal(PromptNotice, errorNotice('Unable to delete summary:', e)) + } + }, + onCancel: () => {} + }) + } else { + try { + deleteMessage(chatId, message.uuid) + } catch (e) { + openModal(PromptNotice, errorNotice('Unable to delete:', e)) } - return - } - try { - deleteMessage(chatId, message.uuid) - } catch (e) { - window.alert('Unable to delete:\n' + e.message) } } @@ -150,21 +162,21 @@ waitingForTruncateConfirm = 0 if (message.summarized) { // is in a summary, so we're summarized - window.alert('Sorry, you can\'t truncate a summarized message') + openModal(PromptNotice, errorNotice('Sorry, you can\'t truncate a summarized message')) return } try { truncateFromMessage(chatId, message.uuid) $submitExitingPromptsNow = true } catch (e) { - window.alert('Unable to delete:\n' + e.message) + openModal(PromptNotice, errorNotice('Unable to delete:', e)) } } const setSuppress = (value:boolean) => { if (message.summarized) { // is in a summary, so we're summarized - window.alert('Sorry, you can\'t suppress a summarized message') + openModal(PromptNotice, errorNotice('Sorry, you can\'t suppress a summarized message')) return } message.suppress = value diff --git a/src/lib/PromptNotice.svelte b/src/lib/PromptNotice.svelte new file mode 100644 index 0000000..5c1c65b --- /dev/null +++ b/src/lib/PromptNotice.svelte @@ -0,0 +1,50 @@ + + +{#if isOpen} +