]> git.immae.eu Git - github/bastienwirtz/homer.git/commitdiff
Fix dynamic message override.
authorBastien Wirtz <bastien.wirtz@gmail.com>
Mon, 29 Jun 2020 01:31:42 +0000 (18:31 -0700)
committerBastien Wirtz <bastien.wirtz@gmail.com>
Mon, 29 Jun 2020 01:31:42 +0000 (18:31 -0700)
src/components/Message.vue

index fcb0fbba9bb79adf4770dfa8c094a53152a9a3d4..2c3df405daa8fe814d47990c18f17ccf079c27a2 100644 (file)
@@ -1,9 +1,9 @@
 <template>
-  <article v-if="item" class="message" :class="item.style">
-    <div v-if="item.title" class="message-header">
-      <p>{{ item.title }}</p>
+  <article v-if="show" class="message" :class="message.style">
+    <div v-if="message.title" class="message-header">
+      <p>{{ message.title }}</p>
     </div>
-    <div v-if="item.content" class="message-body" v-html="item.content"></div>
+    <div v-if="message.content" class="message-body" v-html="message.content"></div>
   </article>
 </template>
 
@@ -13,19 +13,25 @@ export default {
   props: {
     item: Object,
   },
-  created: function () {
+  data: function () {
+    return {
+      show: false,
+      message: {},
+    };
+  },
+  created: async function () {
     // Look for a new message if an endpoint is provided.
-    let that = this;
+    this.message = Object.assign({}, this.item);
     if (this.item && this.item.url) {
-      this.getMessage(this.item.url).then(function (message) {
-        // keep the original config value if no value is provided by the endpoint
-        for (const prop of ["title", "style", "content"]) {
-          if (prop in message && message[prop] !== null) {
-            that.item[prop] = message[prop];
-          }
+      const fetchedMessage = await this.getMessage(this.item.url);
+      // keep the original config value if no value is provided by the endpoint
+      for (const prop of ["title", "style", "content"]) {
+        if (prop in fetchedMessage && fetchedMessage[prop] !== null) {
+          this.message[prop] = fetchedMessage[prop];
         }
-      });
+      }
     }
+    this.show = this.message.title || this.message.content;
   },
   methods: {
     getMessage: function (url) {