From 9cae9c1d2a0b4f7fa72f3075541b9ffafe1a7275 Mon Sep 17 00:00:00 2001
From: Zach Berwaldt <zberwaldt@tutamail.com>
Date: Fri, 15 Mar 2024 18:49:43 -0400
Subject: Add routes for preference, clean up and add types

---
 fe/src/lib/DataView.svelte | 40 ++++++++++++++--------------------------
 1 file changed, 14 insertions(+), 26 deletions(-)

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

diff --git a/fe/src/lib/DataView.svelte b/fe/src/lib/DataView.svelte
index 0a6b81b..5e81a5a 100644
--- a/fe/src/lib/DataView.svelte
+++ b/fe/src/lib/DataView.svelte
@@ -1,10 +1,11 @@
 <script lang="ts">
     import { onDestroy, onMount } from "svelte";
-    import HttpClient from "../http";
+    import http from "../http";
     import { token } from "../stores/auth";
     import { addFormOpen } from "../stores/forms";
     import Table from "./Table.svelte";
-    import Chart from "chart.js/auto";
+    import ChartJS from "chart.js/auto";
+    import Chart from './Chart.svelte'
     import Card from "./Card.svelte";
     import Column from "./Column.svelte";
     import AddForm from "./forms/AddForm.svelte";
@@ -46,8 +47,8 @@
 
         if (res.ok) {
             const json = await res.json();
-            let labels = json.map(d => d.name);
-            let data = json.map(d => d.total);
+            let labels = json.map((d: any) => d.name);
+            let data = json.map((d: any) => d.total);
             return [labels, data];
         } else {
             throw new Error("There was a problem with your request");
@@ -65,8 +66,8 @@
 
         if (res.ok) {
             const json = await res.json();
-            let labels = json.map(d => d.date);
-            let data = json.map(d => d.total);
+            let labels = json.map((d: any) => d.date);
+            let data = json.map((d: any) => d.total);
             return [labels, data];
         } else {
             throw new Error("There was a problem with your request");
@@ -84,9 +85,9 @@
         fetchDailyUserStatistics().then(updateDailyUserTotalsChart).catch(err => console.error(err));
     }
 
-    function setupWeeklyTotalsChart(result) {
+    function setupWeeklyTotalsChart(result: any) {
         [lastSevenDays, lastSevenDaysData] = result;
-        lineChart = new Chart(lineCanvasRef, {
+        lineChart = new ChartJS(lineCanvasRef, {
             type: "line",
             data: {
                 labels: lastSevenDays,
@@ -129,10 +130,10 @@
         });
     }
 
-    function setupDailyUserTotalsChart(result) {
+    function setupDailyUserTotalsChart(result: any) {
         [userTotalsLabels, userTotalsData] = result;
 
-        barChart = new Chart(barCanvasRef, {
+        barChart = new ChartJS(barCanvasRef, {
             type: "bar",
             data: {
                 labels: userTotalsLabels,
@@ -177,13 +178,13 @@
         });
     }
 
-    function updateWeeklyTotalsChart(result) {
+    function updateWeeklyTotalsChart(result: any) {
         [, lastSevenDaysData] = result;
         lineChart.data.datasets[0].data = lastSevenDaysData;
         lineChart.update();
     }
 
-    function updateDailyUserTotalsChart(result) {
+    function updateDailyUserTotalsChart(result: any) {
         [, userTotalsData] = result;
         barChart.data.datasets[0].data = userTotalsData;
         barChart.update();
@@ -205,6 +206,7 @@
 
 <Column --width="500px">
     <Card --height="300px">
+        <!--<Chart />-->
         <canvas bind:this={barCanvasRef} />
     </Card>
     <Card --height="300px">
@@ -223,17 +225,3 @@
     </Card>
 </Column>
 <!-- <Chart /> -->
-
-
-<style>
-    dialog {
-        background: red;
-        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);
-        background-color: red;
-    }
-</style>
-- 
cgit v1.1

