This commit is contained in:
Niklas Kapelle 2025-01-09 22:25:09 +01:00
parent b5208e5ca7
commit 49357c2521
Signed by: niklas
GPG Key ID: 4EB651B36D841D16
3 changed files with 52 additions and 18 deletions

View File

@ -1,9 +1,11 @@
<script lang="ts"> <script lang="ts">
import Game from "./pages/Game.svelte" import Game from "./pages/Game.svelte"
import Player from "./pages/Player.svelte";
</script> </script>
<main> <main>
</main> </main>
<Game gameID="1" /> <Game gameID="1" />
<Player playerID="niklas" />
<style> <style>
</style> </style>

View File

@ -4,9 +4,11 @@
import { onMount } from "svelte"; import { onMount } from "svelte";
import type { GetGameQuery } from "../gql/graphql"; import type { GetGameQuery } from "../gql/graphql";
let { gameID } : { let {
gameID: string gameID,
} = $props() }: {
gameID: string;
} = $props();
const doc = graphql(` const doc = graphql(`
query getGame($gameID: ID!) { query getGame($gameID: ID!) {
@ -31,17 +33,13 @@
`); `);
let loading = $state(true); let loading = $state(true);
let data: GetGameQuery | undefined = $state(undefined); let data: GetGameQuery | undefined = $state();
onMount(() => { onMount(() => {
request("http://localhost:5173/graphql", doc, { gameID }).then( request("http://localhost:5173/graphql", doc, { gameID }).then((e) => {
(e) => {
console.log(e.game);
data = e; data = e;
loading = false; loading = false;
}, });
);
}); });
</script> </script>
@ -49,6 +47,8 @@
{#if loading} {#if loading}
Loading... Loading...
{:else if data == null || data.game == null}
Game not found.
{:else} {:else}
{data?.game?.score} {data.game.score}
{/if} {/if}

View File

@ -1,10 +1,42 @@
<script lang="ts"> <script lang="ts">
let player = { import { request } from "graphql-request";
id: "playerid", import { graphql } from "./../gql";
currentElo: 1001, import { onMount } from "svelte";
games: 3, import type { GetPlayerQuery } from "../gql/graphql";
let {
playerID,
}: {
playerID: string;
} = $props();
const doc = graphql(`
query getPlayer($playerID: ID!) {
player(id: $playerID) {
ID
} }
}
`);
let loading = $state(true);
let data: GetPlayerQuery | undefined = $state();
onMount(() => {
request("http://localhost:5173/graphql", doc, { playerID }).then(
(e) => {
data = e;
loading = false;
},
);
});
</script> </script>
<h1 class="text-2xl">Player</h1> <h1 class="text-2xl">Player</h1>
{#if loading}
Loading...
{:else if data == null || data.player == null}
Player not found.
{:else}
{data.player.ID}
{/if}