diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-02-17 17:11:16 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-02-17 17:11:16 +0100 |
commit | 8f29332048ce8fb1f06148be82542832a517ec84 (patch) | |
tree | e477122c0f80a44b09b6ece0f652d913a0d944c0 /web/pw-server/src/routes/index.svelte | |
parent | 4dc77e16263a701169b48187251dde7e375c9206 (diff) | |
download | planetwars.dev-8f29332048ce8fb1f06148be82542832a517ec84.tar.xz planetwars.dev-8f29332048ce8fb1f06148be82542832a517ec84.zip |
adapt frontend to new match api
Diffstat (limited to 'web/pw-server/src/routes/index.svelte')
-rw-r--r-- | web/pw-server/src/routes/index.svelte | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/web/pw-server/src/routes/index.svelte b/web/pw-server/src/routes/index.svelte index 3bab27a..46eb635 100644 --- a/web/pw-server/src/routes/index.svelte +++ b/web/pw-server/src/routes/index.svelte @@ -51,13 +51,35 @@ async function selectMatch(matchId: string) { console.log("showing match " + matchId); - let matchLog = await loadMatch(matchId); + let matchLog = await getMatchLog(matchId); selectedMatchId = matchId; selectedMatchLog = matchLog; } - async function loadMatch(matchId: string) { - const res = await fetch(`/api/matches/${matchId}`, { + async function getMatchData(matchId: string) { + let response = await fetch(`/api/matches/${matchId}`, { + headers: { + "Content-Type": "application/json", + }, + }); + + if (!response.ok) { + throw Error(response.statusText); + } + + let matchData = await response.json(); + return matchData; + } + + async function getMatchLog(matchId: string) { + const matchData = await getMatchData(matchId); + console.log(matchData); + if (matchData["state"] !== "Finished") { + // log is not available yet + return null; + } + + const res = await fetch(`/api/matches/${matchId}/log`, { headers: { "Content-Type": "application/json", }, |