rememberMeInput: false,
notes: [],
searchTerm: null,
- searchTimeout: null,
+ draftSaveTimeout: null,
+ draftContent: null,
searchResults: null,
currentNote: null,
titleInput: null,
});
},
+ getContentForEditor: function() {
+ let draftContent = localStorage.getItem(this.currentNote.filename);
+ if (draftContent) {
+ if (confirm("Do you want to resume the saved draft?")) {
+ return draftContent;
+ } else {
+ localStorage.removeItem(this.currentNote.filename);
+ }
+ }
+ return this.currentNote.content;
+ },
+
loadNote: function(filename) {
let parent = this;
api
this.currentView = this.views.note;
},
+ getEditorContent: function() {
+ return this.$refs.toastUiEditor.invoke("getMarkdown");
+ },
+
+ clearDraftSaveTimeout: function() {
+ if (this.draftSaveTimeout != null) {
+ clearTimeout(this.draftSaveTimeout);
+ }
+ },
+
+ startDraftSaveTimeout: function() {
+ this.clearDraftSaveTimeout();
+ this.draftSaveTimeout = setTimeout(this.saveDraft, 1000);
+ },
+
+ saveDraft: function() {
+ localStorage.setItem(this.currentNote.filename, this.getEditorContent());
+ },
+
saveNote: function() {
- let newContent = this.$refs.toastUiEditor.invoke("getMarkdown");
+ let newContent = this.getEditorContent();
// New Note
if (this.currentNote.lastModified == null) {
},
saveNoteResponseHandler: function(response) {
+ localStorage.removeItem(this.currentNote.filename);
this.currentNote = new Note(
response.data.filename,
response.data.lastModified,
this.toggleEditMode();
},
+ cancelNote: function() {
+ localStorage.removeItem(this.currentNote.filename);
+ if (this.currentNote.lastModified == null) {
+ // Cancelling a new note
+ this.currentNote = null;
+ this.currentView = this.views.home;
+ }
+ this.toggleEditMode();
+ },
+
deleteNote: function() {
if (
confirm(
v-if="currentView == views.note && editMode == true"
type="button"
class="btn btn-secondary mx-1"
- @click="toggleEditMode"
+ @click="cancelNote"
>
Cancel
</button>
<div v-else>
<input type="text" class="form-control" v-model="titleInput" />
<editor
- :initialValue="currentNote.content"
+ :initialValue="getContentForEditor()"
previewStyle="tab"
height="calc(100vh - 180px)"
ref="toastUiEditor"
+ @change="startDraftSaveTimeout"
/>
</div>
</div>