4 Commits
1.2.0 ... 1.4.0

10 changed files with 58 additions and 13 deletions

6
app.go
View File

@@ -2,6 +2,7 @@ package main
import (
"context"
"os"
)
// App struct
@@ -135,3 +136,8 @@ func (a *App) SetSetting(key string, value int64) WailsGenericAck {
}
return WailsGenericAck{Success: true}
}
//region other
func (a *App) Close() {
os.Exit(0)
}

View File

@@ -1,12 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<meta charset="UTF-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>calorie-counter</title>
</head>
<body>
<div id="app"></div>
<script src="./src/main.ts" type="module"></script>
<div id="app"></div>
<script src="./src/main.ts" type="module"></script>
</body>
</html>

View File

@@ -1,9 +1,30 @@
<script lang="ts">
import Header from "$lib/components/Header.svelte";
import Router from "$lib/router/Router.svelte";
import { Toaster } from 'svelte-sonner'
import { Close } from "$wails/main/App";
import { Toaster } from "svelte-sonner";
import * as srouter from "svelte-spa-router";
import { location } from "svelte-spa-router";
function keyDown(event: KeyboardEvent) {
if (event.ctrlKey && event.key == "r") {
window.location.reload();
}
if (event.ctrlKey && event.key == "w") {
Close();
}
if (event.ctrlKey && event.key == "Tab") {
if ($location == "/") {
srouter.replace("/Weight");
} else if ($location == "/Weight") {
srouter.replace("/");
}
}
}
</script>
<svelte:window on:keydown={keyDown} />
<Toaster />
<template>
<Header />

View File

@@ -19,6 +19,7 @@
let per100: string = "";
let per100Edited: boolean = false;
let per100Element: HTMLTableCellElement;
let nameElement: HTMLTableCellElement;
async function update(event: KeyboardEvent & { currentTarget: EventTarget & HTMLTableCellElement }) {
name = name.trim();
@@ -26,7 +27,7 @@
description = description.trim();
per100 = per100.trim();
if (!per100Edited && event.currentTarget === per100Element) per100Edited = true;
if (!per100Edited && event.currentTarget == per100Element) per100Edited = true;
if (event.key == "Enter") {
event.preventDefault();
@@ -48,6 +49,7 @@
}
foodStore.update((value) => [res.data, ...value]);
nameElement.focus();
}
if (!per100Edited)
@@ -75,6 +77,7 @@
contenteditable="true"
autofocus
on:keydown={update}
bind:this={nameElement}
>
</td>
<td

View File

@@ -1,10 +1,11 @@
<script lang="ts">
import { GenerateColor } from "$lib/utils";
import { GenerateColor, RemoveExistingColors } from "$lib/utils";
import { main } from "$wails/models";
import EmptyFoodComp from "./EmptyFoodComp.svelte";
import FoodComp from "./FoodComp.svelte";
export let items: main.Food[] = [];
RemoveExistingColors();
let minCal = 1e5;
let maxCal = 0;

View File

@@ -1,10 +1,11 @@
<script lang="ts">
import { GenerateColor } from "$lib/utils";
import { GenerateColor, RemoveExistingColors } from "$lib/utils";
import EmptyWeightComp from "$components/Weight/EmptyWeightComp.svelte";
import WeightComp from "$components/Weight/WeightComp.svelte";
import { main } from "$wails/models";
export let items: main.Weight[] = [];
RemoveExistingColors();
const dateColors: Map<string, string> = new Map<string, string>();

View File

@@ -4,7 +4,6 @@
let forceUpdate = false;
weightStore.subscribe(() => {
console.log("updte");
forceUpdate = !forceUpdate;
});
</script>

View File

@@ -68,8 +68,11 @@ function GenerateRandomHSL(): Color {
const existingColors: Color[] = [];
function RemoveExistingColors() {
existingColors.length = 0;
}
function GenerateColor(): string {
const minDistance = 15;
const minDistance = 5;
let newColor: Color;
let isDistinct = false;
@@ -89,7 +92,9 @@ function GenerateColor(): string {
break;
}
}
existingColors.push(newColor);
if (isDistinct) {
existingColors.push(newColor);
}
}
// We can not reach this point without having a color generated
@@ -104,5 +109,5 @@ function LerpColor(color1: Color, color2: Color, t: number): Color {
return { h, s, l };
}
export { GenerateColor, LerpColor };
export { GenerateColor, LerpColor, RemoveExistingColors };
export type { Color };

View File

@@ -2,6 +2,8 @@
// This file is automatically generated. DO NOT EDIT
import {main} from '../models';
export function Close():Promise<void>;
export function CreateFood(arg1:main.Food):Promise<main.WailsFood1>;
export function CreateWeight(arg1:main.Weight):Promise<main.WailsWeight1>;

View File

@@ -2,6 +2,10 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
export function Close() {
return window['go']['main']['App']['Close']();
}
export function CreateFood(arg1) {
return window['go']['main']['App']['CreateFood'](arg1);
}