From 72dc73e09082f1c3a8a3805821be31485c5a3cfb Mon Sep 17 00:00:00 2001 From: Colin McLeod Date: Mon, 4 Apr 2016 12:31:54 -0700 Subject: [PATCH] Include discounts on comparison page --- src/app/pages/ComparisonPage.jsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/app/pages/ComparisonPage.jsx b/src/app/pages/ComparisonPage.jsx index 897b5655..07913028 100644 --- a/src/app/pages/ComparisonPage.jsx +++ b/src/app/pages/ComparisonPage.jsx @@ -53,6 +53,7 @@ export default class ComparisonPage extends Page { super(props, context); this._sortShips = this._sortShips.bind(this); this._buildsSelected = this._buildsSelected.bind(this); + this._updateDiscounts = this._updateDiscounts.bind(this); this.state = this._initState(context); } @@ -161,6 +162,7 @@ export default class ComparisonPage extends Page { let b = new Ship(id, data.properties, data.slots); // Create a new Ship instance b.buildFrom(code); // Populate components from code b.buildName = name; + b.applyDiscounts(Persist.getShipDiscount(), Persist.getModuleDiscount()); return b; }; @@ -383,6 +385,21 @@ export default class ComparisonPage extends Page { }); } + /** + * Update all ship costs on disount change + */ + _updateDiscounts() { + let shipDiscount = Persist.getShipDiscount(); + let moduleDiscount = Persist.getModuleDiscount(); + let builds = []; + + for (let b of this.state.builds) { + builds.push(b.applyDiscounts(shipDiscount, moduleDiscount)); + } + + this.setState({ builds }); + } + /** * Update state based on context changes * @param {Object} nextProps Incoming/Next properties @@ -399,6 +416,7 @@ export default class ComparisonPage extends Page { */ componentWillMount() { this.resizeListener = this.context.onWindowResize(this._updateDimensions); + this.persistListener = Persist.addListener('discounts', this._updateDiscounts); } /** @@ -413,6 +431,7 @@ export default class ComparisonPage extends Page { */ componentWillUnmount() { this.resizeListener.remove(); + this.persistListener.remove(); } /**