From db7980504f75371965fe887f2e459c8554ac09d0 Mon Sep 17 00:00:00 2001
From: Ilion Beyst <ilion.beyst@gmail.com>
Date: Sun, 7 Aug 2022 10:57:15 +0200
Subject: move match index to ApiClient

---
 web/pw-server/src/routes/matches/index.svelte | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 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 c89013e..af0cd08 100644
--- a/web/pw-server/src/routes/matches/index.svelte
+++ b/web/pw-server/src/routes/matches/index.svelte
@@ -1,23 +1,22 @@
 <script lang="ts" context="module">
-  export async function load() {
-    const res = await fetch("/api/matches", {
-      headers: {
-        "Content-Type": "application/json",
-      },
-    });
+  import { ApiClient } from "$lib/api_client";
+
+  export async function load({ fetch }) {
+    try {
+      const apiClient = new ApiClient(fetch);
+      const matches = await apiClient.get("/api/matches");
 
-    if (res.ok) {
       return {
         props: {
-          matches: await res.json(),
+          matches,
         },
       };
+    } catch (error) {
+      return {
+        status: error.status,
+        error: new Error("failed to load matches"),
+      };
     }
-
-    return {
-      status: res.status,
-      error: new Error("failed to load matches"),
-    };
   }
 </script>
 
-- 
cgit v1.2.3

