feat: function filter example boilerplate

This commit is contained in:
Timothy J. Baek
2024-06-20 01:07:55 -07:00
parent 43e08c6afa
commit 40cde07e5c
2 changed files with 49 additions and 126 deletions

View File

@@ -1,18 +1,19 @@
<script>
import { toast } from 'svelte-sonner';
import { onMount } from 'svelte';
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { getToolById, getTools, updateToolById } from '$lib/apis/tools';
import Spinner from '$lib/components/common/Spinner.svelte';
import ToolkitEditor from '$lib/components/workspace/Tools/ToolkitEditor.svelte';
import { tools } from '$lib/stores';
import { onMount } from 'svelte';
import { toast } from 'svelte-sonner';
import { updateFunctionById, getFunctions, getFunctionById } from '$lib/apis/functions';
let tool = null;
import FunctionEditor from '$lib/components/workspace/Functions/FunctionEditor.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
let func = null;
const saveHandler = async (data) => {
console.log(data);
const res = await updateToolById(localStorage.token, tool.id, {
const res = await updateFunctionById(localStorage.token, func.id, {
id: data.id,
name: data.name,
meta: data.meta,
@@ -23,10 +24,7 @@
});
if (res) {
toast.success('Tool updated successfully');
tools.set(await getTools(localStorage.token));
// await goto('/workspace/tools');
toast.success('Function updated successfully');
}
};
@@ -35,24 +33,24 @@
const id = $page.url.searchParams.get('id');
if (id) {
tool = await getToolById(localStorage.token, id).catch((error) => {
func = await getFunctionById(localStorage.token, id).catch((error) => {
toast.error(error);
goto('/workspace/tools');
goto('/workspace/functions');
return null;
});
console.log(tool);
console.log(func);
}
});
</script>
{#if tool}
<ToolkitEditor
{#if func}
<FunctionEditor
edit={true}
id={tool.id}
name={tool.name}
meta={tool.meta}
content={tool.content}
id={func.id}
name={func.name}
meta={func.meta}
content={func.content}
on:save={(e) => {
saveHandler(e.detail);
}}