Add the whole api stack for weight

This commit is contained in:
2024-08-09 23:18:50 +02:00
parent 57d88c093e
commit 1edc3e83ef
11 changed files with 570 additions and 16 deletions

View File

@@ -0,0 +1,47 @@
<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'
let item: Weight = {
weight: 0
}
let weight: string | null = null
async function update(event: KeyboardEvent & { currentTarget: (EventTarget & HTMLTableCellElement) }) {
if (!weight) return
weight = weight.trim()
if (event.key == 'Enter') {
event.preventDefault()
item.weight = parseFloat(weight)
const [dbRow, err]: [Weight, Err] = await WeightService.Create(item)
weight = ''
if (err) {
toast.error(err)
return
}
RefreshStores()
}
}
</script>
<template>
<tr class="border-b border-gray-200 dark:border-gray-700 text-lg font-bold">
<th class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap bg-gray-50 dark:text-white dark:bg-gray-800"
scope="row">
</th>
<td bind:innerText={weight}
class:border-[3px]={!weight}
class:border-red-600={!weight}
class="px-6 py-4 overflow-hidden"
contenteditable="true"
autofocus
on:keydown={update}>
</td>
</tr>
</template>