Skip to content

Commit d68d712

Browse files
committed
Add download feature
1 parent 79d7fea commit d68d712

File tree

5 files changed

+146
-1
lines changed

5 files changed

+146
-1
lines changed

package-lock.json

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
"homepage": "https://apps.peterjuma.com/noteApp",
1111
"dependencies": {
1212
"@monaco-editor/react": "^4.1.3",
13+
"file-saver": "^2.0.5",
1314
"gh-pages": "^3.1.0",
1415
"github-markdown": "^3.2.0",
1516
"github-markdown-css": "^4.0.0",
1617
"highlight.js": "^10.5.0",
1718
"idb": "^6.0.0",
1819
"jquery": "^3.5.1",
20+
"jszip": "^3.6.0",
1921
"markdown-it": "^8.4.2",
2022
"markdown-it-emoji": "^2.0.0",
2123
"markdown-it-html5-embed": "^1.0.0",

src/App.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import keyCodes from "./KeyCodes";
1212
import { openDB } from "idb/with-async-ittr.js";
1313
import { html2md, md2html } from "./useMarkDown";
1414
import marked from "marked";
15+
import { saveAs } from "file-saver";
1516

1617
class App extends Component {
1718
constructor(props) {
@@ -50,6 +51,7 @@ class App extends Component {
5051
this.handleCopyCodeButtonClick;
5152
this.handleSplitScreen = this.handleSplitScreen.bind(this);
5253
this.handleNoteEditor = this.handleNoteEditor.bind(this);
54+
this.handleNotesBackup = this.handleNotesBackup.bind(this);
5355
}
5456

5557
async componentDidMount() {
@@ -645,6 +647,18 @@ class App extends Component {
645647
e.preventDefault();
646648
}
647649

650+
handleNotesBackup() {
651+
const zip = require("jszip")();
652+
this.state.allnotes.map((note) => {
653+
const title = `${note.title.replace(/[^A-Z0-9]+/gi, "_") || "note"}.md`;
654+
zip.file(title, note.body);
655+
});
656+
657+
zip.generateAsync({ type: "blob" }).then((content) => {
658+
saveAs(content, "notes_backup.zip");
659+
});
660+
}
661+
648662
handleSplitScreen() {
649663
this.setState((prevState) => ({
650664
split: !prevState.split,
@@ -727,7 +741,10 @@ class App extends Component {
727741
handleSearchNotes={this.handleSearchNotes}
728742
/>
729743
<ul className="note-list">{noteListItems}</ul>
730-
<NoteSort handleSortNotes={this.handleSortNotes} />
744+
<NoteSort
745+
handleSortNotes={this.handleSortNotes}
746+
handleNotesBackup={this.handleNotesBackup}
747+
/>
731748
</div>
732749
<div className="right">
733750
{RightNavbar}

src/NoteSort.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ function NoteSort(props) {
1717
<option value="5">Modified: Oldest</option>
1818
</select>
1919
</label>
20+
<div className="backupbtn">
21+
<i class="fas fa-download btn" onClick={props.handleNotesBackup}></i>
22+
</div>
2023
</div>
2124
);
2225
}

src/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ ol {
209209
bottom: 0;
210210
}
211211

212+
.backupbtn {
213+
float: right;
214+
}
215+
212216
.right-bottom-bar {
213217
height: 50px;
214218
line-height: 44px;

0 commit comments

Comments
 (0)