aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server/src
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-02-22 19:44:29 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2022-02-22 19:44:29 +0100
commite15944622d3741137f443e7fa0b5d193b4ce28d9 (patch)
tree279e10d0bbebc9ece9914b57a7104fc1fd9420a5 /web/pw-server/src
parent006ce356220c1a089fc468bbfdc0dea819cd9288 (diff)
downloadplanetwars.dev-e15944622d3741137f443e7fa0b5d193b4ce28d9.tar.xz
planetwars.dev-e15944622d3741137f443e7fa0b5d193b4ce28d9.zip
poll for matches to complete
Diffstat (limited to 'web/pw-server/src')
-rw-r--r--web/pw-server/src/routes/index.svelte23
1 files changed, 19 insertions, 4 deletions
diff --git a/web/pw-server/src/routes/index.svelte b/web/pw-server/src/routes/index.svelte
index 59552bc..7b364be 100644
--- a/web/pw-server/src/routes/index.svelte
+++ b/web/pw-server/src/routes/index.svelte
@@ -55,15 +55,30 @@
let matchData = responseData["match"];
- matches.push(matchData);
+ matches.unshift(matchData);
matches = matches;
+ selectMatch(matchData["id"]);
}
async function selectMatch(matchId: string) {
- console.log("showing match " + matchId);
- let matchLog = await getMatchLog(matchId);
selectedMatchId = matchId;
- selectedMatchLog = matchLog;
+ selectedMatchLog = null;
+ fetchSelectedMatchLog(matchId);
+ }
+
+ async function fetchSelectedMatchLog(matchId: string) {
+ if (matchId !== selectedMatchId) {
+ return;
+ }
+
+ let matchLog = await getMatchLog(matchId);
+
+ if (matchLog) {
+ selectedMatchLog = matchLog;
+ } else {
+ // try again in 1 second
+ setTimeout(fetchSelectedMatchLog, 1000, matchId);
+ }
}
async function getMatchData(matchId: string) {