aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-08-12 20:54:34 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-08-12 20:54:34 +0200
commit7ba9fcee64387dd28064ae051aee344d73e889db (patch)
tree4db04f78d1b583f26bfdadb5d57d0a5022558bf4 /web/pw-server
parent84748fd60e1771a0bda427eb4e7b4fea6c79d0dc (diff)
downloadplanetwars.dev-7ba9fcee64387dd28064ae051aee344d73e889db.tar.xz
planetwars.dev-7ba9fcee64387dd28064ae051aee344d73e889db.zip
allow filtering for bot matches
Diffstat (limited to 'web/pw-server')
-rw-r--r--web/pw-server/src/routes/matches/index.svelte24
1 files changed, 22 insertions, 2 deletions
diff --git a/web/pw-server/src/routes/matches/index.svelte b/web/pw-server/src/routes/matches/index.svelte
index 95e653f..393d513 100644
--- a/web/pw-server/src/routes/matches/index.svelte
+++ b/web/pw-server/src/routes/matches/index.svelte
@@ -6,11 +6,13 @@
export async function load({ url, fetch }) {
try {
const apiClient = new ApiClient(fetch);
+ const botName = url.searchParams.get("bot");
let query = {
count: PAGE_SIZE,
before: url.searchParams.get("before"),
after: url.searchParams.get("after"),
+ bot: botName,
};
let matches = await apiClient.get("/api/matches", removeUndefined(query));
@@ -23,6 +25,7 @@
return {
props: {
matches,
+ botName,
},
};
} catch (error) {
@@ -49,13 +52,30 @@
import MatchList from "$lib/components/matches/MatchList.svelte";
export let matches: object[];
+ export let botName: string | null;
+
+ type Cursor = {
+ before?: string;
+ after?: string;
+ };
+
+ function pageLink(cursor: Cursor) {
+ let paramsObj = {
+ ...cursor,
+ };
+ if (botName) {
+ paramsObj["bot"] = botName;
+ }
+ const params = new URLSearchParams(paramsObj);
+ return `?${params}`;
+ }
async function loadNewer() {
if (matches.length == 0) {
return;
}
const firstTimestamp = matches[0]["timestamp"];
- goto(`?after=${firstTimestamp}`);
+ goto(pageLink({ after: firstTimestamp }));
}
async function loadOlder() {
@@ -63,7 +83,7 @@
return;
}
const lastTimestamp = matches[matches.length - 1]["timestamp"];
- goto(`?before=${lastTimestamp}`);
+ goto(pageLink({ before: lastTimestamp }));
}
</script>