Code format
This commit is contained in:
23
src/lib/components/AggregatedFood/AggregatedFoodComp.svelte
Normal file
23
src/lib/components/AggregatedFood/AggregatedFoodComp.svelte
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { AggregatedFood } from '$lib/database/food'
|
||||||
|
|
||||||
|
export let item: AggregatedFood
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<tr class="border-b border-gray-200 dark:border-gray-700">
|
||||||
|
<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">
|
||||||
|
{item.date}
|
||||||
|
</th>
|
||||||
|
<td class="px-6 py-4">
|
||||||
|
{item.amount}
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4 bg-gray-50 dark:bg-gray-800">
|
||||||
|
{item.avgPer100}
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4">
|
||||||
|
{item.energy}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</template>
|
@@ -1,9 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
|
||||||
import FoodComp from '$components/Food/FoodComp.svelte'
|
import type { AggregatedFood } from '$lib/database/food'
|
||||||
import type { Food } from '$lib/database/food'
|
import AggregatedFoodComp from '$components/AggregatedFood/AggregatedFoodComp.svelte'
|
||||||
|
|
||||||
export let items: Food[] = []
|
export let items: AggregatedFood[] = []
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -12,23 +12,23 @@
|
|||||||
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
|
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
|
||||||
<thead class="text-xs text-gray-700 uppercase dark:text-gray-400">
|
<thead class="text-xs text-gray-700 uppercase dark:text-gray-400">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" class="px-6 py-3 bg-gray-50 dark:bg-gray-800">
|
<th class="px-6 py-3 bg-gray-50 dark:bg-gray-800" scope="col">
|
||||||
Period
|
Period
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3">
|
<th class="px-6 py-3" scope="col">
|
||||||
Amount
|
Amount
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3 bg-gray-50 dark:bg-gray-800">
|
<th class="px-6 py-3 bg-gray-50 dark:bg-gray-800" scope="col">
|
||||||
AvgPer100
|
AvgPer100
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3">
|
<th class="px-6 py-3" scope="col">
|
||||||
Energy
|
Energy
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{#each items as f}
|
{#each items as f}
|
||||||
<FoodComp item="{f}" />
|
<AggregatedFoodComp item="{f}" />
|
||||||
{/each}
|
{/each}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@@ -45,18 +45,18 @@
|
|||||||
<th class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap bg-gray-50 dark:text-white dark:bg-gray-800"
|
<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">
|
scope="row">
|
||||||
</th>
|
</th>
|
||||||
<td class="px-6 py-4"
|
<td bind:innerText={name}
|
||||||
bind:innerText={name}
|
class="px-6 py-4"
|
||||||
contenteditable="true"
|
contenteditable="true"
|
||||||
on:keyup={update}>
|
on:keyup={update}>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4 bg-gray-50 dark:bg-gray-800"
|
<td bind:innerText={description}
|
||||||
bind:innerText={description}
|
class="px-6 py-4 bg-gray-50 dark:bg-gray-800"
|
||||||
contenteditable="true"
|
contenteditable="true"
|
||||||
on:keyup={update}>
|
on:keyup={update}>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4"
|
<td bind:innerText={amount}
|
||||||
bind:innerText={amount}
|
class="px-6 py-4"
|
||||||
contenteditable="true"
|
contenteditable="true"
|
||||||
on:keyup={update}>
|
on:keyup={update}>
|
||||||
</td>
|
</td>
|
||||||
|
@@ -8,8 +8,8 @@
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<tr class="border-b border-gray-200 dark:border-gray-700">
|
<tr class="border-b border-gray-200 dark:border-gray-700">
|
||||||
<th scope="row"
|
<th class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap bg-gray-50 dark:text-white dark:bg-gray-800"
|
||||||
class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap bg-gray-50 dark:text-white dark:bg-gray-800">
|
scope="row">
|
||||||
{item.date}
|
{item.date}
|
||||||
</th>
|
</th>
|
||||||
<td class="px-6 py-4">
|
<td class="px-6 py-4">
|
||||||
|
@@ -13,22 +13,22 @@
|
|||||||
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
|
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
|
||||||
<thead class="text-xs text-gray-700 uppercase dark:text-gray-400">
|
<thead class="text-xs text-gray-700 uppercase dark:text-gray-400">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" class="px-6 py-3 bg-gray-50 dark:bg-gray-800">
|
<th class="px-6 py-3 bg-gray-50 dark:bg-gray-800" scope="col">
|
||||||
Date
|
Date
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3">
|
<th class="px-6 py-3" scope="col">
|
||||||
Food
|
Food
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3 bg-gray-50 dark:bg-gray-800">
|
<th class="px-6 py-3 bg-gray-50 dark:bg-gray-800" scope="col">
|
||||||
Description
|
Description
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3">
|
<th class="px-6 py-3" scope="col">
|
||||||
Amount
|
Amount
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3 bg-gray-50 dark:bg-gray-800">
|
<th class="px-6 py-3 bg-gray-50 dark:bg-gray-800" scope="col">
|
||||||
Cal Per 100
|
Cal Per 100
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3">
|
<th class="px-6 py-3" scope="col">
|
||||||
Energy
|
Energy
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@@ -31,11 +31,11 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<header
|
<header
|
||||||
data-tauri-drag-region
|
|
||||||
class="flex h-14 items-center justify-between bg-base-100 shadow-lg sticky top-0 z-50 border-b
|
class="flex h-14 items-center justify-between bg-base-100 shadow-lg sticky top-0 z-50 border-b
|
||||||
border-border/40 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60"
|
border-border/40 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60"
|
||||||
|
data-tauri-drag-region
|
||||||
>
|
>
|
||||||
<Button on:click={toggleMode} size="icon" variant="outline" class="ml-2">
|
<Button class="ml-2" on:click={toggleMode} size="icon" variant="outline">
|
||||||
<Sun
|
<Sun
|
||||||
class="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"
|
class="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"
|
||||||
/>
|
/>
|
||||||
@@ -49,11 +49,11 @@
|
|||||||
class="flex space-x-4 text-xl font-bold select-none"
|
class="flex space-x-4 text-xl font-bold select-none"
|
||||||
on:dragstart|preventDefault
|
on:dragstart|preventDefault
|
||||||
>
|
>
|
||||||
<div class:text-amber-500="{$dbStateStore.transacting}" on:click={DBService.Begin} class="cursor-pointer">T
|
<div class="cursor-pointer" class:text-amber-500="{$dbStateStore.transacting}" on:click={DBService.Begin}>T
|
||||||
</div>
|
</div>
|
||||||
<div class:text-emerald-600={$dbStateStore.transacting} on:click={DBService.Commit} class="cursor-pointer">C
|
<div class="cursor-pointer" class:text-emerald-600={$dbStateStore.transacting} on:click={DBService.Commit}>C
|
||||||
</div>
|
</div>
|
||||||
<div class:text-red-700={$dbStateStore.transacting} on:click={DBService.Rollback} class="cursor-pointer">R</div>
|
<div class="cursor-pointer" class:text-red-700={$dbStateStore.transacting} on:click={DBService.Rollback}>R</div>
|
||||||
{#each links as { href, label }}
|
{#each links as { href, label }}
|
||||||
<a
|
<a
|
||||||
use:link
|
use:link
|
||||||
@@ -68,18 +68,18 @@
|
|||||||
|
|
||||||
<div class="flex h-full [&>*]:px-2 [&>*]:transition-all">
|
<div class="flex h-full [&>*]:px-2 [&>*]:transition-all">
|
||||||
<a
|
<a
|
||||||
on:dragstart|preventDefault
|
|
||||||
target="_blank"
|
|
||||||
href="https://github.com/Fractal-Tess/Svelte-Tauri"
|
|
||||||
class="flex items-center hover:text-secondary"
|
class="flex items-center hover:text-secondary"
|
||||||
|
href="https://github.com/Fractal-Tess/Svelte-Tauri"
|
||||||
|
on:dragstart|preventDefault
|
||||||
rel="noreferrer noopener"
|
rel="noreferrer noopener"
|
||||||
|
target="_blank"
|
||||||
>
|
>
|
||||||
<Fa icon={faGithub} size="lg" />
|
<Fa icon={faGithub} size="lg" />
|
||||||
</a>
|
</a>
|
||||||
<button on:click={appWindow.minimize} class="text-xl hover:text-secondary">
|
<button class="text-xl hover:text-secondary" on:click={appWindow.minimize}>
|
||||||
<Fa icon={faWindowMinimize} />
|
<Fa icon={faWindowMinimize} />
|
||||||
</button>
|
</button>
|
||||||
<button on:click={appWindow.close} class="text-2xl hover:text-secondary">
|
<button class="text-2xl hover:text-secondary" on:click={appWindow.close}>
|
||||||
<Fa icon={faXmark} />
|
<Fa icon={faXmark} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -4,13 +4,15 @@
|
|||||||
import { cn } from '$lib/utils'
|
import { cn } from '$lib/utils'
|
||||||
|
|
||||||
let message = ''
|
let message = ''
|
||||||
|
|
||||||
async function callTauri() {
|
async function callTauri() {
|
||||||
message = await helloTauri()
|
message = await helloTauri()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Button variant="outline" class="px-8 py-6" on:click={callTauri}
|
<Button class="px-8 py-6" on:click={callTauri} variant="outline"
|
||||||
>Call Tauri</Button
|
>Call Tauri
|
||||||
|
</Button
|
||||||
>
|
>
|
||||||
|
|
||||||
<p
|
<p
|
||||||
|
@@ -13,12 +13,12 @@
|
|||||||
<div class="flex flex-col w-full max-w-sm gap-1.5">
|
<div class="flex flex-col w-full max-w-sm gap-1.5">
|
||||||
<Label for="hash">Hash string</Label>
|
<Label for="hash">Hash string</Label>
|
||||||
<Input
|
<Input
|
||||||
placeholder="String to hash"
|
|
||||||
id="hash"
|
|
||||||
bind:value={hashInput}
|
bind:value={hashInput}
|
||||||
type="text"
|
|
||||||
class="input-bordered input-secondary input focus:border-secondary
|
class="input-bordered input-secondary input focus:border-secondary
|
||||||
focus:outline-none focus:ring-secondary"
|
focus:outline-none focus:ring-secondary"
|
||||||
|
id="hash"
|
||||||
|
placeholder="String to hash"
|
||||||
|
type="text"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<code class="border border-border rounded-md px-2 py-1 text-sm"
|
<code class="border border-border rounded-md px-2 py-1 text-sm"
|
||||||
|
@@ -41,12 +41,12 @@
|
|||||||
<div class="flex gap-4">
|
<div class="flex gap-4">
|
||||||
<div class="flex-1 flex-col gap-y-2 flex">
|
<div class="flex-1 flex-col gap-y-2 flex">
|
||||||
<Label for="key">Key</Label>
|
<Label for="key">Key</Label>
|
||||||
<Input id="key" bind:value={key} />
|
<Input bind:value={key} id="key" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex-1 flex-col gap-y-2 flex">
|
<div class="flex-1 flex-col gap-y-2 flex">
|
||||||
<Label for="val">Value</Label>
|
<Label for="val">Value</Label>
|
||||||
<Input id="val" bind:value={val} />
|
<Input bind:value={val} id="val" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex w-full gap-4">
|
<div class="flex w-full gap-4">
|
||||||
|
@@ -11,6 +11,13 @@ export type Food = {
|
|||||||
energy?: number,
|
energy?: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type AggregatedFood = {
|
||||||
|
date: Date,
|
||||||
|
amount: number,
|
||||||
|
avgPer100: number,
|
||||||
|
energy: number,
|
||||||
|
}
|
||||||
|
|
||||||
const columns = ['rowid', 'date', 'food', 'description', 'amount', 'per100', 'energy']
|
const columns = ['rowid', 'date', 'food', 'description', 'amount', 'per100', 'energy']
|
||||||
const aggColumns = ['date', 'amount', 'avgPer100', 'energy']
|
const aggColumns = ['date', 'amount', 'avgPer100', 'energy']
|
||||||
|
|
||||||
@@ -40,22 +47,22 @@ order by date DESC;
|
|||||||
|
|
||||||
return [row, null]
|
return [row, null]
|
||||||
},
|
},
|
||||||
async GetDaily(): Promise<[Food[], Err]> {
|
async GetDaily(): Promise<[AggregatedFood[], Err]> {
|
||||||
const rows = await db.select<Food[]>(`select ${aggColumns.join(', ')} from daily limit 100`)
|
const rows = await db.select<AggregatedFood[]>(`select ${aggColumns.join(', ')} from daily limit 100`)
|
||||||
return [rows, null]
|
return [rows, null]
|
||||||
},
|
},
|
||||||
async GetWeekly(): Promise<[Food[], Err]> {
|
async GetWeekly(): Promise<[AggregatedFood[], Err]> {
|
||||||
const rows = await db.select<Food[]>(`select ${aggColumns.join(', ')} from weekly limit 100`)
|
const rows = await db.select<AggregatedFood[]>(`select ${aggColumns.join(', ')} from weekly limit 100`)
|
||||||
return [rows, null]
|
return [rows, null]
|
||||||
},
|
},
|
||||||
async GetMonthly(): Promise<[Food[], Err]> {
|
async GetMonthly(): Promise<[AggregatedFood[], Err]> {
|
||||||
const rows = await db.select<Food[]>(`select ${aggColumns.join(', ')} from monthly limit 100`)
|
const rows = await db.select<AggregatedFood[]>(`select ${aggColumns.join(', ')} from monthly limit 100`)
|
||||||
return [rows, null]
|
return [rows, null]
|
||||||
},
|
},
|
||||||
async GetYearly(): Promise<[Food[], Err]> {
|
async GetYearly(): Promise<[AggregatedFood[], Err]> {
|
||||||
const rows = await db.select<Food[]>(`select ${aggColumns.join(', ')} from yearly limit 100`)
|
const rows = await db.select<AggregatedFood[]>(`select ${aggColumns.join(', ')} from yearly limit 100`)
|
||||||
return [rows, null]
|
return [rows, null]
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { FoodService }
|
export { FoodService }
|
||||||
|
@@ -8,22 +8,20 @@ declare global {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Function avoids 'window not defined' in SSR
|
// Function avoids 'window not defined' in SSR
|
||||||
const invoke = () => window.__TAURI_INVOKE__;
|
const invoke = () => window.__TAURI_INVOKE__
|
||||||
|
|
||||||
export function helloTauri() {
|
export function helloTauri() {
|
||||||
return invoke()<string>("hello_tauri")
|
return invoke()<string>('hello_tauri')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hash256sum(hashInput: string) {
|
export function hash256sum(hashInput: string) {
|
||||||
return invoke()<string>("hash256sum", { hashInput })
|
return invoke()<string>('hash256sum', { hashInput })
|
||||||
}
|
}
|
||||||
|
|
||||||
export function storeSetKey(key: string, value: string) {
|
export function storeSetKey(key: string, value: string) {
|
||||||
return invoke()<null>("store_set_key", { key,value })
|
return invoke()<null>('store_set_key', { key, value })
|
||||||
}
|
}
|
||||||
|
|
||||||
export function storeReadKey(key: string) {
|
export function storeReadKey(key: string) {
|
||||||
return invoke()<string | null>("store_read_key", { key })
|
return invoke()<string | null>('store_read_key', { key })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { type Food, FoodService } from '$lib/database/food'
|
import { type AggregatedFood, FoodService } from '$lib/database/food'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
import FoodTable from '$components/Food/FoodTable.svelte'
|
import AggregatedFoodTable from '$components/AggregatedFood/AggregatedFoodTable.svelte'
|
||||||
|
|
||||||
let foods: Food[] = []
|
let foods: AggregatedFood[] = []
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const [dbfoods, err] = await FoodService.GetDaily()
|
const [dbfoods, err] = await FoodService.GetDaily()
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -15,5 +15,5 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<FoodTable items="{foods}"/>
|
<AggregatedFoodTable items="{foods}" />
|
||||||
</template>
|
</template>
|
||||||
|
@@ -4,5 +4,5 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<FoodTable items="{$foodStore}" create="true" />
|
<FoodTable create="true" items="{$foodStore}" />
|
||||||
</template>
|
</template>
|
||||||
|
Reference in New Issue
Block a user