From 7ba9fcee64387dd28064ae051aee344d73e889db Mon Sep 17 00:00:00 2001
From: Ilion Beyst <ilion.beyst@gmail.com>
Date: Fri, 12 Aug 2022 20:54:34 +0200
Subject: allow filtering for bot matches

---
 web/pw-server/src/routes/matches/index.svelte | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

(limited to 'web/pw-server/src/routes/matches/index.svelte')

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>
 
-- 
cgit v1.2.3

