IT'S WORKING
This commit is contained in:
parent
a3947220b2
commit
b5208e5ca7
@ -4,6 +4,6 @@
|
|||||||
|
|
||||||
<main>
|
<main>
|
||||||
</main>
|
</main>
|
||||||
<Game />
|
<Game gameID="1" />
|
||||||
<style>
|
<style>
|
||||||
</style>
|
</style>
|
||||||
|
@ -1,41 +1,54 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { request } from "graphql-request";
|
import { request } from "graphql-request";
|
||||||
import { graphql } from "./../gql";
|
import { graphql } from "./../gql";
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import type { GetGameQuery } from "../gql/graphql";
|
||||||
|
|
||||||
|
let { gameID } : {
|
||||||
|
gameID: string
|
||||||
|
} = $props()
|
||||||
|
|
||||||
const doc = graphql(`
|
const doc = graphql(`
|
||||||
query hello {
|
query getGame($gameID: ID!) {
|
||||||
game(id: "1") {
|
game(id: $gameID) {
|
||||||
|
added
|
||||||
|
overtime
|
||||||
score
|
score
|
||||||
|
team0player0 {
|
||||||
|
ID
|
||||||
|
}
|
||||||
|
team0player1 {
|
||||||
|
ID
|
||||||
|
}
|
||||||
|
team1player0 {
|
||||||
|
ID
|
||||||
|
}
|
||||||
|
team1player1 {
|
||||||
|
ID
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
request("http://localhost:5173/graphql", doc).then((e) => {
|
let loading = $state(true);
|
||||||
console.log(e.game?.score);
|
let data: GetGameQuery | undefined = $state(undefined);
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
request("http://localhost:5173/graphql", doc, { gameID }).then(
|
||||||
|
(e) => {
|
||||||
|
console.log(e.game);
|
||||||
|
|
||||||
|
data = e;
|
||||||
|
loading = false;
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
let game = {
|
|
||||||
id: "myid",
|
|
||||||
added: new Date(),
|
|
||||||
author: "authorid",
|
|
||||||
score: 3,
|
|
||||||
overtime: true,
|
|
||||||
team0player0: "T0P0",
|
|
||||||
team0player1: "T0P1",
|
|
||||||
team1player0: "T1P0",
|
|
||||||
team1player1: "T1P1",
|
|
||||||
};
|
|
||||||
|
|
||||||
let scoreTeam0 = game.score > 0 ? game.score : 0;
|
|
||||||
let scoreTeam1 = game.score < 0 ? game.score : 0;
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h1 class="text-2xl">Game</h1>
|
<h1 class="text-2xl">Game</h1>
|
||||||
|
|
||||||
Played at: {game.added} <br />
|
{#if loading}
|
||||||
Added by: {game.author} <br />
|
Loading...
|
||||||
Overtime: {game.overtime} <br />
|
{:else}
|
||||||
|
{data?.game?.score}
|
||||||
Team 1: {scoreTeam0} Team2: {scoreTeam1} <br />
|
{/if}
|
||||||
{game.team0player0} | {game.team1player0} <br />
|
|
||||||
{game.team0player1} | {game.team1player1} <br />
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user