Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
better autosave - only once per 5 seconds with guaranteed save when changing notes
azivnerbcc4f22cf52e
diff --git a/static/js/note.js b/static/js/note.jsindex b3012ebbd1..7bd80e855d 100644--- a/static/js/note.js+++ b/static/js/note.js@@ -11,11 +11,25 @@ let tags = {let noteChangeDisabled = false;+let isNoteChanged = false;+function noteChanged() {if (noteChangeDisabled) {return;}+ isNoteChanged = true;+}++function saveNoteIfChanged(callback) {+ if (!isNoteChanged) {+ if (callback) {+ callback();+ }++ return;+ }+let note = globalNote;let contents = $('#noteDetail').summernote('code');@@ -36,7 +50,13 @@ function noteChanged() {data: JSON.stringify(note),contentType: "application/json",success: function(result) {+ isNoteChanged = false;+message("Saved!");++ if (callback) {+ callback();+ }},error: function(result) {error("Error saving the note!");@@ -44,6 +64,8 @@ function noteChanged() {});}+setInterval(saveNoteIfChanged, 5000);+$(document).ready(function() {$("#noteTitle").on('input', function() {noteChanged();diff --git a/static/js/tree.js b/static/js/tree.jsindex 2968164ca1..5459a4d524 100644--- a/static/js/tree.js+++ b/static/js/tree.js@@ -39,7 +39,7 @@ $(function(){const node = data.node.data;const noteId = node.is_clone ? node.note_clone_id : node.note_id;- loadNote(noteId);+ saveNoteIfChanged(() => loadNote(noteId));},expand: function(event, data) {setExpanded(data.node.key, true);diff --git a/static/js/utils.js b/static/js/utils.jsindex 071437c853..d9108d2be8 100644--- a/static/js/utils.js+++ b/static/js/utils.js@@ -1,7 +1,7 @@function message(str) {- $("#top-message").show();+ $("#top-message").fadeIn(1500);$("#top-message").html(str);- $("#top-message").fadeOut(3000);+ $("#top-message").fadeOut(1500);}function error(str) {diff --git a/static/style.css b/static/style.cssindex ecd10eb101..e5a9baf10f 100644--- a/static/style.css+++ b/static/style.css@@ -6,8 +6,8 @@#top-message {display: none; /* initial state is hidden */- background-color: greenyellow;- color: green;+ background-color: #e0e0e0;+ color: #333;padding: 5px;border-radius: 10px;}