From 003c551e7320912d468b00905da234ad262b5446 Mon Sep 17 00:00:00 2001
From: Ilion Beyst <ilion.beyst@gmail.com>
Date: Sat, 25 Dec 2021 20:28:10 +0100
Subject: implement basic MatchBrowser component

---
 web/pw-frontend/src/lib/MatchBrowser.svelte | 89 +++++++++++++++++++++++++++++
 1 file changed, 89 insertions(+)
 create mode 100644 web/pw-frontend/src/lib/MatchBrowser.svelte

(limited to 'web/pw-frontend/src/lib/MatchBrowser.svelte')

diff --git a/web/pw-frontend/src/lib/MatchBrowser.svelte b/web/pw-frontend/src/lib/MatchBrowser.svelte
new file mode 100644
index 0000000..71fadb2
--- /dev/null
+++ b/web/pw-frontend/src/lib/MatchBrowser.svelte
@@ -0,0 +1,89 @@
+<script lang="ts">
+  import { onMount } from "svelte";
+  import Visualizer from "./Visualizer.svelte";
+
+  let matches = [];
+  let selectedMatch = null;
+  let selectedMatchLog = null;
+
+  onMount(() => {
+    fetch("/api/matches")
+      .then((response) => response.json())
+      .then((m) => (matches = m));
+  });
+
+  function selectMatch(matchName) {
+    selectedMatch = matchName;
+    selectedMatchLog = null;
+    fetch(`/api/matches/${matchName}`)
+      .then((resp) => resp.text())
+      .then((log) => {
+        selectedMatchLog = log;
+      });
+  }
+</script>
+
+<div class="container">
+  <div class="sidebar">
+    <div class="sidebar-header" />
+    <ul class="match-list">
+      {#each matches as match (match.name)}
+        <li
+          on:click={() => selectMatch(match.name)}
+          class:selected={selectedMatch === match.name}
+          class="match-card"
+        >
+          {match.name}
+        </li>
+      {/each}
+    </ul>
+  </div>
+  <Visualizer matchLog={selectedMatchLog} />
+</div>
+
+<style scoped>
+  .container {
+    display: flex;
+    width: 100vw;
+    height: 100vh;
+    overflow-y: hidden;
+    background-color: rgb(41, 41, 41);
+  }
+
+  .sidebar {
+    width: 20%;
+    width: 350px;
+    color: #eee;
+    overflow: hidden;
+    overflow-y: scroll;
+    height: 100%;
+  }
+
+  .sidebar-header {
+    margin-top: 2em;
+    text-transform: uppercase;
+    font-weight: 600;
+    color: rgba(255, 255, 255, 0.7);
+    font-size: 14px;
+    font-family: "Open Sans", sans-serif;
+    padding-left: 14px;
+  }
+
+  .match-list {
+    list-style: none;
+    padding: 0;
+  }
+
+  .match-card {
+    padding: 0.5em;
+    padding-left: 14px;
+  }
+
+  .match-card.selected {
+    background-color: #333;
+  }
+
+  .match-card:hover {
+    background-color: #333;
+  }
+</style>
-- 
cgit v1.2.3

