generated from schreifuchs/wails-template
undo & delete games
This commit is contained in:
10
app.go
10
app.go
@ -47,6 +47,10 @@ func (a *App) GetGames() (games []model.Game) {
|
|||||||
a.db.Find(&games)
|
a.db.Find(&games)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
func (a *App) DeleteGame(g *model.Game) {
|
||||||
|
a.db.Delete(g)
|
||||||
|
|
||||||
|
}
|
||||||
func (a *App) NewGame() (id uint) {
|
func (a *App) NewGame() (id uint) {
|
||||||
game := model.Game{
|
game := model.Game{
|
||||||
Steps: []model.Step{},
|
Steps: []model.Step{},
|
||||||
@ -58,3 +62,9 @@ func (a *App) NewGame() (id uint) {
|
|||||||
func (a *App) SaveStep(s *model.Step) {
|
func (a *App) SaveStep(s *model.Step) {
|
||||||
a.db.Save(s)
|
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)
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import "./app.css";
|
import "./app.css";
|
||||||
import { Router, Route, Link, navigate } from "svelte-routing";
|
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 "./app.css";
|
||||||
import {
|
import {
|
||||||
Navbar,
|
Navbar,
|
||||||
@ -12,7 +17,12 @@
|
|||||||
Heading,
|
Heading,
|
||||||
DropdownDivider,
|
DropdownDivider,
|
||||||
} from "flowbite-svelte";
|
} 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 Game from "./routes/Game.svelte";
|
||||||
import { model } from "../wailsjs/go/models";
|
import { model } from "../wailsjs/go/models";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
@ -29,6 +39,11 @@
|
|||||||
console.log(url);
|
console.log(url);
|
||||||
});
|
});
|
||||||
onMount(update);
|
onMount(update);
|
||||||
|
|
||||||
|
function beautyfyTime(t: any): string {
|
||||||
|
const date = new Date(t);
|
||||||
|
return date.toLocaleString();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@ -47,7 +62,7 @@
|
|||||||
{#if game === null}
|
{#if game === null}
|
||||||
Select a game
|
Select a game
|
||||||
{:else}
|
{:else}
|
||||||
{game.CreatedAt}
|
{beautyfyTime(game.CreatedAt)}
|
||||||
{/if}
|
{/if}
|
||||||
<ChevronDownOutline
|
<ChevronDownOutline
|
||||||
class="w-6 h-6 ms-2 text-white dark:text-white"
|
class="w-6 h-6 ms-2 text-white dark:text-white"
|
||||||
@ -55,9 +70,17 @@
|
|||||||
>
|
>
|
||||||
<Dropdown>
|
<Dropdown>
|
||||||
{#each games as g}
|
{#each games as g}
|
||||||
<DropdownItem onclick={() => GetGame(g.ID).then((g) => (game = g))}
|
<DropdownItem onclick={() => {}} class="flex justify-center">
|
||||||
>{g.CreatedAt}</DropdownItem
|
<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}
|
{/each}
|
||||||
<DropdownDivider />
|
<DropdownDivider />
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Button, Heading, P, Range } from "flowbite-svelte";
|
import { Button, Heading, P, Range } from "flowbite-svelte";
|
||||||
import { onMount } from "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 { model } from "../../wailsjs/go/models";
|
||||||
import { derived } from "svelte/store";
|
import { derived } from "svelte/store";
|
||||||
import TichuSelect from "@/components/TichuSelect.svelte";
|
import TichuSelect from "@/components/TichuSelect.svelte";
|
||||||
|
import { UndoOutline } from "flowbite-svelte-icons";
|
||||||
|
|
||||||
let { gameId }: { gameId: number } = $props();
|
let { gameId }: { gameId: number } = $props();
|
||||||
|
|
||||||
@ -73,5 +74,8 @@
|
|||||||
});
|
});
|
||||||
}}>Save</Button
|
}}>Save</Button
|
||||||
>
|
>
|
||||||
|
<Button color="red" onclick={() => UndoFor(game).then(update)}
|
||||||
|
><UndoOutline /></Button
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
4
frontend/wailsjs/go/main/App.d.ts
vendored
4
frontend/wailsjs/go/main/App.d.ts
vendored
@ -2,6 +2,8 @@
|
|||||||
// This file is automatically generated. DO NOT EDIT
|
// This file is automatically generated. DO NOT EDIT
|
||||||
import {model} from '../models';
|
import {model} from '../models';
|
||||||
|
|
||||||
|
export function DeleteGame(arg1:model.Game):Promise<void>;
|
||||||
|
|
||||||
export function GetGame(arg1:number):Promise<model.Game>;
|
export function GetGame(arg1:number):Promise<model.Game>;
|
||||||
|
|
||||||
export function GetGames():Promise<Array<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 NewGame():Promise<number>;
|
||||||
|
|
||||||
export function SaveStep(arg1:model.Step):Promise<void>;
|
export function SaveStep(arg1:model.Step):Promise<void>;
|
||||||
|
|
||||||
|
export function UndoFor(arg1:model.Game):Promise<void>;
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||||
// This file is automatically generated. DO NOT EDIT
|
// This file is automatically generated. DO NOT EDIT
|
||||||
|
|
||||||
|
export function DeleteGame(arg1) {
|
||||||
|
return window['go']['main']['App']['DeleteGame'](arg1);
|
||||||
|
}
|
||||||
|
|
||||||
export function GetGame(arg1) {
|
export function GetGame(arg1) {
|
||||||
return window['go']['main']['App']['GetGame'](arg1);
|
return window['go']['main']['App']['GetGame'](arg1);
|
||||||
}
|
}
|
||||||
@ -25,3 +29,7 @@ export function NewGame() {
|
|||||||
export function SaveStep(arg1) {
|
export function SaveStep(arg1) {
|
||||||
return window['go']['main']['App']['SaveStep'](arg1);
|
return window['go']['main']['App']['SaveStep'](arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function UndoFor(arg1) {
|
||||||
|
return window['go']['main']['App']['UndoFor'](arg1);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user