From 61f7d376d283363ddc652978f35891d1a4adf55f Mon Sep 17 00:00:00 2001 From: willyb321 Date: Wed, 13 Jun 2018 06:46:12 +1000 Subject: [PATCH] store number of rolls per grade --- src/app/components/ModalShoppingList.jsx | 10 +++----- src/app/stores/Persist.js | 30 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/app/components/ModalShoppingList.jsx b/src/app/components/ModalShoppingList.jsx index 2f98e02a..f9f0a9d3 100644 --- a/src/app/components/ModalShoppingList.jsx +++ b/src/app/components/ModalShoppingList.jsx @@ -2,6 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import TranslatedComponent from './TranslatedComponent'; import ShortenUrl from '../utils/ShortenUrl'; +import Persist from '../stores/Persist'; /** * Permalink modal @@ -21,13 +22,7 @@ export default class ModalShoppingList extends TranslatedComponent { this.state = { matsList: '', mats: {}, - matsPerGrade: { - 1: 2, - 2: 2, - 3: 3, - 4: 4, - 5: 6 - } + matsPerGrade: Persist.getRolls() }; } @@ -89,6 +84,7 @@ export default class ModalShoppingList extends TranslatedComponent { let newState = this.state.matsPerGrade; newState[grade] = parseInt(e.target.value); this.setState({ matsPerGrade: newState }); + Persist.setRolls(newState); this.renderMats(); } diff --git a/src/app/stores/Persist.js b/src/app/stores/Persist.js index e1ea7b82..74418318 100644 --- a/src/app/stores/Persist.js +++ b/src/app/stores/Persist.js @@ -13,6 +13,7 @@ const LS_KEY_STATE = 'state'; const LS_KEY_SIZE_RATIO = 'sizeRatio'; const LS_KEY_TOOLTIPS = 'tooltips'; const LS_KEY_MODULE_RESISTANCES = 'moduleResistances'; +const LS_KEY_ROLLS = 'matsPerGrade'; let LS; @@ -84,6 +85,7 @@ export class Persist extends EventEmitter { } let moduleResistances = _get(LS_KEY_MODULE_RESISTANCES); + let matsPerGrade = _get(LS_KEY_ROLLS); let tips = _get(LS_KEY_TOOLTIPS); let insurance = _getString(LS_KEY_INSURANCE); let shipDiscount = _get(LS_KEY_SHIP_DISCOUNT); @@ -102,6 +104,13 @@ export class Persist extends EventEmitter { this.outfittingTab = _getString(LS_KEY_OUTFITTING_TAB); this.state = _get(LS_KEY_STATE); this.sizeRatio = _get(LS_KEY_SIZE_RATIO) || 1; + this.matsPerGrade = matsPerGrade || { + 1: 2, + 2: 2, + 3: 4, + 4: 4, + 5: 10 + }; this.tooltipsEnabled = tips === null ? true : tips; this.moduleResistancesEnabled = moduleResistances === null ? true : moduleResistances; @@ -152,6 +161,10 @@ export class Persist extends EventEmitter { this.moduleResistancesEnabled = !!newValue && newValue.toLowerCase() == 'true'; this.emit('moduleresistances', this.moduleResistancesEnabled); break; + case LS_KEY_ROLLS: + this.matsPerGrade = JSON.parse(newValue); + this.emit('matsPerGrade', this.matsPerGrade); + break; } } catch (e) { // On JSON.Parse Error - don't sync or do anything @@ -457,6 +470,23 @@ export class Persist extends EventEmitter { return this.moduleDiscount; } + /** + * Get the saved ship discount + * @param {Object} matsPerGrade # of rolls per grade + */ + setRolls(matsPerGrade) { + this.matsPerGrade = matsPerGrade; + _put(LS_KEY_ROLLS, this.matsPerGrade); + this.emit('matsPerGrade'); + } + /** + * Get the saved Mats per grade + * @return {Object} # of rolls per grade + */ + getRolls() { + return this.matsPerGrade; + } + /** * Persist selected cost tab * @param {number} tabName Cost tab name