refac
This commit is contained in:
+10
-6
@@ -2,11 +2,11 @@
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { goto } from '$app/navigation';
|
||||
import { prompts } from '$lib/stores';
|
||||
import { onMount, tick, getContext } from 'svelte';
|
||||
import { onMount, getContext } from 'svelte';
|
||||
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
import { getPromptByCommand, getPrompts, updatePromptByCommand } from '$lib/apis/prompts';
|
||||
import { getPromptById, getPrompts, updatePromptByCommand } from '$lib/apis/prompts';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
import PromptEditor from '$lib/components/workspace/Prompts/PromptEditor.svelte';
|
||||
@@ -14,6 +14,9 @@
|
||||
let prompt = null;
|
||||
let disabled = false;
|
||||
|
||||
// Get prompt ID from route params
|
||||
$: promptId = $page.params.id;
|
||||
|
||||
const onSubmit = async (_prompt) => {
|
||||
console.log(_prompt);
|
||||
const updatedPrompt = await updatePromptByCommand(localStorage.token, _prompt).catch((error) => {
|
||||
@@ -26,6 +29,7 @@
|
||||
await prompts.set(await getPrompts(localStorage.token));
|
||||
// Update local prompt state to reflect the new version
|
||||
prompt = {
|
||||
id: updatedPrompt.id,
|
||||
name: updatedPrompt.name,
|
||||
command: updatedPrompt.command,
|
||||
content: updatedPrompt.content,
|
||||
@@ -36,11 +40,10 @@
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
const command = $page.url.searchParams.get('command');
|
||||
if (command) {
|
||||
const _prompt = await getPromptByCommand(
|
||||
if (promptId) {
|
||||
const _prompt = await getPromptById(
|
||||
localStorage.token,
|
||||
command.replace(/\//g, '')
|
||||
promptId
|
||||
).catch((error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
@@ -49,6 +52,7 @@
|
||||
if (_prompt) {
|
||||
disabled = !_prompt.write_access ?? true;
|
||||
prompt = {
|
||||
id: _prompt.id,
|
||||
name: _prompt.name,
|
||||
command: _prompt.command,
|
||||
content: _prompt.content,
|
||||
Reference in New Issue
Block a user