Centralised toast messaging.
authorAdam Dullage <redacted>
Mon, 5 Feb 2024 20:50:05 +0000 (20:50 +0000)
committerAdam Dullage <redacted>
Mon, 5 Feb 2024 20:50:05 +0000 (20:50 +0000)
client/components/App.js
client/components/App.vue
client/components/Login.vue
client/components/NoteViewerEditor.vue
client/components/RecentlyModified.vue
client/components/SearchInput.vue
client/components/SearchResults.vue

index 8ea084db670eb4d0ca2e88055b8d211ed6b47b04..01a88895fd1c341c37ccd9db4a7d2267f45c7125 100644 (file)
@@ -134,12 +134,16 @@ export default {
       this.navigate(constants.basePaths.login);
     },
 
-    noteDeletedToast: function () {
-      this.$bvToast.toast("Note deleted ✓", {
-        variant: "success",
+    showToast: function (variant, message, title = null) {
+      const options = {
+        variant: variant,
         noCloseButton: true,
         toaster: "b-toaster-bottom-right",
-      });
+      };
+      if (title != null) {
+        options.title = title;
+      }
+      this.$bvToast.toast(message, options);
     },
 
     focusSearchInput: function () {
@@ -158,14 +162,10 @@ export default {
     },
 
     unhandledServerErrorToast: function () {
-      this.$bvToast.toast(
+      this.showToast(
+        "danger",
         "Unknown error communicating with the server. Please try again.",
-        {
-          title: "Unknown Error",
-          variant: "danger",
-          noCloseButton: true,
-          toaster: "b-toaster-bottom-right",
-        }
+        "Unknown Error"
       );
     },
 
@@ -186,7 +186,8 @@ export default {
     this.constants = constants;
 
     EventBus.$on("navigate", this.navigate);
-    EventBus.$on("unhandledServerError", this.unhandledServerErrorToast);
+    EventBus.$on("showToast", this.showToast);
+    EventBus.$on("unhandledServerErrorToast", this.unhandledServerErrorToast);
     EventBus.$on("updateNoteTitle", this.updateNoteTitle);
 
     Mousetrap.bind("/", function () {
index 78f0b71caedcf3fb5b4c8412b855f26eae55e5c3..3e46c528d6ba7741c97da8dc7d2c597e47f304d8 100644 (file)
@@ -61,7 +61,7 @@
       class="flex-grow-1"
       :titleToLoad="noteTitle"
       :auth-type="authType"
-      @note-deleted="noteDeletedToast"
+      @note-deleted="showToast('success', 'Note deleted ✓')"
     ></NoteViewerEditor>
   </div>
 </template>
index 4a42c03d6362e1c1ba26e3687c41e5864f6c5e36..5080b5ee1d747a689dbafeb4f348aa3a3e29d388 100644 (file)
@@ -148,13 +148,9 @@ export default {
             typeof error.response !== "undefined" &&
             error.response.status == 401
           ) {
-            parent.$bvToast.toast("Incorrect login credentials ✘", {
-              variant: "danger",
-              noCloseButton: true,
-              toaster: "b-toaster-bottom-right",
-            });
+            EventBus.$emit("showToast", "danger", "Incorrect login credentials ✘")
           } else {
-            EventBus.$emit("unhandledServerError");
+            EventBus.$emit("unhandledServerErrorToast");
           }
         })
         .finally(function () {
index e62467b775f48f1a749104d3a2a686ac6a7779b8..d1a855017ffc3276163d51e76e6a25ec9dab8981 100644 (file)
@@ -243,13 +243,10 @@ export default {
 
   methods: {
     badFilenameToast: function (invalidItem) {
-      this.$bvToast.toast(
-        `Invalid ${invalidItem}. Due to filename restrictions, the following characters are not allowed: <>:"/\\|?*`,
-        {
-          variant: "danger",
-          noCloseButton: true,
-          toaster: "b-toaster-bottom-right",
-        }
+      EventBus.$emit(
+        "showToast",
+        "danger",
+        `Invalid ${invalidItem}. Due to filename restrictions, the following characters are not allowed: <>:"/\\|?*`
       );
     },
 
@@ -276,7 +273,7 @@ export default {
             parent.noteLoadFailedMessage = "Note not found";
             parent.noteLoadFailed = true;
           } else {
-            EventBus.$emit("unhandledServerError");
+            EventBus.$emit("unhandledServerErrorToast");
             parent.noteLoadFailed = true;
           }
         });
@@ -392,26 +389,20 @@ export default {
     },
 
     existingTitleToast: function () {
-      this.$bvToast.toast(
+      EventBus.$emit(
+        "showToast",
+        "danger",
         "A note with this title already exists. Please try again with a new title.",
-        {
-          title: "Duplicate ✘",
-          variant: "danger",
-          noCloseButton: true,
-          toaster: "b-toaster-bottom-right",
-        }
+        "Duplicate ✘"
       );
     },
 
     entityTooLargeToast: function (entityName) {
-      this.$bvToast.toast(
+      EventBus.$emit(
+        "showToast",
+        "danger",
         `This ${entityName.toLowerCase()} is too large. Please try again with a smaller ${entityName.toLowerCase()} or adjust your server configuration.`,
-        {
-          title: `${entityName} Too Large ✘`,
-          variant: "danger",
-          noCloseButton: true,
-          toaster: "b-toaster-bottom-right",
-        }
+        `${entityName} Too Large ✘`
       );
     },
 
@@ -426,11 +417,11 @@ export default {
         this.titleInput = this.titleInput.trim();
       }
       if (!this.titleInput) {
-        this.$bvToast.toast("Cannot save note without a title ✘", {
-          variant: "danger",
-          noCloseButton: true,
-          toaster: "b-toaster-bottom-right",
-        });
+        EventBus.$emit(
+          "showToast",
+          "danger",
+          "Cannot save note without a title ✘"
+        );
         return;
       }
 
@@ -455,7 +446,7 @@ export default {
             } else if (error.response?.status == 413) {
               this.entityTooLargeToast("Note");
             } else {
-              EventBus.$emit("unhandledServerError");
+              EventBus.$emit("unhandledServerErrorToast");
             }
           });
       }
@@ -480,7 +471,7 @@ export default {
             ) {
               parent.existingTitleToast();
             } else {
-              EventBus.$emit("unhandledServerError");
+              EventBus.$emit("unhandledServerErrorToast");
             }
           });
       }
@@ -507,11 +498,7 @@ export default {
     },
 
     noteSavedToast: function () {
-      this.$bvToast.toast("Note saved ✓", {
-        variant: "success",
-        noCloseButton: true,
-        toaster: "b-toaster-bottom-right",
-      });
+      EventBus.$emit("showToast", "success", "Note saved ✓");
     },
 
     cancelNote: function () {
@@ -575,7 +562,7 @@ export default {
               })
               .catch(function (error) {
                 if (!error.handled) {
-                  EventBus.$emit("unhandledServerError");
+                  EventBus.$emit("unhandledServerErrorToast");
                 }
               });
           }
@@ -613,11 +600,7 @@ export default {
         return false;
       }
 
-      this.$bvToast.toast("Uploading attachment...", {
-        variant: "success",
-        noCloseButton: true,
-        toaster: "b-toaster-bottom-right",
-      });
+      EventBus.$emit("showToast", "success", "Uploading attachment...");
 
       const formData = new FormData();
       formData.append("file", file);
@@ -628,31 +611,24 @@ export default {
           },
         })
         .then(function () {
-          parent.$bvToast.toast("Attachment uploaded ✓", {
-            variant: "success",
-            noCloseButton: true,
-            toaster: "b-toaster-bottom-right",
-          });
+          EventBus.$emit("showToast", "success", "Attachment uploaded ✓");
           return true;
         })
         .catch(function (error) {
           if (error.response?.status == 409) {
-            parent.$bvToast.toast(
-              "An attachment with this filename already exists ✘",
-              {
-                variant: "danger",
-                noCloseButton: true,
-                toaster: "b-toaster-bottom-right",
-              }
+            EventBus.$emit(
+              "showToast",
+              "danger",
+              "An attachment with this filename already exists ✘"
             );
           } else if (error.response?.status == 413) {
             this.entityTooLargeToast("Attachment");
           } else {
-            parent.$bvToast.toast("Failed to upload attachment ✘", {
-              variant: "danger",
-              noCloseButton: true,
-              toaster: "b-toaster-bottom-right",
-            });
+            EventBus.$emit(
+              "showToast",
+              "danger",
+              "Failed to upload attachment ✘"
+            );
           }
           return false;
         });
index 789d29822a96fa06535ad4a3bffacadf5d1f2b22..af872b05e3d947351f2cbd1f762b7c219ef5cde6 100644 (file)
@@ -92,7 +92,7 @@ export default {
         .catch(function (error) {
           parent.loadingFailed = true;
           if (!error.handled) {
-            EventBus.$emit("unhandledServerError");
+            EventBus.$emit("unhandledServerErrorToast");
           }
         });
     },
index fb54f91fc213788da501df49fefe2cdb70c4b95e..dea5212a5a6c2c6c2b0d38afee183cdab466a8f4 100644 (file)
@@ -93,11 +93,7 @@ export default {
           }=${encodeURIComponent(this.searchTermInput)}`
         );
       } else {
-        this.$bvToast.toast("Please enter a search term ✘", {
-          variant: "danger",
-          noCloseButton: true,
-          toaster: "b-toaster-bottom-right",
-        });
+        EventBus.$emit("showToast", "danger", "Please enter a search term ✘");
       }
     },
 
index e39083b0f25e067d1f4779dc425e1ce9b00c6167..f8792cf7f4e96d09bd0429482202850b79d928f7 100644 (file)
@@ -232,7 +232,7 @@ export default {
         .catch(function (error) {
           if (!error.handled) {
             parent.searchFailed = true;
-            EventBus.$emit("unhandledServerError");
+            EventBus.$emit("unhandledServerErrorToast");
           }
         });
     },
git clone https://git.99rst.org/PROJECT