Simplify alert modals

This commit is contained in:
Webifi 2023-06-05 22:47:55 -05:00
parent e6082144cb
commit 886b3d463d
7 changed files with 31 additions and 27 deletions

View File

@ -68,8 +68,7 @@
// Delete the current chat and go to the max chatId // Delete the current chat and go to the max chatId
replace(`/chat/${newChat.id}`).then(() => { deleteChat(chatId) }) replace(`/chat/${newChat.id}`).then(() => { deleteChat(chatId) })
} }
}, }
onCancel: () => {}
}) })
} }
@ -83,8 +82,7 @@
confirmButton: 'Delete ALL', confirmButton: 'Delete ALL',
onConfirm: () => { onConfirm: () => {
clearChats() clearChats()
}, }
onCancel: () => {}
}) })
} }

View File

@ -33,8 +33,6 @@
import ChatSettingField from './ChatSettingField.svelte' import ChatSettingField from './ChatSettingField.svelte'
import { getModelMaxTokens } from './Stats.svelte' import { getModelMaxTokens } from './Stats.svelte'
import { replace } from 'svelte-spa-router' import { replace } from 'svelte-spa-router'
import { openModal } from 'svelte-modals'
import PromptNotice from './PromptNotice.svelte'
export let chatId:number export let chatId:number
export const show = () => { showSettings() } export const show = () => { showSettings() }
@ -103,7 +101,7 @@
applyProfile(chatId, clone.profile) applyProfile(chatId, clone.profile)
refreshSettings() refreshSettings()
} catch (e) { } catch (e) {
openModal(PromptNotice, errorNotice('Error cloning profile:', e)) errorNotice('Error cloning profile:', e)
} }
} }
@ -117,7 +115,7 @@
applyProfile(chatId, chat.settings.profile as any) applyProfile(chatId, chat.settings.profile as any)
refreshSettings() refreshSettings()
} catch (e) { } catch (e) {
openModal(PromptNotice, errorNotice('Error deleting profile:', e)) errorNotice('Error deleting profile:', e)
} }
} }
@ -140,7 +138,7 @@
saveCustomProfile(profile) saveCustomProfile(profile)
refreshSettings() refreshSettings()
} catch (e) { } catch (e) {
openModal(PromptNotice, errorNotice('Unable to import profile:', e)) errorNotice('Unable to import profile:', e)
} }
} }
} }
@ -203,7 +201,7 @@
saveCustomProfile(chat.settings) saveCustomProfile(chat.settings)
refreshSettings() refreshSettings()
} catch (e) { } catch (e) {
openModal(PromptNotice, errorNotice('Error saving profile:', e)) errorNotice('Error saving profile:', e)
} }
} }

View File

@ -10,7 +10,6 @@
import { errorNotice, scrollIntoViewWithOffset } from './Util.svelte' import { errorNotice, scrollIntoViewWithOffset } from './Util.svelte'
import { openModal } from 'svelte-modals' import { openModal } from 'svelte-modals'
import PromptConfirm from './PromptConfirm.svelte' import PromptConfirm from './PromptConfirm.svelte'
import PromptNotice from './PromptNotice.svelte'
export let message:Message export let message:Message
export let chatId:number export let chatId:number
@ -118,7 +117,7 @@
waitingForDeleteConfirm = 0 waitingForDeleteConfirm = 0
if (message.summarized) { if (message.summarized) {
// is in a summary, so we're summarized // is in a summary, so we're summarized
openModal(PromptNotice, errorNotice('Sorry, you can\'t delete a summarized message')) errorNotice('Sorry, you can\'t delete a summarized message')
return return
} }
if (message.summary) { if (message.summary) {
@ -134,16 +133,15 @@
try { try {
deleteSummaryMessage(chatId, message.uuid) deleteSummaryMessage(chatId, message.uuid)
} catch (e) { } catch (e) {
openModal(PromptNotice, errorNotice('Unable to delete summary:', e)) errorNotice('Unable to delete summary:', e)
} }
}, }
onCancel: () => {}
}) })
} else { } else {
try { try {
deleteMessage(chatId, message.uuid) deleteMessage(chatId, message.uuid)
} catch (e) { } catch (e) {
openModal(PromptNotice, errorNotice('Unable to delete:', e)) errorNotice('Unable to delete:', e)
} }
} }
} }
@ -162,21 +160,21 @@
waitingForTruncateConfirm = 0 waitingForTruncateConfirm = 0
if (message.summarized) { if (message.summarized) {
// is in a summary, so we're summarized // is in a summary, so we're summarized
openModal(PromptNotice, errorNotice('Sorry, you can\'t truncate a summarized message')) errorNotice('Sorry, you can\'t truncate a summarized message')
return return
} }
try { try {
truncateFromMessage(chatId, message.uuid) truncateFromMessage(chatId, message.uuid)
$submitExitingPromptsNow = true $submitExitingPromptsNow = true
} catch (e) { } catch (e) {
openModal(PromptNotice, errorNotice('Unable to delete:', e)) errorNotice('Unable to delete:', e)
} }
} }
const setSuppress = (value:boolean) => { const setSuppress = (value:boolean) => {
if (message.summarized) { if (message.summarized) {
// is in a summary, so we're summarized // is in a summary, so we're summarized
openModal(PromptNotice, errorNotice('Sorry, you can\'t suppress a summarized message')) errorNotice('Sorry, you can\'t suppress a summarized message')
return return
} }
message.suppress = value message.suppress = value

View File

@ -8,7 +8,7 @@
export let asHtml:boolean = false export let asHtml:boolean = false
export let onConfirm:()=>boolean|void export let onConfirm:()=>boolean|void
export let onCancel:()=>boolean|void export let onCancel:(()=>boolean|void)|null = null
export let confirmButton:string = 'Okay' export let confirmButton:string = 'Okay'
export let confirmButtonClass:string = 'is-info' export let confirmButtonClass:string = 'is-info'

View File

@ -7,7 +7,7 @@
export let message:string export let message:string
export let asHtml:boolean = false export let asHtml:boolean = false
export let onConfirm:()=>boolean|void export let onConfirm:(()=>boolean|void)|null = null
export let confirmButton:string = 'Okay' export let confirmButton:string = 'Okay'
export let confirmButtonClass:string = 'is-info' export let confirmButtonClass:string = 'is-info'

View File

@ -5,8 +5,6 @@
import { getChatSettingObjectByKey, getGlobalSettingObjectByKey, getChatDefaults, getExcludeFromProfile } from './Settings.svelte' import { getChatSettingObjectByKey, getGlobalSettingObjectByKey, getChatDefaults, getExcludeFromProfile } from './Settings.svelte'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import { getProfile, getProfiles, isStaticProfile, newNameForProfile, restartProfile } from './Profiles.svelte' import { getProfile, getProfiles, isStaticProfile, newNameForProfile, restartProfile } from './Profiles.svelte'
import { openModal } from 'svelte-modals'
import PromptNotice from './PromptNotice.svelte'
import { errorNotice } from './Util.svelte' import { errorNotice } from './Util.svelte'
export const chatsStorage = persisted('chats', [] as Chat[]) export const chatsStorage = persisted('chats', [] as Chat[])
@ -59,11 +57,11 @@
try { try {
chat = JSON.parse(json) as Chat chat = JSON.parse(json) as Chat
if (!chat.settings || !chat.messages || isNaN(chat.id)) { if (!chat.settings || !chat.messages || isNaN(chat.id)) {
openModal(PromptNotice, errorNotice('Not valid Chat JSON')) errorNotice('Not valid Chat JSON')
return 0 return 0
} }
} catch (err) { } catch (err) {
openModal(PromptNotice, errorNotice("Can't parse file JSON")) errorNotice("Can't parse file JSON")
return 0 return 0
} }

View File

@ -1,5 +1,7 @@
<script context="module" lang="ts"> <script context="module" lang="ts">
import { compare } from 'stacking-order' import { compare } from 'stacking-order'
import { openModal } from 'svelte-modals'
import PromptNotice from './PromptNotice.svelte'
export const sizeTextElements = () => { export const sizeTextElements = () => {
const els = document.querySelectorAll('textarea.auto-size') const els = document.querySelectorAll('textarea.auto-size')
for (let i:number = 0, l = els.length; i < l; i++) autoGrowInput(els[i] as HTMLTextAreaElement) for (let i:number = 0, l = els.length; i < l; i++) autoGrowInput(els[i] as HTMLTextAreaElement)
@ -53,13 +55,23 @@
} }
export const errorNotice = (message:string, error:Error|undefined = undefined):any => { export const errorNotice = (message:string, error:Error|undefined = undefined):any => {
return { openModal(PromptNotice, {
title: 'Error', title: 'Error',
class: 'is-danger', class: 'is-danger',
message: message + (error ? '<br>' + error.message : ''), message: message + (error ? '<br>' + error.message : ''),
asHtml: true, asHtml: true,
onConfirm: () => {} onConfirm: () => {}
} })
}
export const warningNotice = (message:string, error:Error|undefined = undefined):any => {
openModal(PromptNotice, {
title: 'Warning',
class: 'is-warning',
message: message + (error ? '<br>' + error.message : ''),
asHtml: true,
onConfirm: () => {}
})
} }
</script> </script>