Skip to content

Redirect to first reportID if the path is empty #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion src/IONKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default {
NETWORK: 'network',
PERSONAL_DETAILS: 'personal_details',
REPORT: 'report',
REPORT_HISTORY: 'report_history',
REPORT_ACTION: 'reportAction',
REPORT_HISTORY: 'report_history',
REPORT_IDS: 'report_ids',
SESSION: 'session',
};
1 change: 1 addition & 0 deletions src/lib/actions/ActionsReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ function fetchAll() {
return _.isEmpty(report) ? null : _.values(report)[0];
})))
.then(() => Ion.get(IONKEYS.SESSION, 'accountID'))
.then(() => Ion.set(IONKEYS.REPORT_IDS, _.pluck(fetchedReports, 'reportID')))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than storing an entire array, how about just storing the first one? Since localStorage has limited space, storing the least amount of data there is a good optimization.

Suggested change
.then(() => Ion.set(IONKEYS.REPORT_IDS, _.pluck(fetchedReports, 'reportID')))
.then(() => Ion.set(IONKEYS.REPORT_IDS, _.first(_.pluck(fetchedReports, 'reportID'))))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me, I'll update the ion key to be FIRST_REPORT_ID so it isn't misleading

.then((accountID) => {
const ionPromises = _.map(fetchedReports, (report) => {
// Store only the absolute bare minimum of data in Ion because space is limited
Expand Down
4 changes: 1 addition & 3 deletions src/page/HomePage/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export default class App extends React.Component {
super(props);

this.state = {
// TODO: Set back to windowSize.width > widthBreakPoint once
// https://github.com/AndrewGable/ReactNativeChat/pull/132 is merged
hamburgerShown: true,
hamburgerShown: windowSize.width > widthBreakPoint,
isHamburgerEnabled: windowSize.width <= widthBreakPoint,
animationTranslateX: new Animated.Value(0),
};
Expand Down
13 changes: 12 additions & 1 deletion src/page/HomePage/SidebarView.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {fetchAll} from '../../lib/actions/ActionsReport';
import SidebarLink from './SidebarLink';
import logo from '../../../assets/images/expensify-logo_reversed.png';
import PageTitleUpdater from '../../lib/PageTitleUpdater';
import Ion from '../../lib/Ion';
import Anchor from '../../components/Anchor';

const propTypes = {
Expand Down Expand Up @@ -123,7 +124,17 @@ export default WithIon({
key: `${IONKEYS.REPORT}_[0-9]+$`,
addAsCollection: true,
collectionID: 'reportID',
loader: fetchAll,
loader: () => fetchAll().then(() => {
Ion.multiGet([IONKEYS.CURRENT_URL, IONKEYS.REPORT_IDS]).then((values) => {
const currentURL = values[IONKEYS.CURRENT_URL] || '';
const reportIDs = values[IONKEYS.REPORT_IDS] || [];

// If we're on the home page, then redirect to the first report ID
if (currentURL === '/' && reportIDs.length) {
Ion.set(IONKEYS.APP_REDIRECT_TO, `/${reportIDs[0]}`);
}
});
}),
},
isOffline: {
key: IONKEYS.NETWORK,
Expand Down