Setup elysia treaty on client

This commit is contained in:
Dominic Ferrando
2026-06-25 00:27:50 -04:00
parent 038ea7015b
commit 0e5ba9c466
+11 -17
View File
@@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import type { Printful } from "@blade-and-brawn/commerce"; import type { Printful } from "@blade-and-brawn/commerce";
import { PUBLIC_API_URL } from "$env/static/public";
import { onMount } from "svelte"; import { onMount } from "svelte";
import { api } from "$lib/api.js";
const { data } = $props(); const { data } = $props();
@@ -9,9 +9,7 @@
isRunning: false, isRunning: false,
printfulProductIds: [] as number[], printfulProductIds: [] as number[],
poll: async function () { poll: async function () {
const res = (await ( const res = await api.products.sync.get();
await fetch(`${PUBLIC_API_URL}/products/sync`)
).json()) as any;
if (res.data) { if (res.data) {
synchronizer.isRunning = res.data.isRunning; synchronizer.isRunning = res.data.isRunning;
synchronizer.printfulProductIds = synchronizer.printfulProductIds =
@@ -26,16 +24,11 @@
}, },
syncAll: async () => { syncAll: async () => {
synchronizer.startPolling(); synchronizer.startPolling();
await fetch(`${PUBLIC_API_URL}/products/sync`, { method: "POST" }); await api.products.sync.post();
}, },
sync: async (printfulProductId: number) => { sync: async (printfulProductId: number) => {
synchronizer.startPolling(); synchronizer.startPolling();
await fetch( await api.products.sync.post({ printfulProductId });
`${PUBLIC_API_URL}/products/sync/${printfulProductId}`,
{
method: "POST",
},
);
}, },
}); });
@@ -85,12 +78,13 @@
<td <td
><button ><button
onclick={async () => { onclick={async () => {
const productData = (await ( const res = await api
await fetch( .products({
`${PUBLIC_API_URL}/products/${printfulProduct.id}`, printfulProductId:
) printfulProduct.id,
).json()) as any; })
console.log(productData); .get();
console.log(res.data);
}} }}
class="cursor-pointer underline" class="cursor-pointer underline"
> >