Skip to content

Commit

Permalink
Merge pull request #2 from nklmkln/add-data-export-option
Browse files Browse the repository at this point in the history
add data export
  • Loading branch information
nklmkln authored Jul 24, 2024
2 parents 4bbd0c9 + 1f3982b commit b14b903
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions css/list.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
}

.menuItem {
margin-left: var(--space-xs);

cursor: pointer;

transition: 0.3s ease;
Expand Down
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<link rel="manifest" href="manifest.webmanifest">

<title>Something from Your Mind</title>
<meta name="application-name" content="smthmind">
<meta name="description"
content="A space to collect your thoughts locally on your device and revisit them for reflection">

Expand Down Expand Up @@ -111,6 +112,7 @@
<div id="listHeader">
<span id='clearFilter' onClick='getAndDisplayThoughts()'>ALL THOUGHTS</span>
<div id="listFilter"></div>
<div class="menuItem" id="exportLink"></div>
<div class="menuItem"></div>
</div>
<div id="list"></div>
Expand All @@ -127,6 +129,9 @@
}
</script>
<script src="https://unpkg.com/dexie/dist/dexie.js"></script>
<script src="https://unpkg.com/dexie-export-import/dist/dexie-export-import.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/downloadjs/1.4.8/download.min.js"></script>

<script src="main.js"></script>

</body>
Expand Down
17 changes: 17 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}

0 comments on commit b14b903

Please sign in to comment.