Skip to content

Commit

Permalink
Add export all notes functionality and style updates for export modal
Browse files Browse the repository at this point in the history
  • Loading branch information
vorlie committed Jan 5, 2025
1 parent c56cb28 commit d8fc757
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ <h2 class="header-h2">Notes</h2>
<div id="exportModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeExportModal()">&times;</span>
<h2 class="modal-h2">Click on an item to export</h2>
<div style="display: flex; justify-content: space-between; align-items: center;">
<h2 class="modal-h2">Click on an item to export</h2>
<button title="Export all notes as JSON" class="button" onclick="exportAllNotesAsJson()">Export All as JSON</button>
</div>
<ul class="export-note-list"></ul>
</div>
</div>
Expand Down
14 changes: 14 additions & 0 deletions src/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,21 @@ body {
max-height: 80vh;
overflow: hidden;
}
.modal .button {
background-color: var(--button-bg-color);
color: var(--button-color);
border: 1px solid var(--button-border-color);
border-radius: var(--button-border-radius);
padding: var(--button-padding);
cursor: pointer;
transition: var(--hover-transition);
margin-right: 150px;
margin-bottom: 10px;
}

.button:hover {
background-color: var(--button-bg-color-hover);
}
.modal-h2{
margin: 0px 0px 10px 0px;
}
Expand Down
12 changes: 12 additions & 0 deletions src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ function exportSelectedNoteById(id) {
closeExportModal();
}

function exportAllNotesAsJson() {
const notes = getNotesFromLocalStorage();
const json = JSON.stringify(notes, null, 2);
const blob = new Blob([json], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'notes.json';
a.click();
URL.revokeObjectURL(url);
}

function importNotes(event) {
const files = event.target.files;
const notes = getNotesFromLocalStorage();
Expand Down

0 comments on commit d8fc757

Please sign in to comment.