From 5467cff84a44f6ce255e6e48a9cc798f39953823 Mon Sep 17 00:00:00 2001 From: Florian Pichler Date: Wed, 15 Dec 2021 13:02:33 +0100 Subject: [PATCH] Refactor: Handle notififaction htmlContent in backing class --- addon/components/notification-message.js | 13 ++++++++++++- addon/templates/components/notification-message.hbs | 6 +----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/addon/components/notification-message.js b/addon/components/notification-message.js index d398c4eb..e00969d0 100644 --- a/addon/components/notification-message.js +++ b/addon/components/notification-message.js @@ -1,6 +1,6 @@ /* eslint-disable ember/no-classic-components, ember/no-computed-properties-in-native-classes */ import Component from '@ember/component'; -import { htmlSafe } from '@ember/template'; +import { htmlSafe, isHTMLSafe } from '@ember/template'; import { action, computed, set } from '@ember/object'; import { inject as service } from '@ember/service'; @@ -15,6 +15,17 @@ export default class NotificationMessage extends Component { paused = false; + @computed('notification.{htmlContent,message}') + get message() { + const { htmlContent, message } = this.notification; + + if (isHTMLSafe(message) || !htmlContent) { + return message; + } + + return htmlSafe(message); + } + @computed('notification.dismiss') get dismissClass() { return !this.notification.dismiss ? 'c-notification--in' : ''; diff --git a/addon/templates/components/notification-message.hbs b/addon/templates/components/notification-message.hbs index e5f7a36a..c7d4371a 100644 --- a/addon/templates/components/notification-message.hbs +++ b/addon/templates/components/notification-message.hbs @@ -23,11 +23,7 @@ {{/if}}
- {{#if @notification.htmlContent}} - {{{@notification.message}}} - {{else}} - {{@notification.message}} - {{/if}} + {{this.message}}