From ecf1d89a8b03d99882b1a652cdb15ce8017b5649 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 23 Jun 2024 15:57:16 -0700 Subject: [PATCH] refac: prompts ui --- src/lib/components/workspace/Prompts.svelte | 102 ++++++------------ .../workspace/Prompts/PromptMenu.svelte | 92 ++++++++++++++++ 2 files changed, 127 insertions(+), 67 deletions(-) create mode 100644 src/lib/components/workspace/Prompts/PromptMenu.svelte diff --git a/src/lib/components/workspace/Prompts.svelte b/src/lib/components/workspace/Prompts.svelte index 65c8442e8..05884208b 100644 --- a/src/lib/components/workspace/Prompts.svelte +++ b/src/lib/components/workspace/Prompts.svelte @@ -8,13 +8,16 @@ import { createNewPrompt, deletePromptByCommand, getPrompts } from '$lib/apis/prompts'; import { error } from '@sveltejs/kit'; import { goto } from '$app/navigation'; + import PromptMenu from './Prompts/PromptMenu.svelte'; + import EllipsisHorizontal from '../icons/EllipsisHorizontal.svelte'; const i18n = getContext('i18n'); let importFiles = ''; let query = ''; let promptsImportInputElement: HTMLInputElement; - const sharePrompt = async (prompt) => { + + const shareHandler = async (prompt) => { toast.success($i18n.t('Redirecting you to OpenWebUI Community')); const url = 'https://openwebui.com'; @@ -32,7 +35,20 @@ ); }; - const deletePrompt = async (command) => { + const cloneHandler = async (prompt) => { + sessionStorage.prompt = JSON.stringify(prompt); + goto('/workspace/prompts/create'); + }; + + const exportHandler = async (prompt) => { + let blob = new Blob([JSON.stringify([prompt])], { + type: 'application/json' + }); + saveAs(blob, `prompt-export-${Date.now()}.json`); + }; + + const deleteHandler = async (prompt) => { + const command = prompt.command; await deletePromptByCommand(localStorage.token, command); await prompts.set(await getPrompts(localStorage.token)); }; @@ -128,76 +144,28 @@ - - - - - + + + {/each} diff --git a/src/lib/components/workspace/Prompts/PromptMenu.svelte b/src/lib/components/workspace/Prompts/PromptMenu.svelte new file mode 100644 index 000000000..9a4177b1e --- /dev/null +++ b/src/lib/components/workspace/Prompts/PromptMenu.svelte @@ -0,0 +1,92 @@ + + + { + if (e.detail === false) { + onClose(); + } + }} +> + + + + +
+ + { + shareHandler(); + }} + > + +
{$i18n.t('Share')}
+
+ + { + cloneHandler(); + }} + > + + +
{$i18n.t('Clone')}
+
+ + { + exportHandler(); + }} + > + + +
{$i18n.t('Export')}
+
+ +
+ + { + deleteHandler(); + }} + > + +
{$i18n.t('Delete')}
+
+
+
+