Implement weight components

This commit is contained in:
2024-08-09 23:40:31 +02:00
parent e8da257bf1
commit 2f161bed79
6 changed files with 68 additions and 76 deletions

View File

@@ -1,12 +1,13 @@
<script lang="ts">
import { toast } from 'svelte-sonner'
import type { Err } from '$lib/types'
import { type Weight, WeightService } from '$lib/database/weight'
import { weightStore } from '$lib/store/weight/weightStore'
import { RefreshStores } from '$lib/utils'
import { main } from "$wails/models";
import { CreateWeight } from '$wails/main/App';
import { weightStore } from '$lib/store/Weight/weightStore';
let item: Weight = {
weight: 0
let item: main.Weight = {
weight: 0,
rowid: 0,
date: ''
}
let weight: string | null = null
@@ -18,14 +19,20 @@
event.preventDefault()
item.weight = parseFloat(weight)
const [dbRow, err]: [Weight, Err] = await WeightService.Create(item)
weight = ''
if (err) {
toast.error(err)
if (isNaN(item.weight)) {
toast.error('Weight must be a number')
return
}
RefreshStores()
const res = await CreateWeight(item)
weight = ''
if (!res.success) {
toast.error(`failed to create weight with error ${res.error}`)
return
}
console.log("update");
weightStore.update((value) => [res.data, ...value]);
}
}
</script>