auto-save!
This commit is contained in:
parent
e0fd2317ef
commit
a9aaceb967
|
@ -8,7 +8,7 @@
|
|||
},
|
||||
"package": {
|
||||
"productName": "snotes-deck",
|
||||
"version": "0.0.5"
|
||||
"version": "0.0.6"
|
||||
},
|
||||
"tauri": {
|
||||
"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 */
|
||||
let reversed = true;
|
||||
|
||||
let typingTimer: number | null = null;
|
||||
const AUTOSAVE_DELAY = 5000;
|
||||
|
||||
|
||||
enum EditorState {
|
||||
NEW,
|
||||
|
@ -104,6 +107,7 @@ async function retrieveNotes(): Promise<Array<JSON>> {
|
|||
* Handle even listeners on load.
|
||||
* This does not handle listeners for generated fields like
|
||||
* the Notes in the sidebar.
|
||||
* TODO: consistency
|
||||
*/
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
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();
|
||||
});
|
||||
|
||||
|
@ -431,4 +445,4 @@ async function refreshSidebarAndOpenLatestNote() {
|
|||
function toggleReverse(val: boolean) {
|
||||
reversed = val;
|
||||
showNotes();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue