before svelte upgrade

This commit is contained in:
2025-02-07 13:33:43 +01:00
parent 57cf5e617a
commit 0501c11c49
17 changed files with 396 additions and 88 deletions

View File

@ -1,22 +1,26 @@
<script lang="ts">
import "./app.css";
import { Navbar, NavBrand, DarkMode } from "flowbite-svelte";
import { Router, Route } from "svelte-routing";
import { Router, Route, Link, navigate } from "svelte-routing";
import Home from "./routes/Home.svelte";
import "./app.css";
import Tournament from "./routes/Tournament.svelte";
export let url = "";
</script>
<main class="flex-col h-screen items-center bg-gray-50 dark:bg-gray-800">
<Navbar>
<NavBrand>
<span>Wails</span>
<NavBrand on:click={() => navigate("", { replace: true })}>
<span>Tournamenter</span>
</NavBrand>
<DarkMode />
</Navbar>
<Router {url}>
<Router bind:url>
<div>
<Route path="/"><Home /></Route>
<Route path="/tournament/:id" let:params
><Tournament id={params.id} /></Route
>
</div>
</Router>
</main>

View File

@ -1,14 +1,8 @@
<script lang="ts">
import { onMount } from "svelte";
import { GetTournaments } from "../../wailsjs/go/main/App";
import { model } from "../../wailsjs/go/models";
import {
GetThings,
DeleteThing,
NewThing,
} from "../../wailsjs/go/things/Service";
import { things } from "../../wailsjs/go/models";
import {
Label,
Input,
Button,
Table,
TableHead,
@ -16,60 +10,58 @@
TableBody,
TableBodyRow,
TableBodyCell,
Modal,
} from "flowbite-svelte";
import TourCreator from "./TourCreator.svelte";
import { Link } from "svelte-routing";
let name: string;
let thingsList: things.Thing[] = [];
let thingsList: model.Tournament[] = [];
let newThing: boolean = false;
function update() {
GetThings().then((ts) => {
GetTournaments().then((ts) => {
thingsList = ts;
});
}
function submit(e: Event) {
e.preventDefault();
NewThing(name).then(update);
name = "";
}
function deleteEvent(id: number) {
DeleteThing(id).then(update);
}
onMount(update);
</script>
<form class="max-w-96 m-5 grid-cols-1 gap-10" on:submit={submit}>
<div class="m-5">
<Label for="first_name" class="mb-2">First name</Label>
<Input type="text" placeholder="John" bind:value={name} required />
</div>
<div class="m-5">
<Button type="submit">Submit</Button>
</div>
</form>
<Table>
<TableHead>
<TableHeadCell>ID</TableHeadCell>
<TableHeadCell>Name</TableHeadCell>
<TableHeadCell>Delete</TableHeadCell>
<TableHeadCell>Title</TableHeadCell>
<TableHeadCell>Game</TableHeadCell>
<TableHeadCell>Winner</TableHeadCell>
</TableHead>
<TableBody>
{#each thingsList as t}
<TableBodyRow>
<TableBodyCell>
{t.ID}
{t.Title}
</TableBodyCell>
<TableBodyCell>
{t.Game.Name}
</TableBodyCell>
<TableBodyCell>
{t.WinnierParticipant.Name}
</TableBodyCell>
<TableBodyCell>
{t.Name}
</TableBodyCell>
<TableBodyCell>
<Button on:click={(_) => deleteEvent(t.ID)}>Delete</Button>
<Link to={`/tournament/${t.ID}`}>Edit</Link>
</TableBodyCell>
</TableBodyRow>
{/each}
</TableBody>
<div class="flex-row justify-evenly p-5">
<Button>View</Button>
<Button on:click={(_) => (newThing = true)}>New Tournament</Button>
</div>
<Modal bind:open={newThing}>
<TourCreator
onCreated={() => {
update();
newThing = false;
}}
/>
</Modal>
</Table>

View File

@ -0,0 +1,44 @@
<script lang="ts">
import { Button, Input, Label, Select } from "flowbite-svelte";
import { model } from "../../wailsjs/go/models";
import { GetGames, SaveTournament } from "../../wailsjs/go/main/App";
import { onMount } from "svelte";
let tournament = new model.Tournament();
let games: model.Game[] = [];
export let onCreated: (t: model.Tournament) => void = (_) => {};
function submit(e: Event) {
e.preventDefault();
SaveTournament(tournament).then(() => {
onCreated(tournament);
});
}
onMount(() => {
GetGames().then((gs) => {
games = gs;
});
});
</script>
<form on:submit={submit}>
<div>
<Label>Title</Label>
<Input type="text" bind:value={tournament.Title} />
</div>
<div>
e
<Label>Game</Label>
<Select
items={games.map((g) => {
return { value: g.ID, name: g.Name };
})}
bind:value={tournament.GameID}
/>
</div>
<div>
<Label>Size</Label>
<Input type="number" step="1" min="1" bind:value={tournament.Size} />
</div>
<Button type="submit">Save</Button>
</form>

View File

@ -0,0 +1,28 @@
<script lang="ts">
import { Link } from "svelte-routing";
import { GetTournament } from "../../wailsjs/go/main/App";
import { model } from "../../wailsjs/go/models";
import { onMount } from "svelte";
export let id: number | null = null;
let tournament: model.Tournament;
function update() {
GetTournament(id).then((t) => {
console.log(t);
tournament = t;
});
}
$: {
id = id;
update();
}
onMount(update);
</script>
<div>
<Link to="/" replace="true">Home</Link>
</div>
{#if tournament}
{tournament.Title}
{/if}

View File

@ -1,4 +1,11 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
import {model} from '../models';
export function Greet(arg1:string):Promise<string>;
export function GetGames():Promise<Array<model.Game>>;
export function GetTournament(arg1:number):Promise<model.Tournament>;
export function GetTournaments():Promise<Array<model.Tournament>>;
export function SaveTournament(arg1:model.Tournament):Promise<void>;

View File

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

View File

@ -1,18 +1,147 @@
export namespace things {
export namespace model {
export class Thing {
export class Game {
ID: number;
// Go type: time
CreatedAt: any;
// Go type: time
UpdatedAt: any;
// Go type: gorm
DeletedAt: any;
Name: string;
static createFrom(source: any = {}) {
return new Thing(source);
return new Game(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.ID = source["ID"];
this.CreatedAt = this.convertValues(source["CreatedAt"], null);
this.UpdatedAt = this.convertValues(source["UpdatedAt"], null);
this.DeletedAt = this.convertValues(source["DeletedAt"], null);
this.Name = source["Name"];
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice && a.map) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
}
export class Tournament {
ID: number;
// Go type: time
CreatedAt: any;
// Go type: time
UpdatedAt: any;
// Go type: gorm
DeletedAt: any;
Title: string;
GameID: number;
Game: Game;
Size?: number;
TournamentState: number;
WinnierParticipantID: number;
WinnierParticipant: Participant;
Participants: Participant[];
static createFrom(source: any = {}) {
return new Tournament(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.ID = source["ID"];
this.CreatedAt = this.convertValues(source["CreatedAt"], null);
this.UpdatedAt = this.convertValues(source["UpdatedAt"], null);
this.DeletedAt = this.convertValues(source["DeletedAt"], null);
this.Title = source["Title"];
this.GameID = source["GameID"];
this.Game = this.convertValues(source["Game"], Game);
this.Size = source["Size"];
this.TournamentState = source["TournamentState"];
this.WinnierParticipantID = source["WinnierParticipantID"];
this.WinnierParticipant = this.convertValues(source["WinnierParticipant"], Participant);
this.Participants = this.convertValues(source["Participants"], Participant);
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice && a.map) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
}
export class Participant {
ID: number;
// Go type: time
CreatedAt: any;
// Go type: time
UpdatedAt: any;
// Go type: gorm
DeletedAt: any;
Name: string;
IsTemporary: boolean;
IsTeam: boolean;
Tournaments: Tournament[];
static createFrom(source: any = {}) {
return new Participant(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.ID = source["ID"];
this.CreatedAt = this.convertValues(source["CreatedAt"], null);
this.UpdatedAt = this.convertValues(source["UpdatedAt"], null);
this.DeletedAt = this.convertValues(source["DeletedAt"], null);
this.Name = source["Name"];
this.IsTemporary = source["IsTemporary"];
this.IsTeam = source["IsTeam"];
this.Tournaments = this.convertValues(source["Tournaments"], Tournament);
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice && a.map) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
}
}

View File

@ -1,9 +0,0 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
import {things} from '../models';
export function DeleteThing(arg1:number):Promise<void>;
export function GetThings():Promise<Array<things.Thing>>;
export function NewThing(arg1:string):Promise<void>;

View File

@ -1,15 +0,0 @@
// @ts-check
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
export function DeleteThing(arg1) {
return window['go']['things']['Service']['DeleteThing'](arg1);
}
export function GetThings() {
return window['go']['things']['Service']['GetThings']();
}
export function NewThing(arg1) {
return window['go']['things']['Service']['NewThing'](arg1);
}