From afeffe31bd7d0f8333627a972e1d32e64a325b5b Mon Sep 17 00:00:00 2001
From: Zach Berwaldt <zberwaldt@tutamail.com>
Date: Fri, 1 Mar 2024 18:17:42 -0500
Subject: reformat fe

---
 fe/src/lib/DataView.svelte | 177 ++++++++++++++++++++++-----------------------
 1 file changed, 87 insertions(+), 90 deletions(-)

(limited to 'fe/src/lib/DataView.svelte')

diff --git a/fe/src/lib/DataView.svelte b/fe/src/lib/DataView.svelte
index dc8acae..1458c9a 100644
--- a/fe/src/lib/DataView.svelte
+++ b/fe/src/lib/DataView.svelte
@@ -1,126 +1,123 @@
-<script lang='ts'>
-import { onMount } from 'svelte';
-import type { Preference } from '../types';
-import { token, user, preferences } from '../stores/auth'
-import Table from './Table.svelte';
-import PreferencesForm from './PreferencesForm.svelte';
+<script lang="ts">
+  import { onMount } from "svelte";
+  import type { Statistic } from "../types";
+  import { token, user } from "../stores/auth";
+  import Table from "./Table.svelte";
 
-const formatter = new Intl.DateTimeFormat(
-    'en',
-    {
-        year: 'numeric',
-        month: '2-digit',
-        day: '2-digit'
-    }
-);
-
-let json;
-let showAddForm: boolean = false;
+  let json: Promise<any>;
+  let showAddForm: boolean = false;
 
-let statistic: Statistic = newStatistic();
+  let statistic: Statistic = newStatistic();
 
-async function fetchData() {
-    const res = await fetch('http://localhost:8080/api/v1/stats/', {
-        method: "GET",
-        headers: {
-            'Authorization': `Bearer ${$token}`
-        }
+  async function fetchData() {
+    const res = await fetch("http://localhost:8080/api/v1/stats/", {
+      method: "GET",
+      headers: {
+        Authorization: `Bearer ${$token}`,
+      },
     });
     if (res.ok) {
-        json = res.json();
+      json = res.json();
     } else {
-        throw new Error('There was a problem with your request');
+      throw new Error("There was a problem with your request");
     }
-}
+  }
 
-async function submitStat() {
-    const response = await fetch('http://localhost:8080/api/v1/stats/', {
-        method: "POST",
-        headers: {
-            'Authorization': `Bearer ${$token}`
-        },
-        body: JSON.stringify({
-            date: new Date,
-            user_id: 1,
-            quantity: 3
-        })
+  async function submitStat() {
+    const response = await fetch("http://localhost:8080/api/v1/stats/", {
+      method: "POST",
+      headers: {
+        Authorization: `Bearer ${$token}`,
+      },
+      body: JSON.stringify({
+        date: new Date(),
+        user_id: 1,
+        quantity: 3,
+      }),
     });
     fetchData();
-}
+  }
 
-function handleClick() {
+  function handleClick() {
     showAddForm = true;
-}
+  }
 
-function handleAddDialogSubmit (e) {
+  function handleAddDialogSubmit(e: Event) {
     console.log(statistic);
     showAddForm = false;
-}
+  }
 
-function closeDialog () {
+  function closeDialog() {
     showAddForm = false;
-}
+  }
 
-function newStatistic (): Statistic {
-    let now = new Date(), month, day, year;
+  function newStatistic(): Statistic {
+    let now = new Date(),
+      month,
+      day,
+      year;
 
     month = `${now.getMonth() + 1}`;
     day = `${now.getDate()}`;
     year = now.getFullYear();
-    if (month.length < 2)
-        month = '0' + month;
-    if (day.length < 2)
-        day = '0' + day;
+    if (month.length < 2) month = "0" + month;
+    if (day.length < 2) day = "0" + day;
 
-    const date = [year, month, day].join('-');
+    const date = [year, month, day].join("-");
 
     return {
-        user_id: $user.uuid,
-        date,
-        quantity: 1
-    }
-}
+      user_id: $user!.uuid,
+      date,
+      quantity: 1,
+    };
+  }
 
-onMount(() => {
+  onMount(() => {
     fetchData();
-});
-
+  });
 </script>
+
 <div>
-    <button on:click={submitStat}>Add Stat Test</button>
-    <PreferencesForm />
-    <dialog open={showAddForm} on:submit={handleAddDialogSubmit}>
-        <h2>Add Water</h2>
-        <form method="dialog">
-            <div class='form input group'>
-                <label for="date">Date:</label>
-                <input bind:value={statistic.date} id="date" name="date" type="date" />
-            </div>
-            <div class='form input group'>
-                <label for="quantity">Quantity:</label>
-                <input bind:value={statistic.quantity} id="quantity" name="quantity" type="number" min="0" autocomplete="off"/>
-            </div>
-            <button on:click={closeDialog}>Cancel</button>
-            <button type="submit">Submit</button>
-        </form>
-    </dialog>
-    <button on:click={handleClick}>Add</button>
-    {#await json then data}
-        <Table {data} nofooter />
-    {:catch error}
-        <p>{error}</p>
-    {/await}
-    <!-- <Chart /> -->
+  <button on:click={submitStat}>Add Stat Test</button>
+  <dialog open={showAddForm} on:submit={handleAddDialogSubmit}>
+    <h2>Add Water</h2>
+    <form method="dialog">
+      <div class="form input group">
+        <label for="date">Date:</label>
+        <input bind:value={statistic.date} id="date" name="date" type="date" />
+      </div>
+      <div class="form input group">
+        <label for="quantity">Quantity:</label>
+        <input
+          bind:value={statistic.quantity}
+          id="quantity"
+          name="quantity"
+          type="number"
+          min="0"
+          autocomplete="off"
+        />
+      </div>
+      <button on:click={closeDialog}>Cancel</button>
+      <button type="submit">Submit</button>
+    </form>
+  </dialog>
+  <button on:click={handleClick}>Add</button>
+  {#await json then data}
+    <Table {data} nofooter />
+  {:catch error}
+    <p>{error}</p>
+  {/await}
+  <!-- <Chart /> -->
 </div>
 
 <style>
-dialog {
+  dialog {
     background: red;
-    box-shadow: 0 20px 5em 10px rgba(0,0,0,0.8);
-}
-dialog::backdrop {
+    box-shadow: 0 20px 5em 10px rgba(0, 0, 0, 0.8);
+  }
+  dialog::backdrop {
     padding: 20px;
-    box-shadow: 20px 20px rgba(0,0,0,0.8);
+    box-shadow: 20px 20px rgba(0, 0, 0, 0.8);
     background-color: red;
-}
+  }
 </style>
-- 
cgit v1.1

