Add message when trying to save a note with a duplicate title. Resolves #3.
authorAdam Dullage <redacted>
Tue, 28 Jun 2022 20:08:23 +0000 (21:08 +0100)
committerAdam Dullage <redacted>
Tue, 28 Jun 2022 20:08:23 +0000 (21:08 +0100)
flatnotes/main.py
flatnotes/src/components/App.js

index b2dde6ec0b035603e221eed2bc25a73bd7827f24..c1b627c154592ae0fc04e78d708c4f070d09b33b 100644 (file)
@@ -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
 
index 57b969c603ffe75dec08c411ac075931813a7a40..971555687cbbad1a349f060af6520d9f7a6e8418 100644 (file)
@@ -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
git clone https://git.99rst.org/PROJECT