Skip to content

Commit

Permalink
Move getDataTypeFromRouteName into selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Sworup Shakya committed Oct 2, 2019
1 parent 5613915 commit 14aa68b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
16 changes: 14 additions & 2 deletions src/navigation/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@
* mSupply Mobile
* Sustainable Solutions (NZ) Ltd. 2019
*/
const routeList = {
customerRequisitions: 'ResponseRequisition',
supplierRequisitions: 'RequestRequisition',
supplierInvoices: 'SupplierInvoice',
stocktakes: 'Stocktake',
customerInvoices: 'CustomerInvoice',
};

export const getCurrentRouteName = state =>
const getCurrentRouteName = state =>
state.routes[state.index] ? state.routes[state.index].routeName : undefined;

export const getCurrentParams = state =>
const getCurrentParams = state =>
state.routes[state.index] ? state.routes[state.index].params : undefined;

const getDataTypeFromRouteName = props =>
props.routeName in routeList ? routeList[props.routeName] : '';

export { routeList, getCurrentRouteName, getCurrentParams, getDataTypeFromRouteName };
20 changes: 3 additions & 17 deletions src/widgets/NavigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,16 @@ import Icon from 'react-native-vector-icons/FontAwesome';
import { textStyles } from '../globalStyles';
import { BadgeSet } from './BadgeSet';
import { generalStrings } from '../localization';
import { getDataTypeFromRouteName } from '../navigation/selectors';

export class NavigationBar extends React.Component {
state = {
badge: [{ title: '', type: 'unfinalised', Count: 0 }],
};

routeList = {
customerRequisitions: 'ResponseRequisition',
supplierRequisitions: 'RequestRequisition',
supplierInvoices: 'SupplierInvoice',
stocktakes: 'Stocktake',
customerInvoices: 'CustomerInvoice',
};

componentWillReceiveProps(props) {
if (props.routeName in this.routeList) {
const dataType = this.getDataTypeFromRouteName(props);
this.refreshData(dataType);
}
}

// eslint-disable-next-line class-methods-use-this
getDataTypeFromRouteName(props) {
return props.routeName in this.routeList ? this.routeList[props.routeName] : '';
const dataType = getDataTypeFromRouteName(props);
if (dataType !== '') this.refreshData(dataType);
}

refreshData = dataType => {
Expand Down

0 comments on commit 14aa68b

Please sign in to comment.