undo & delete games
All checks were successful
build / windows (push) Successful in 2m33s
build / linux (push) Successful in 2m3s

This commit is contained in:
2025-03-10 11:54:15 +01:00
parent b107b926a2
commit 56016d75ab
5 changed files with 56 additions and 7 deletions

10
app.go
View File

@ -47,6 +47,10 @@ func (a *App) GetGames() (games []model.Game) {
a.db.Find(&games)
return
}
func (a *App) DeleteGame(g *model.Game) {
a.db.Delete(g)
}
func (a *App) NewGame() (id uint) {
game := model.Game{
Steps: []model.Step{},
@ -58,3 +62,9 @@ func (a *App) NewGame() (id uint) {
func (a *App) SaveStep(s *model.Step) {
a.db.Save(s)
}
func (a *App) UndoFor(game *model.Game) {
var step model.Step
a.db.Where("game_id = ?", game.ID).Order("created_at DESC").First(&step)
a.db.Delete(&step)
}

View File

@ -1,7 +1,12 @@
<script lang="ts">
import "./app.css";
import { Router, Route, Link, navigate } from "svelte-routing";
import { GetGame, GetGames, NewGame } from "../wailsjs/go/main/App";
import {
DeleteGame,
GetGame,
GetGames,
NewGame,
} from "../wailsjs/go/main/App";
import "./app.css";
import {
Navbar,
@ -12,7 +17,12 @@
Heading,
DropdownDivider,
} from "flowbite-svelte";
import { ChevronDownOutline, HomeOutline } from "flowbite-svelte-icons";
import {
ChevronDownOutline,
DeleteTableOutline,
HomeOutline,
TrashBinOutline,
} from "flowbite-svelte-icons";
import Game from "./routes/Game.svelte";
import { model } from "../wailsjs/go/models";
import { onMount } from "svelte";
@ -29,6 +39,11 @@
console.log(url);
});
onMount(update);
function beautyfyTime(t: any): string {
const date = new Date(t);
return date.toLocaleString();
}
</script>
<div
@ -47,7 +62,7 @@
{#if game === null}
Select a game
{:else}
{game.CreatedAt}
{beautyfyTime(game.CreatedAt)}
{/if}
<ChevronDownOutline
class="w-6 h-6 ms-2 text-white dark:text-white"
@ -55,9 +70,17 @@
>
<Dropdown>
{#each games as g}
<DropdownItem onclick={() => GetGame(g.ID).then((g) => (game = g))}
>{g.CreatedAt}</DropdownItem
>
<DropdownItem onclick={() => {}} class="flex justify-center">
<Button
onclick={() => GetGame(g.ID).then((g) => (game = g))}
color="none"
>
{beautyfyTime(g.CreatedAt)}
</Button>
<Button color="none" onclick={() => DeleteGame(g).then(update)}
><TrashBinOutline /></Button
>
</DropdownItem>
{/each}
<DropdownDivider />
<DropdownItem

View File

@ -1,10 +1,11 @@
<script lang="ts">
import { Button, Heading, P, Range } from "flowbite-svelte";
import { onMount } from "svelte";
import { GetGame, SaveStep } from "../../wailsjs/go/main/App";
import { GetGame, SaveStep, UndoFor } from "../../wailsjs/go/main/App";
import { model } from "../../wailsjs/go/models";
import { derived } from "svelte/store";
import TichuSelect from "@/components/TichuSelect.svelte";
import { UndoOutline } from "flowbite-svelte-icons";
let { gameId }: { gameId: number } = $props();
@ -73,5 +74,8 @@
});
}}>Save</Button
>
<Button color="red" onclick={() => UndoFor(game).then(update)}
><UndoOutline /></Button
>
</div>
</div>

View File

@ -2,6 +2,8 @@
// This file is automatically generated. DO NOT EDIT
import {model} from '../models';
export function DeleteGame(arg1:model.Game):Promise<void>;
export function GetGame(arg1:number):Promise<model.Game>;
export function GetGames():Promise<Array<model.Game>>;
@ -13,3 +15,5 @@ export function Greet(arg1:string):Promise<string>;
export function NewGame():Promise<number>;
export function SaveStep(arg1:model.Step):Promise<void>;
export function UndoFor(arg1:model.Game):Promise<void>;

View File

@ -2,6 +2,10 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
export function DeleteGame(arg1) {
return window['go']['main']['App']['DeleteGame'](arg1);
}
export function GetGame(arg1) {
return window['go']['main']['App']['GetGame'](arg1);
}
@ -25,3 +29,7 @@ export function NewGame() {
export function SaveStep(arg1) {
return window['go']['main']['App']['SaveStep'](arg1);
}
export function UndoFor(arg1) {
return window['go']['main']['App']['UndoFor'](arg1);
}