Add new chat from current to chat option menu

This commit is contained in:
Webifi 2023-06-22 21:08:50 -05:00
parent 3314252c3c
commit 2098bc7a0b
2 changed files with 12 additions and 3 deletions

View File

@ -24,7 +24,7 @@
import { clickOutside } from 'svelte-use-click-outside'
import { openModal } from 'svelte-modals'
import PromptConfirm from './PromptConfirm.svelte'
import { startNewChatWithWarning } from './Util.svelte'
import { startNewChatWithWarning, startNewChatFromChatId } from './Util.svelte'
export let chatId
export const show = (showHide:boolean = true) => {
@ -123,7 +123,10 @@
</a>
<hr class="dropdown-divider">
<a href={'#'} class:is-disabled={!$apiKeyStorage} on:click|preventDefault={() => { $apiKeyStorage && close(); $apiKeyStorage && startNewChatWithWarning(chatId) }} class="dropdown-item">
<span class="menu-icon"><Fa icon={faSquarePlus}/></span> New Chat
<span class="menu-icon"><Fa icon={faSquarePlus}/></span> New Chat from Default
</a>
<a href={'#'} class:is-disabled={!chatId} on:click|preventDefault={() => { chatId && close(); chatId && startNewChatFromChatId(chatId) }} class="dropdown-item">
<span class="menu-icon"><Fa icon={faSquarePlus}/></span> New Chat from Current
</a>
<a href={'#'} class="dropdown-item" class:is-disabled={!chatId} on:click|preventDefault={() => { if (chatId) close(); copyChat(chatId) }}>
<span class="menu-icon"><Fa icon={faClone}/></span> Clone Chat

View File

@ -2,7 +2,7 @@
import { compare } from 'stacking-order'
import { openModal } from 'svelte-modals'
import PromptNotice from './PromptNotice.svelte'
import { getChat } from './Storage.svelte'
import { addChat, getChat } from './Storage.svelte'
import { replace } from 'svelte-spa-router'
import PromptConfirm from './PromptConfirm.svelte'
export const sizeTextElements = () => {
@ -115,6 +115,12 @@
})
}
export const startNewChatFromChatId = (chatId: number) => {
const newChatId = addChat(getChat(chatId).settings)
// go to new chat
replace(`/chat/${newChatId}`)
}
export const startNewChatWithWarning = (activeChatId: number|undefined) => {
if (activeChatId && getChat(activeChatId).settings.isDirty) {
openModal(PromptConfirm, {