Add the whole api stack for weight
This commit is contained in:
47
frontend/src/lib/components/Weight/EmptyWeightComp.svelte
Normal file
47
frontend/src/lib/components/Weight/EmptyWeightComp.svelte
Normal 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>
|
Reference in New Issue
Block a user