This commit is contained in:
Timothy Jaeryang Baek
2024-11-16 17:49:13 -08:00
parent af0ba53715
commit a1ce8422fd
9 changed files with 67 additions and 69 deletions
@@ -8,14 +8,11 @@
import PromptEditor from '$lib/components/workspace/Prompts/PromptEditor.svelte';
let prompt = null;
const onSubmit = async ({ title, command, content }) => {
const prompt = await createNewPrompt(localStorage.token, command, title, content).catch(
(error) => {
toast.error(error);
return null;
}
);
const onSubmit = async (_prompt) => {
const prompt = await createNewPrompt(localStorage.token, _prompt).catch((error) => {
toast.error(error);
return null;
});
if (prompt) {
await prompts.set(await getPrompts(localStorage.token));
@@ -37,7 +34,8 @@
prompt = {
title: _prompt.title,
command: _prompt.command,
content: _prompt.content
content: _prompt.content,
access_control: null
};
});
@@ -51,7 +49,8 @@
prompt = {
title: _prompt.title,
command: _prompt.command,
content: _prompt.content
content: _prompt.content,
access_control: null
};
sessionStorage.removeItem('prompt');
}
@@ -4,19 +4,18 @@
import { prompts } from '$lib/stores';
import { onMount, tick, getContext } from 'svelte';
import { getPrompts, updatePromptByCommand } from '$lib/apis/prompts';
import { getPromptByCommand, getPrompts, updatePromptByCommand } from '$lib/apis/prompts';
import { page } from '$app/stores';
import PromptEditor from '$lib/components/workspace/Prompts/PromptEditor.svelte';
let prompt = null;
const onSubmit = async ({ title, command, content }) => {
const prompt = await updatePromptByCommand(localStorage.token, command, title, content).catch(
(error) => {
toast.error(error);
return null;
}
);
const onSubmit = async (_prompt) => {
console.log(_prompt);
const prompt = await updatePromptByCommand(localStorage.token, _prompt).catch((error) => {
toast.error(error);
return null;
});
if (prompt) {
await prompts.set(await getPrompts(localStorage.token));
@@ -27,13 +26,20 @@
onMount(async () => {
const command = $page.url.searchParams.get('command');
if (command) {
const _prompt = $prompts.filter((prompt) => prompt.command === command).at(0);
const _prompt = await getPromptByCommand(
localStorage.token,
command.replace(/\//g, '')
).catch((error) => {
toast.error(error);
return null;
});
if (_prompt) {
prompt = {
title: _prompt.title,
command: _prompt.command,
content: _prompt.content
content: _prompt.content,
access_control: _prompt?.access_control ?? null
};
} else {
goto('/workspace/prompts');