From 1f3982b1ef1b4656c829ec67f393b5a14c55bfff Mon Sep 17 00:00:00 2001 From: Nico Date: Wed, 24 Jul 2024 13:46:20 +0200 Subject: [PATCH] add data export --- css/list.css | 2 ++ index.html | 5 +++++ main.js | 17 +++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/css/list.css b/css/list.css index 53e4db6..f899fa9 100644 --- a/css/list.css +++ b/css/list.css @@ -29,6 +29,8 @@ } .menuItem { + margin-left: var(--space-xs); + cursor: pointer; transition: 0.3s ease; diff --git a/index.html b/index.html index 463e9f0..f8fec08 100644 --- a/index.html +++ b/index.html @@ -22,6 +22,7 @@ Something from Your Mind + @@ -111,6 +112,7 @@
ALL THOUGHTS
+
@@ -127,6 +129,9 @@ } + + + diff --git a/main.js b/main.js index 0697dc6..9067809 100644 --- a/main.js +++ b/main.js @@ -108,3 +108,20 @@ function displayThoughts(items) { function deleteItem(timestamp) { db.thoughts.delete(timestamp).then(getAndDisplayThoughts); } + +document.addEventListener("DOMContentLoaded", () => { + const exportLink = document.getElementById("exportLink"); + + exportLink.onclick = async () => { + try { + const blob = await db.export({ prettyJson: true, progressCallback }); + download(blob, "my_smthmind_data.json", "application/json"); + } catch (error) { + console.error("" + error); + } + }; +}); + +function progressCallback({ totalRows, completedRows }) { + console.log(`Progress: ${completedRows} of ${totalRows} rows completed`); +}