Add other old components

This commit is contained in:
2024-08-09 19:52:16 +02:00
parent 27f8d2bd29
commit 715bc984be
4 changed files with 60 additions and 71 deletions

View File

@@ -1,9 +1,8 @@
<script lang="ts">
import { foodStore } from "$lib/store/FoodStore";
import FoodTable from "./Food/FoodTable.svelte";
</script>
<template>
{#each $foodStore as f}
<div>{f.food}</div>
{/each}
<FoodTable items={$foodStore} />
</template>

View File

@@ -1,4 +1,4 @@
<script lang="ts">
<!-- <script lang="ts">
import { type Food, FoodService } from '$lib/database/food'
import { toast } from 'svelte-sonner'
import type { Err } from '$lib/types'
@@ -92,4 +92,4 @@
on:keydown={update}>
</td>
</tr>
</template>
</template> -->

View File

@@ -1,7 +1,9 @@
<script lang="ts">
import { type Food, FoodService } from '$lib/database/food'
import { UpdateFood } from '$wails/main/App';
import {main} from '$wails/models'
import { toast } from 'svelte-sonner'
export let item: Food
export let item: main.Food
export let energyColor: string
export let nameColor: string
export let dateColor: string
@@ -33,10 +35,11 @@
item.amount = parseInt(amount)
item.per100 = parseInt(per100)
const [newItem, err] = await FoodService.Update(item)
if (newItem && !err) {
item = newItem
const res = await UpdateFood(item)
if (!res.success) {
toast.error(`failed to update food item with error ${res.error}`)
} else {
item = res.data
}
name = item.food
description = item.description ?? ''

View File

@@ -1,57 +1,57 @@
<script lang="ts">
import EmptyFoodComp from '$components/Energy/Food/EmptyFoodComp.svelte'
import FoodComp from '$components/Energy/Food/FoodComp.svelte'
import type { Food } from '$lib/database/food'
import { GenerateColor } from '$lib/utils'
import EmptyFoodComp from "$components/Energy/Food/EmptyFoodComp.svelte";
import FoodComp from "$components/Energy/Food/FoodComp.svelte";
import { GenerateColor } from "$lib/utils";
import { main } from "$wails/models";
export let items: Food[] = []
export let items: main.Food[] = [];
let minCal = 1e5
let maxCal = 0
let minCal = 1e5;
let maxCal = 0;
for (let item of items) {
if (!item.energy) continue
if (item.energy > maxCal) maxCal = item.energy
if (item.energy < minCal) minCal = item.energy
if (!item.energy) continue;
if (item.energy > maxCal) maxCal = item.energy;
if (item.energy < minCal) minCal = item.energy;
}
const start = '#99ff99'
const end = '#ff9999'
const start = "#99ff99";
const end = "#ff9999";
function lerp(item: Food) {
if (!item) return start
if (!item.energy) return start
const t = (item.energy - minCal) / (maxCal - minCal)
const r = parseInt(start.slice(1, 3), 16) * (1 - t) + parseInt(end.slice(1, 3), 16) * t
const g = parseInt(start.slice(3, 5), 16) * (1 - t) + parseInt(end.slice(3, 5), 16) * t
const b = parseInt(start.slice(5, 7), 16) * (1 - t) + parseInt(end.slice(5, 7), 16) * t
return `rgb(${r}, ${g}, ${b})`
function lerp(item: main.Food) {
if (!item) return start;
if (!item.energy) return start;
const t = (item.energy - minCal) / (maxCal - minCal);
const r = parseInt(start.slice(1, 3), 16) * (1 - t) + parseInt(end.slice(1, 3), 16) * t;
const g = parseInt(start.slice(3, 5), 16) * (1 - t) + parseInt(end.slice(3, 5), 16) * t;
const b = parseInt(start.slice(5, 7), 16) * (1 - t) + parseInt(end.slice(5, 7), 16) * t;
return `rgb(${r}, ${g}, ${b})`;
}
const itemColors: Map<string, string> = new Map<string, string>()
const itemColors: Map<string, string> = new Map<string, string>();
function getNameColor(item: Food): string {
if (!item) return GenerateColor()
if (!item.food) return GenerateColor()
if (!itemColors.has(item.food)) itemColors.set(item.food, GenerateColor())
function getNameColor(item: main.Food): string {
if (!item) return GenerateColor();
if (!item.food) return GenerateColor();
if (!itemColors.has(item.food)) itemColors.set(item.food, GenerateColor());
// THERE'S NOTHING UNDEFINED HERE
// WE GOT RID OF UNDEFINED ON LINE 33
// ASSHOLE
// @ts-ignore
return itemColors.get(item.food)
return itemColors.get(item.food);
}
const dateColors: Map<string, string> = new Map<string, string>()
function getDateColor(item: Food): string {
if (!item) return GenerateColor()
if (!item.date) return GenerateColor()
const date = item.date.toString().split(" ")[0]
if (!date) return GenerateColor()
if (!dateColors.has(date)) dateColors.set(date, GenerateColor())
const dateColors: Map<string, string> = new Map<string, string>();
function getDateColor(item: main.Food): string {
if (!item) return GenerateColor();
if (!item.date) return GenerateColor();
const date = item.date.toString().split(" ")[0];
if (!date) return GenerateColor();
if (!dateColors.has(date)) dateColors.set(date, GenerateColor());
// THERE'S NOTHING UNDEFINED HERE
// WE GOT RID OF UNDEFINED ON LINE 33
// ASSHOLE
// @ts-ignore
return dateColors.get(date)
return dateColors.get(date);
}
</script>
@@ -61,24 +61,12 @@
<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">
<tr>
<th class="px-6 py-3 bg-gray-50 dark:bg-gray-800 w-2/12" scope="col">
Date
</th>
<th class="px-6 py-3 w-3/12" scope="col">
Food
</th>
<th class="px-6 py-3 bg-gray-50 dark:bg-gray-800 w-4/12" scope="col">
Description
</th>
<th class="px-6 py-3 w-1/12" scope="col">
Amount
</th>
<th class="px-6 py-3 bg-gray-50 dark:bg-gray-800 w-1/12" scope="col">
Cal Per 100
</th>
<th class="px-6 py-3 w-1/12" scope="col">
Energy
</th>
<th class="px-6 py-3 bg-gray-50 dark:bg-gray-800 w-2/12" scope="col"> Date </th>
<th class="px-6 py-3 w-3/12" scope="col"> Food </th>
<th class="px-6 py-3 bg-gray-50 dark:bg-gray-800 w-4/12" scope="col"> Description </th>
<th class="px-6 py-3 w-1/12" scope="col"> Amount </th>
<th class="px-6 py-3 bg-gray-50 dark:bg-gray-800 w-1/12" scope="col"> Cal Per 100 </th>
<th class="px-6 py-3 w-1/12" scope="col"> Energy </th>
</tr>
</thead>
<tbody>
@@ -89,7 +77,6 @@
</tbody>
</table>
</div>
<div>
</div>
<div></div>
</div>
</template>