fix: append (Clone) to cloned prompt title and clone to prompt id

This commit is contained in:
Silentoplayz 2025-06-03 17:19:24 -04:00
parent 25157ca6ba
commit 2a6d2392a0
3 changed files with 30 additions and 9 deletions

View File

@ -22,7 +22,7 @@
import ChevronRight from '../icons/ChevronRight.svelte'; import ChevronRight from '../icons/ChevronRight.svelte';
import Spinner from '../common/Spinner.svelte'; import Spinner from '../common/Spinner.svelte';
import Tooltip from '../common/Tooltip.svelte'; import Tooltip from '../common/Tooltip.svelte';
import { capitalizeFirstLetter } from '$lib/utils'; import { capitalizeFirstLetter, slugify } from '$lib/utils';
import XMark from '../icons/XMark.svelte'; import XMark from '../icons/XMark.svelte';
const i18n = getContext('i18n'); const i18n = getContext('i18n');
@ -68,7 +68,15 @@
}; };
const cloneHandler = async (prompt) => { const cloneHandler = async (prompt) => {
sessionStorage.prompt = JSON.stringify(prompt); const clonedPrompt = { ...prompt };
clonedPrompt.title = `${clonedPrompt.title} (Clone)`;
const baseCommand = clonedPrompt.command.startsWith('/')
? clonedPrompt.command.substring(1)
: clonedPrompt.command;
clonedPrompt.command = slugify(`${baseCommand} clone`);
sessionStorage.prompt = JSON.stringify(clonedPrompt);
goto('/workspace/prompts/create'); goto('/workspace/prompts/create');
}; };

View File

@ -13,6 +13,7 @@
export let onSubmit: Function; export let onSubmit: Function;
export let edit = false; export let edit = false;
export let prompt = null; export let prompt = null;
export let clone = false;
const i18n = getContext('i18n'); const i18n = getContext('i18n');
@ -68,8 +69,8 @@
if (prompt) { if (prompt) {
title = prompt.title; title = prompt.title;
await tick(); await tick();
command = prompt.command.at(0) === '/' ? prompt.command.slice(1) : prompt.command; command = prompt.command.at(0) === '/' ? prompt.command.slice(1) : prompt.command;
hasManualEdit = true;
content = prompt.content; content = prompt.content;
accessControl = prompt?.access_control === undefined ? {} : prompt?.access_control; accessControl = prompt?.access_control === undefined ? {} : prompt?.access_control;

View File

@ -9,14 +9,22 @@
import { createNewPrompt, getPrompts } from '$lib/apis/prompts'; import { createNewPrompt, getPrompts } from '$lib/apis/prompts';
import PromptEditor from '$lib/components/workspace/Prompts/PromptEditor.svelte'; import PromptEditor from '$lib/components/workspace/Prompts/PromptEditor.svelte';
let prompt = null; let prompt: {
title: string;
command: string;
content: string;
access_control: any | null;
} | null = null;
let clone = false;
const onSubmit = async (_prompt) => { const onSubmit = async (_prompt) => {
const prompt = await createNewPrompt(localStorage.token, _prompt).catch((error) => { const res = await createNewPrompt(localStorage.token, _prompt).catch((error) => {
toast.error(`${error}`); toast.error(`${error}`);
return null; return null;
}); });
if (prompt) { if (res) {
toast.success($i18n.t('Prompt created successfully')); toast.success($i18n.t('Prompt created successfully'));
await prompts.set(await getPrompts(localStorage.token)); await prompts.set(await getPrompts(localStorage.token));
@ -33,8 +41,9 @@
) )
return; return;
const _prompt = JSON.parse(event.data); const _prompt = JSON.parse(event.data);
console.log(_prompt); console.log('Received prompt via window message:', _prompt);
clone = true;
prompt = { prompt = {
title: _prompt.title, title: _prompt.title,
command: _prompt.command, command: _prompt.command,
@ -49,18 +58,21 @@
if (sessionStorage.prompt) { if (sessionStorage.prompt) {
const _prompt = JSON.parse(sessionStorage.prompt); const _prompt = JSON.parse(sessionStorage.prompt);
sessionStorage.removeItem('prompt');
console.log('Received prompt via sessionStorage:', _prompt);
clone = true;
prompt = { prompt = {
title: _prompt.title, title: _prompt.title,
command: _prompt.command, command: _prompt.command,
content: _prompt.content, content: _prompt.content,
access_control: null access_control: null
}; };
sessionStorage.removeItem('prompt');
} }
}); });
</script> </script>
{#key prompt} {#key prompt}
<PromptEditor {prompt} {onSubmit} /> <PromptEditor {prompt} {onSubmit} {clone} />
{/key} {/key}