refac: prompts frontend

This commit is contained in:
Timothy Jaeryang Baek 2024-11-16 20:53:05 -08:00
parent b81cd15ced
commit e78657f07e
2 changed files with 9 additions and 2 deletions

View File

@ -1,9 +1,11 @@
<script> <script lang="ts">
import { toast } from 'svelte-sonner'; import { toast } from 'svelte-sonner';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { prompts } from '$lib/stores'; import { prompts } from '$lib/stores';
import { onMount, tick, getContext } from 'svelte'; import { onMount, tick, getContext } from 'svelte';
const i18n = getContext('i18n');
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';
@ -15,6 +17,8 @@
}); });
if (prompt) { if (prompt) {
toast.success($i18n.t('Prompt created successfully'));
await prompts.set(await getPrompts(localStorage.token)); await prompts.set(await getPrompts(localStorage.token));
await goto('/workspace/prompts'); await goto('/workspace/prompts');
} }

View File

@ -1,9 +1,11 @@
<script> <script lang="ts">
import { toast } from 'svelte-sonner'; import { toast } from 'svelte-sonner';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { prompts } from '$lib/stores'; import { prompts } from '$lib/stores';
import { onMount, tick, getContext } from 'svelte'; import { onMount, tick, getContext } from 'svelte';
const i18n = getContext('i18n');
import { getPromptByCommand, getPrompts, updatePromptByCommand } from '$lib/apis/prompts'; import { getPromptByCommand, getPrompts, updatePromptByCommand } from '$lib/apis/prompts';
import { page } from '$app/stores'; import { page } from '$app/stores';
@ -18,6 +20,7 @@
}); });
if (prompt) { if (prompt) {
toast.success($i18n.t('Prompt updated successfully'));
await prompts.set(await getPrompts(localStorage.token)); await prompts.set(await getPrompts(localStorage.token));
await goto('/workspace/prompts'); await goto('/workspace/prompts');
} }