Roll-back to using confirm/alert for consistency

This commit is contained in:
Webifi 2023-05-27 12:29:39 -05:00
parent a4f4475682
commit 8ce869c717
1 changed files with 11 additions and 75 deletions

View File

@ -143,23 +143,6 @@
setTimeout(() => document.querySelector('.chat-focus-point')?.scrollIntoView({ behavior: 'smooth', block: 'end' }), 0) setTimeout(() => document.querySelector('.chat-focus-point')?.scrollIntoView({ behavior: 'smooth', block: 'end' }), 0)
} }
// Show question modal
// Yeah, probably should make a component, but...
let qYesNo = (v) => {}
let question:any = null
const askQuestion = (title, message, yesFn, noFn, cls?) => {
qYesNo = (v) => { question = null; v ? yesFn() : noFn() }
question = [title, message, cls]
}
// Show notice modal
let nDone = (v) => {}
let notice:any = null
const doNotice = (title, message, doneFn, cls?) => {
nDone = (v) => { notice = null; doneFn() }
notice = [title, message, cls]
}
// Send API request // Send API request
const sendRequest = async (messages: Message[], doingSummary?:boolean, withSummary?:boolean): Promise<Response> => { const sendRequest = async (messages: Message[], doingSummary?:boolean, withSummary?:boolean): Promise<Response> => {
// Show updating bar // Show updating bar
@ -556,13 +539,13 @@
(typeof setting.afterChange === 'function') && setting.afterChange(chatId, setting) && showSettingsModal++ (typeof setting.afterChange === 'function') && setting.afterChange(chatId, setting) && showSettingsModal++
} }
if (setting.key === 'profile' && checkSessionActivity(chatId)) { if (setting.key === 'profile' && checkSessionActivity(chatId)) {
askQuestion( if (window.confirm('Switching profiles will clear your current chat session. Are you sure you want to continue?')) {
'Warning', // Switch profiles
'Switching profiles will clear your current chat session. Are you sure you want to continue?', () => { doSet() }
() => { doSet() }, // Yes } else {
() => { el.value = getChatSettingValue(chatId, setting) }, // No // Roll-back
'is-warning' () => { el.value = getChatSettingValue(chatId, setting) }
) }
} else { } else {
debounce[setting.key] = setTimeout(doSet, 250) debounce[setting.key] = setTimeout(doSet, 250)
} }
@ -584,7 +567,7 @@
try { try {
saveCustomProfile(chat.settings) saveCustomProfile(chat.settings)
} catch (e) { } catch (e) {
doNotice('Error saving profile', e.message, () => {}, 'is-danger') alert('Error saving profile: ' + e.message)
} }
} }
@ -614,7 +597,7 @@
updateProfileSelectOptions() updateProfileSelectOptions()
showSettingsModal && showSettingsModal++ showSettingsModal && showSettingsModal++
} catch (e) { } catch (e) {
doNotice('Error cloning profile', e.message, () => {}, 'is-danger') alert('Error cloning profile: ' + e.message)
} }
} }
@ -629,7 +612,7 @@
updateProfileSelectOptions() updateProfileSelectOptions()
showSettings() showSettings()
} catch (e) { } catch (e) {
doNotice('Error deleting profile', e.message, () => {}, 'is-danger') alert('Error deleting profile: ' + e.message)
} }
} }
@ -652,7 +635,7 @@
updateProfileSelectOptions() updateProfileSelectOptions()
showSettingsModal && showSettingsModal++ showSettingsModal && showSettingsModal++
} catch (e) { } catch (e) {
doNotice('Unable to import profile', e.message, () => {}, 'is-danger') alert('Unable to import profile: ' + e.message)
} }
} }
} }
@ -871,53 +854,6 @@
</div> </div>
</div> </div>
<!-- notice modal -->
<div class="modal" class:is-active={!!notice}>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div class="modal-background" on:click|preventDefault={() => { nDone(false) }}></div>
<div class="modal-content">
<article class="message {((notice && notice[2]) || '')}">
<div class="message-header">
<p>{notice && notice[0]}</p>
<button class="delete" aria-label="delete" on:click|preventDefault={() => { nDone(false) }}></button>
</div>
<div class="message-body">
{notice && notice[1]}
</div>
<footer style="padding: 1em">
<button class="button is-success" on:click|preventDefault={() => { nDone(true) }}>Close</button>
</footer>
</article>
</div>
<!-- <button class="modal-close is-large" aria-label="close"></button> -->
</div>
<!-- question modal -->
<div class="modal" class:is-active={!!question}>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div class="modal-background" on:click|preventDefault={() => { qYesNo(false) }}></div>
<div class="modal-content">
<article class="message {((question && question[2]) || '')}">
<div class="message-header">
<p>{question && question[0]}</p>
<button class="delete" aria-label="delete" on:click|preventDefault={() => { qYesNo(false) }}></button>
</div>
<div class="message-body">
{question && question[1]}
</div>
<footer style="padding: 1em">
<button class="button is-success" on:click|preventDefault={() => { qYesNo(true) }}>Continue</button>
<button class="button"on:click|preventDefault={() => { qYesNo(false) }}>Cancel</button>
</footer>
</article>
</div>
<!-- <button class="modal-close is-large" aria-label="close"></button> -->
</div>
<!-- rename modal --> <!-- rename modal -->
<form class="modal" bind:this={chatNameSettings} on:submit={saveChatNameSettings}> <form class="modal" bind:this={chatNameSettings} on:submit={saveChatNameSettings}>
<!-- svelte-ignore a11y-click-events-have-key-events --> <!-- svelte-ignore a11y-click-events-have-key-events -->