From 881a8e5d4c39f9b1be74fa56b1274339ece171d5 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 17 Apr 2019 11:08:11 -0400 Subject: [PATCH] Updates to amazon-product-links --- .../components/amazon-product-links.js.es6 | 57 +++++++++++-------- .../components/amazon-product-links.hbs | 2 +- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/assets/javascripts/discourse/components/amazon-product-links.js.es6 b/assets/javascripts/discourse/components/amazon-product-links.js.es6 index 7c5d424..853a92b 100644 --- a/assets/javascripts/discourse/components/amazon-product-links.js.es6 +++ b/assets/javascripts/discourse/components/amazon-product-links.js.es6 @@ -1,6 +1,9 @@ -var currentUser = Discourse.User.current(); +import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad_component"; +import computed from "ember-addons/ember-computed-decorators"; -var data = { +const currentUser = Discourse.User.current(); + +const data = { "topic-list-top": {}, "topic-above-post-stream": {}, "topic-above-suggested": {}, @@ -119,10 +122,12 @@ if ( ); } -export default Ember.Component.extend({ +export default AdComponent.extend({ classNames: ["amazon-product-links"], - init: function() { + showAd: Ember.computed.and("showToTrustLevel", "showToGroups"), + + init() { let placement = this.get("placement"); this.set("user_input", data[placement]["user_input"]); this.set("amazon_width", data[placement]["amazon_width"]); @@ -133,35 +138,37 @@ export default Ember.Component.extend({ this._super(); }, - adWrapperStyle: function() { - return `width: ${this.get("amazon_width")}px; height: ${this.get( - "amazon_height" - )}px;`.htmlSafe(); - }.property("amazon_width", "amazon_height"), + @computed("amazon_width", "amazon_height") + adWrapperStyle(w, h) { + return `width: ${w}px; height: ${h}px;`.htmlSafe(); + }, - adWrapperStyleMobile: function() { - return `width: ${this.get("mobile_amazon_width")}px; height: ${this.get( - "mobile_amazon_height" - )}px;`.htmlSafe(); - }.property("mobile_amazon_width", "mobile_amazon_height"), + @computed("mobile_amazon_width", "mobile_amazon_height") + adWrapperStyleMobile(w, h) { + return `width: ${w}px; height: ${h}px;`.htmlSafe(); + }, - adTitleStyleMobile: function() { - return `width: ${this.get("mobile_amazon_width")}px;`.htmlSafe(); - }.property("mobile_amazon_width"), + @computed("mobile_amazon_width") + adTitleStyleMobile(w) { + return `width: ${w}px;`.htmlSafe(); + }, - userInput: function() { - return `${this.get("user_input")}`.htmlSafe(); - }.property("user_input"), + @computed("user_input") + userInput(userInput) { + return `${userInput}`.htmlSafe(); + }, - userInputMobile: function() { - return `${this.get("user_input_mobile")}`.htmlSafe(); - }.property("user_input_mobile"), + @computed("user_input_mobile") + userInputMobile(userInput) { + return `${userInput}`.htmlSafe(); + }, - checkTrustLevels: function() { + @computed() + showToTrustLevel() { return !( currentUser && currentUser.get("trust_level") > Discourse.SiteSettings.amazon_through_trust_level ); - }.property("trust_level") + } }); diff --git a/assets/javascripts/discourse/templates/components/amazon-product-links.hbs b/assets/javascripts/discourse/templates/components/amazon-product-links.hbs index 8eb83d8..3516dcf 100644 --- a/assets/javascripts/discourse/templates/components/amazon-product-links.hbs +++ b/assets/javascripts/discourse/templates/components/amazon-product-links.hbs @@ -1,4 +1,4 @@ -{{#if checkTrustLevels}} +{{#if showAd}} {{#if site.mobileView}}