fix match detail view
This commit is contained in:
parent
d4c52c3e99
commit
f058000072
1 changed files with 28 additions and 7 deletions
|
@ -1,21 +1,31 @@
|
||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
export async function load({ page }) {
|
function fetchJson(url: string): Promise<Response> {
|
||||||
const res = await fetch(`/api/matches/${page.params["match_id"]}`, {
|
return fetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (res.ok) {
|
export async function load({ params }) {
|
||||||
|
// TODO: handle failure cases better
|
||||||
|
const matchId = params["match_id"];
|
||||||
|
const matchDataResponse = await fetchJson(`/api/matches/${matchId}`);
|
||||||
|
if (!matchDataResponse.ok) {
|
||||||
|
}
|
||||||
|
const matchLogResponse = await fetchJson(`/api/matches/${matchId}/log`);
|
||||||
|
|
||||||
|
if (matchDataResponse.ok && matchLogResponse.ok) {
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
matchLog: await res.text(),
|
matchData: await matchDataResponse.json(),
|
||||||
|
matchLog: await matchLogResponse.text(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: res.status,
|
status: matchDataResponse.status,
|
||||||
error: new Error("failed to load match"),
|
error: new Error("failed to load match"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -24,8 +34,19 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Visualizer from "$lib/components/Visualizer.svelte";
|
import Visualizer from "$lib/components/Visualizer.svelte";
|
||||||
export let matchLog: string;
|
export let matchLog: string;
|
||||||
|
export let matchData: object;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div class="container">
|
||||||
<Visualizer {matchLog} />
|
<Visualizer {matchLog} {matchData} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
// these are needed for making the visualizer fill the screen.
|
||||||
|
min-height: 0;
|
||||||
|
flex-grow: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
Loading…
Reference in a new issue