From: Adam Dullage Date: Tue, 28 Jun 2022 20:08:23 +0000 (+0100) Subject: Add message when trying to save a note with a duplicate title. Resolves #3. X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=efce4d82802cc8f7605e3e6b0bd526a7579bd482;p=flatnotes.git Add message when trying to save a note with a duplicate title. Resolves #3. --- diff --git a/flatnotes/main.py b/flatnotes/main.py index b2dde6e..c1b627c 100644 --- a/flatnotes/main.py +++ b/flatnotes/main.py @@ -119,6 +119,8 @@ async def patch_note( return NoteModel.dump(note, include_content=True) except InvalidFilenameError: return invalid_filename_response + except FileExistsError: + return file_exists_response except FileNotFoundError: return file_not_found_response diff --git a/flatnotes/src/components/App.js b/flatnotes/src/components/App.js index 57b969c..9715556 100644 --- a/flatnotes/src/components/App.js +++ b/flatnotes/src/components/App.js @@ -232,7 +232,19 @@ export default { localStorage.setItem(this.currentNote.filename, this.getEditorContent()); }, + existingFilenameToast: function() { + this.$bvToast.toast( + "A note with this title already exists. Please try again with a new title.", + { + title: "Duplicate ✘", + variant: "danger", + noCloseButton: true, + } + ); + }, + saveNote: function() { + let parent = this; let newContent = this.getEditorContent(); // New Note @@ -242,7 +254,12 @@ export default { filename: `${this.titleInput}.${constants.markdownExt}`, content: newContent, }) - .then(this.saveNoteResponseHandler); + .then(this.saveNoteResponseHandler) + .catch(function(error) { + if (error.response.status == 409) { + parent.existingFilenameToast(); + } + }); } // Modified Note @@ -255,7 +272,12 @@ export default { newFilename: `${this.titleInput}.${this.currentNote.ext}`, newContent: newContent, }) - .then(this.saveNoteResponseHandler); + .then(this.saveNoteResponseHandler) + .catch(function(error) { + if (error.response.status == 409) { + parent.existingFilenameToast(); + } + }); } // No Change