From 39feeb74ffad85ba038e70773eba30385155c950 Mon Sep 17 00:00:00 2001
From: Furkan Sahin <furkan-dev@proton.me>
Date: Tue, 19 Jul 2022 15:20:56 -0400
Subject: Parse local storage db if it exists. Move json parsing to `ts` files,
 remove `json` from rollup

---
 src/components/Sidebar.svelte | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

(limited to 'src/components/Sidebar.svelte')

diff --git a/src/components/Sidebar.svelte b/src/components/Sidebar.svelte
index 6eecf51..92f6427 100644
--- a/src/components/Sidebar.svelte
+++ b/src/components/Sidebar.svelte
@@ -3,10 +3,8 @@
   import AssignLabs from "./AssignLabs/AssignLabs.svelte";
   import FileUploads from "./FileUploads.svelte";
   import { onMount } from "svelte";
-  import { parseDatabase, parseDatabaseLocal } from "../util/parser";
-  import { parseDatabaseFile } from "../logic/EditorActions";
-  import * as local_db from "../../pt-db.json";
- //
+  import { parseDatabaseLocalStorage } from "../util/parser";
+
   let sections = [
     { name: "File Uploads", component: FileUploads },
     { name: "Peer Teachers", component: null }, // TODO
@@ -20,10 +18,15 @@
   // Set initial page to Assign Labs while I work on it
   let selected = sections[2];
 
-  onMount(async () => {
-    // load database on mount for testing purposes
-    console.log("reading local database");
-    parseDatabaseLocal(local_db);
+  // Load from local storage. FOR TESTING PURPOSES ONLY. REMOVE THIS FROM PRODUCTION
+  onMount(() => {
+    const db = localStorage.getItem("db");
+    if (db) {
+      console.log("Using database found in local storage");
+      parseDatabaseLocalStorage(db);
+    } else {
+      console.log("No database found in local storage");
+    }
   });
 </script>
 
-- 
cgit v1.2.3

