diff options
| author | Furkan Sahin <furkan-dev@proton.me> | 2022-07-19 15:35:32 -0400 |
|---|---|---|
| committer | Furkan Sahin <furkan-dev@proton.me> | 2022-07-19 15:35:32 -0400 |
| commit | 309f893dbcf50e021588111c6644848cf177373b (patch) | |
| tree | 4c23d4d81a7a1221993bf580082a8987c9c5d7cf /src/components/FileUploads.svelte | |
| parent | 39feeb74ffad85ba038e70773eba30385155c950 (diff) | |
Add option to export to DB, also make function to unmarshall/strigify a db object. See whether this function can instead be moved to the `DatabaseFile` interface, just like `UnmarshalJson` in `Go`
Diffstat (limited to 'src/components/FileUploads.svelte')
| -rw-r--r-- | src/components/FileUploads.svelte | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/components/FileUploads.svelte b/src/components/FileUploads.svelte index 2c246f7..df952df 100644 --- a/src/components/FileUploads.svelte +++ b/src/components/FileUploads.svelte @@ -37,7 +37,7 @@ snackbar.open(); } }) - .finally( () => { + .finally(() => { snackbarText = "Sucessfullyed imported Peer Teacher/s!"; snackbar.open(); }); @@ -80,7 +80,7 @@ } } - function exportDB() { + function dbStringify(): string { const peerTeachers = [...$ptStore.values()]; const labs = [...$labStore.values()]; const database = { @@ -98,6 +98,11 @@ return value; }); + return dbObj; + } + + function exportDB() { + const dbObj = dbStringify(); const blob = new Blob([dbObj], { type: "text/json" }); const anchor = document.createElement("a"); const url = window.URL.createObjectURL(blob); @@ -109,6 +114,11 @@ document.body.removeChild(anchor); window.URL.revokeObjectURL(url); } + + function exportDB2LocalStorage() { + const db = dbStringify(); + localStorage.setItem("db", db); + } </script> <div class="flex flex-col items-center justify-center h-full "> @@ -154,6 +164,15 @@ > <button class="btn btn-warning" on:click={exportDB}>Download</button> </Card> + + <Card + title="Export to Local Storage" + desc="Save current DB to local storage. Local storage db should only be used for testing purposes to avoid data anomalies" + > + <button class="btn btn-warning" on:click={exportDB2LocalStorage} + >LocalStorage</button + > + </Card> </div> </div> |
