Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Expensify.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, {Component} from 'react';
import {View} from 'react-native';
import get from 'lodash.get';

// import {Beforeunload} from 'react-beforeunload';
import SignInPage from './page/SignInPage';
Expand Down Expand Up @@ -30,7 +29,7 @@ class Expensify extends Component {

this.state = {
loading: true,
authenticated: false,
authToken: '',
};
}

Expand All @@ -39,9 +38,9 @@ class Expensify extends Component {
// redirect to the signin page if we do not have one. Otherwise when the app inits
// we will fall through to the homepage and the user will see a brief flash of the main
// app experience.
Ion.get(IONKEYS.SESSION)
.then((response) => {
this.setState({loading: false, authenticated: Boolean(get(response, 'authToken', false))});
Ion.get(IONKEYS.SESSION, 'authToken', '')
.then((authToken) => {
this.setState({loading: false, authToken});
});
}

Expand All @@ -63,7 +62,7 @@ class Expensify extends Component {

// We can only have a redirectTo if this is not the initial render so if we have one we'll
// always navigate to it. If we are not authenticated by this point then we'll force navigate to sign in.
const redirectTo = this.state.redirectTo || (!this.state.authenticated && '/signin');
const redirectTo = this.state.redirectTo || (!this.state.authToken && '/signin');

return (

Expand Down
16 changes: 8 additions & 8 deletions src/components/WithIon.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
import React from 'react';
import _ from 'underscore';
import get from 'lodash.get';
import has from 'lodash.has';
import lodashGet from 'lodash.get';
import lodashHas from 'lodash.has';
import Ion from '../lib/Ion';

/**
Expand Down Expand Up @@ -52,9 +52,9 @@ export default function (mapIonToState) {
// If any of the mappings use data from the props, then when the props change, all the
// connections need to be reconnected with the new props
_.each(mapIonToState, (mapping, propertyName) => {
if (has(mapping, 'pathForProps')) {
const prevPropsData = get(prevProps, mapping.pathForProps);
const currentPropsData = get(this.props, mapping.pathForProps);
if (lodashHas(mapping, 'pathForProps')) {
const prevPropsData = lodashGet(prevProps, mapping.pathForProps);
const currentPropsData = lodashGet(this.props, mapping.pathForProps);
if (prevPropsData !== currentPropsData) {
Ion.disconnect(this.activeConnectionIDsWithPropsData[mapping.pathForProps]);
this.connectMappingToIon(mapping, propertyName, this.wrappedComponent);
Expand Down Expand Up @@ -105,7 +105,7 @@ export default function (mapIonToState) {
if (mapping.pathForProps) {
// If there is a path for props data, then the data needs to be pulled out of props and parsed
// into the key
const dataFromProps = get(this.props, mapping.pathForProps);
const dataFromProps = lodashGet(this.props, mapping.pathForProps);
const keyWithPropsData = mapping.key.replace('%DATAFROMPROPS%', dataFromProps);
ionConnectionConfig.key = keyWithPropsData;

Expand All @@ -124,7 +124,7 @@ export default function (mapIonToState) {
// If there is a path for props data, then the data needs to be pulled out of props and parsed
// into the key
if (mapping.pathForProps) {
const dataFromProps = get(this.props, mapping.pathForProps);
const dataFromProps = lodashGet(this.props, mapping.pathForProps);
prefillKey = mapping.prefillWithKey.replace('%DATAFROMPROPS%', dataFromProps);
}

Expand All @@ -138,7 +138,7 @@ export default function (mapIonToState) {
const paramsForLoaderFunction = _.map(mapping.loaderParams, (loaderParam) => {
// Some params might com from the props data
if (loaderParam === '%DATAFROMPROPS%') {
return get(this.props, mapping.pathForProps);
return lodashGet(this.props, mapping.pathForProps);
}
return loaderParam;
});
Expand Down
6 changes: 3 additions & 3 deletions src/lib/actions/ActionsReport.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import moment from 'moment';
import _ from 'underscore';
import get from 'lodash.get';
import lodashGet from 'lodash.get';
import Ion from '../Ion';
import {queueRequest} from '../Network';
import IONKEYS from '../../IONKEYS';
Expand Down Expand Up @@ -110,7 +110,7 @@ function fetchAll() {
return promiseAllSettled(reportFetchPromises)
.then(data => fetchedReports = _.compact(_.map(data, (promiseResult) => {
// Grab the report from the promise result which stores it in the `value` key
const report = get(promiseResult, 'value.reports', {});
const report = lodashGet(promiseResult, 'value.reports', {});

// If there is no report found from the promise, return null
// Otherwise, grab the actual report object from the first index in the values array
Expand Down Expand Up @@ -172,7 +172,7 @@ function addHistoryItem(reportID, reportComment) {
.then((values) => {
const reportHistory = values[historyKey];
const email = values[IONKEYS.SESSION].email || '';
const personalDetails = get(values, [IONKEYS.PERSONAL_DETAILS, email], {});
const personalDetails = lodashGet(values, [IONKEYS.PERSONAL_DETAILS, email], {});

// The new sequence number will be one higher than the highest
let highestSequenceNumber = _.chain(reportHistory)
Expand Down