auto-save!
This commit is contained in:
parent
e0fd2317ef
commit
a9aaceb967
|
@ -8,7 +8,7 @@
|
||||||
},
|
},
|
||||||
"package": {
|
"package": {
|
||||||
"productName": "snotes-deck",
|
"productName": "snotes-deck",
|
||||||
"version": "0.0.5"
|
"version": "0.0.6"
|
||||||
},
|
},
|
||||||
"tauri": {
|
"tauri": {
|
||||||
"allowlist": {
|
"allowlist": {
|
||||||
|
|
16
src/main.ts
16
src/main.ts
|
@ -19,6 +19,9 @@ let currentNoteId: number | null = null;
|
||||||
/** reverse the order of note by id in the sidebar */
|
/** reverse the order of note by id in the sidebar */
|
||||||
let reversed = true;
|
let reversed = true;
|
||||||
|
|
||||||
|
let typingTimer: number | null = null;
|
||||||
|
const AUTOSAVE_DELAY = 5000;
|
||||||
|
|
||||||
|
|
||||||
enum EditorState {
|
enum EditorState {
|
||||||
NEW,
|
NEW,
|
||||||
|
@ -104,6 +107,7 @@ async function retrieveNotes(): Promise<Array<JSON>> {
|
||||||
* Handle even listeners on load.
|
* Handle even listeners on load.
|
||||||
* This does not handle listeners for generated fields like
|
* This does not handle listeners for generated fields like
|
||||||
* the Notes in the sidebar.
|
* the Notes in the sidebar.
|
||||||
|
* TODO: consistency
|
||||||
*/
|
*/
|
||||||
window.addEventListener("DOMContentLoaded", () => {
|
window.addEventListener("DOMContentLoaded", () => {
|
||||||
createNoteContentEl = document.querySelector("#create-input");
|
createNoteContentEl = document.querySelector("#create-input");
|
||||||
|
@ -172,6 +176,16 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// auto-save timer
|
||||||
|
createNoteContentEl?.addEventListener("keyup", () => {
|
||||||
|
if (editorState === EditorState.EDITING) {
|
||||||
|
if (typingTimer) {
|
||||||
|
clearTimeout(typingTimer);
|
||||||
|
}
|
||||||
|
typingTimer = window.setTimeout(() => saveNote(), AUTOSAVE_DELAY);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
refreshContextMenuElements();
|
refreshContextMenuElements();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -431,4 +445,4 @@ async function refreshSidebarAndOpenLatestNote() {
|
||||||
function toggleReverse(val: boolean) {
|
function toggleReverse(val: boolean) {
|
||||||
reversed = val;
|
reversed = val;
|
||||||
showNotes();
|
showNotes();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue