diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-08-22 21:18:20 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-08-22 21:18:20 +0200 |
commit | 82ab9cef78020361d556f4208c57ecd9259d51ea (patch) | |
tree | 068c89af9bb40bbfaf483ebb8fc9ebe5f7a65e05 /web/pw-server/src/routes | |
parent | 947ced152e43c148830e2c1fb25b9e10e766b5c8 (diff) | |
download | planetwars.dev-82ab9cef78020361d556f4208c57ecd9259d51ea.tar.xz planetwars.dev-82ab9cef78020361d556f4208c57ecd9259d51ea.zip |
populate new index page
Diffstat (limited to 'web/pw-server/src/routes')
-rw-r--r-- | web/pw-server/src/routes/index.svelte | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/web/pw-server/src/routes/index.svelte b/web/pw-server/src/routes/index.svelte index e69de29..fd1f505 100644 --- a/web/pw-server/src/routes/index.svelte +++ b/web/pw-server/src/routes/index.svelte @@ -0,0 +1,92 @@ +<script lang="ts" context="module"> + import { ApiClient } from "$lib/api_client"; + + const NUM_MATCHES = "25"; + + export async function load({ fetch }) { + try { + const apiClient = new ApiClient(fetch); + + let { matches, has_next } = await apiClient.get("/api/matches", { + count: NUM_MATCHES, + }); + + return { + props: { + matches, + hasNext: has_next, + }, + }; + } catch (error) { + return { + status: error.status, + error: new Error("failed to load matches"), + }; + } + } +</script> + +<script lang="ts"> + import LinkButton from "$lib/components/LinkButton.svelte"; + import MatchList from "$lib/components/matches/MatchList.svelte"; + + export let matches; + export let hasNext; + + $: viewMoreUrl = olderMatchesLink(matches); + + // TODO: deduplicate. + // Maybe move to ApiClient logic? + function olderMatchesLink(matches: object[]): string { + if (matches.length == 0 || !hasNext) { + return null; + } + const lastTimestamp = matches[matches.length - 1]["timestamp"]; + return `/matches?before=${lastTimestamp}`; + } +</script> + +<div class="container"> + <div class="introduction"> + <h2>Welcome to PlanetWars!</h2> + <p> + Planetwars is a game of galactic conquest for busy people. Your goal is to program a bot that + will conquer the galaxy for you, while you take care of more important stuff. + </p> + <p> + Feel free to watch some games below to see what it's all about. When you are ready to try + writing your own bot, head over to + <a href="/docs">How to play</a> for instructions. You can program your bot in the browser + using the <a href="/editor">Editor</a>. + </p> + </div> + <h2>Recent matches</h2> + <MatchList {matches} /> + <div class="see-more-container"> + <LinkButton href={viewMoreUrl}>View more</LinkButton> + </div> +</div> + +<style scoped lang="scss"> + .container { + max-width: 800px; + margin: 0 auto; + } + + .introduction { + padding-top: 16px; + a { + color: rgb(9, 105, 218); + text-decoration: none; + } + + a:hover { + text-decoration: underline; + } + } + + .see-more-container { + padding: 24px; + text-align: center; + } +</style> |