-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Conversation
src/lib/actions/ActionsReport.js
Outdated
return new Promise(resolve => allSettledPromise | ||
.then(() => { | ||
fetchedReports = _.sortBy(fetchedReports, 'reportID'); | ||
resolve(fetchedReports); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We weren't actually returning the reports here, just a list of promise results and undefined values (AsyncStorage.mergeItem resolves null from the Ion.merge call), so I added a resolve to return the newReport data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, I think that was on purpose. We shouldn't be returning data from the actions. The actions should call the API, and then put the data straight into Ion. Any other code that needs access to the data should be subscribing to it from Ion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, that makes sense! I was going to say let's add this to the readme, but looks like you're already on top of it in #205
src/page/HomePage/SidebarView.js
Outdated
|
||
let urlLocationObject = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is the best way to do this, but I had trouble getting the path variable in a way that worked for both web and mobile. On web, grabbing the location from window.location works, but not for mobile (window technically exists, but it doesn't have location or match). I tried a few other methods, but I couldn't access the SidebarView's props inside the loader callback at the bottom of the file which ultimately lead me to this.
If there's a better React-y way to do this, lmk and I'll have a look! I also think using a PubSub pattern would work here, but I'd rather avoid adding it if we don't need to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of other options that I would suggest (in this order):
- Do the redirect from
componentDidMount
where it has access to the props - Get the URL from
Ion.get(IONKEYS.CURRENT_URL)
(will probably have some race conditions because this value is set asynchronously from another component) - Do the redirect from
ActionsReports.js
via a param passed tofetchAll
loader method (there is aloaderParams
setting for Ion binding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main issue I ran into with doing the redirect in componentDidMount
is that it was invoked before the data was fetched, so while I could access the location, I didn't have a reportID to redirect to. Is there another way you were thinking of making that work?
I'll have a look into approach 2 and see if I can get any race conditions to happen.
src/lib/actions/ActionsReport.js
Outdated
return new Promise(resolve => allSettledPromise | ||
.then(() => { | ||
fetchedReports = _.sortBy(fetchedReports, 'reportID'); | ||
resolve(fetchedReports); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, I think that was on purpose. We shouldn't be returning data from the actions. The actions should call the API, and then put the data straight into Ion. Any other code that needs access to the data should be subscribing to it from Ion.
src/page/HomePage/SidebarView.js
Outdated
|
||
let urlLocationObject = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of other options that I would suggest (in this order):
- Do the redirect from
componentDidMount
where it has access to the props - Get the URL from
Ion.get(IONKEYS.CURRENT_URL)
(will probably have some race conditions because this value is set asynchronously from another component) - Do the redirect from
ActionsReports.js
via a param passed tofetchAll
loader method (there is aloaderParams
setting for Ion binding.
Updated, I couldn't reproduce any race conditions using |
FYI - Conflicts |
Conflicts resolved |
src/lib/actions/ActionsReport.js
Outdated
@@ -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'))) |
There was a problem hiding this comment.
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.
.then(() => Ion.set(IONKEYS.REPORT_IDS, _.pluck(fetchedReports, 'reportID'))) | |
.then(() => Ion.set(IONKEYS.REPORT_IDS, _.first(_.pluck(fetchedReports, 'reportID')))) |
There was a problem hiding this comment.
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
…diem-flow Fix per diem nav bug
Fixes #83
Details
This PR ensures that when the app loads, we show the history for the first report in the LHN. This is the same change as in #132, but without the merge issues.
Tests
http://localhost:8080/#/
(no exitTo) and sign back in, confirm that you are redirected to the first chat after it loadsnpm run ios/android
. Confirm that the hamburger menu is not open on load, and a chat automatically loads