Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Commit

Permalink
Include discounts on comparison page
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmcleod committed Apr 4, 2016
1 parent bb19dc2 commit 72dc73e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/app/pages/ComparisonPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
};

Expand Down Expand Up @@ -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
Expand All @@ -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);
}

/**
Expand All @@ -413,6 +431,7 @@ export default class ComparisonPage extends Page {
*/
componentWillUnmount() {
this.resizeListener.remove();
this.persistListener.remove();
}

/**
Expand Down

0 comments on commit 72dc73e

Please sign in to comment.