Implement weight components
This commit is contained in:
@@ -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>
|
||||
|
Reference in New Issue
Block a user