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
replace(`/chat/${newChat.id}`).then(() => { deleteChat(chatId) })
}
},
onCancel: () => {}
}
})
}
@ -83,8 +82,7 @@
confirmButton: 'Delete ALL',
onConfirm: () => {
clearChats()
},
onCancel: () => {}
}
})
}

View File

@ -33,8 +33,6 @@
import ChatSettingField from './ChatSettingField.svelte'
import { getModelMaxTokens } from './Stats.svelte'
import { replace } from 'svelte-spa-router'
import { openModal } from 'svelte-modals'
import PromptNotice from './PromptNotice.svelte'
export let chatId:number
export const show = () => { showSettings() }
@ -103,7 +101,7 @@
applyProfile(chatId, clone.profile)
refreshSettings()
} 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)
refreshSettings()
} catch (e) {
openModal(PromptNotice, errorNotice('Error deleting profile:', e))
errorNotice('Error deleting profile:', e)
}
}
@ -140,7 +138,7 @@
saveCustomProfile(profile)
refreshSettings()
} catch (e) {
openModal(PromptNotice, errorNotice('Unable to import profile:', e))
errorNotice('Unable to import profile:', e)
}
}
}
@ -203,7 +201,7 @@
saveCustomProfile(chat.settings)
refreshSettings()
} 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 { openModal } from 'svelte-modals'
import PromptConfirm from './PromptConfirm.svelte'
import PromptNotice from './PromptNotice.svelte'
export let message:Message
export let chatId:number
@ -118,7 +117,7 @@
waitingForDeleteConfirm = 0
if (message.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
}
if (message.summary) {
@ -134,16 +133,15 @@
try {
deleteSummaryMessage(chatId, message.uuid)
} catch (e) {
openModal(PromptNotice, errorNotice('Unable to delete summary:', e))
errorNotice('Unable to delete summary:', e)
}
},
onCancel: () => {}
}
})
} else {
try {
deleteMessage(chatId, message.uuid)
} catch (e) {
openModal(PromptNotice, errorNotice('Unable to delete:', e))
errorNotice('Unable to delete:', e)
}
}
}
@ -162,21 +160,21 @@
waitingForTruncateConfirm = 0
if (message.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
}
try {
truncateFromMessage(chatId, message.uuid)
$submitExitingPromptsNow = true
} catch (e) {
openModal(PromptNotice, errorNotice('Unable to delete:', e))
errorNotice('Unable to delete:', e)
}
}
const setSuppress = (value:boolean) => {
if (message.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
}
message.suppress = value

View File

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

View File

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

View File

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

View File

@ -1,5 +1,7 @@
<script context="module" lang="ts">
import { compare } from 'stacking-order'
import { openModal } from 'svelte-modals'
import PromptNotice from './PromptNotice.svelte'
export const sizeTextElements = () => {
const els = document.querySelectorAll('textarea.auto-size')
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 => {
return {
openModal(PromptNotice, {
title: 'Error',
class: 'is-danger',
message: message + (error ? '<br>' + error.message : ''),
asHtml: true,
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>