Repository navigation
Redirect to first reportID if the path is empty - #191
Conversation
| return new Promise(resolve => allSettledPromise | ||
| .then(() => { | ||
| fetchedReports = _.sortBy(fetchedReports, 'reportID'); | ||
| resolve(fetchedReports); |
There was a problem hiding this comment.
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.
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.
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
| import Ion from '../../lib/Ion'; | ||
| import {withRouter} from '../../lib/Router'; | ||
|
|
||
| let urlLocationObject = {}; |
There was a problem hiding this comment.
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.
There are a couple of other options that I would suggest (in this order):
- Do the redirect from
componentDidMountwhere 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.jsvia a param passed tofetchAllloader method (there is aloaderParamssetting for Ion binding.
There was a problem hiding this comment.
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.
| return new Promise(resolve => allSettledPromise | ||
| .then(() => { | ||
| fetchedReports = _.sortBy(fetchedReports, 'reportID'); | ||
| resolve(fetchedReports); |
There was a problem hiding this comment.
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.
| import Ion from '../../lib/Ion'; | ||
| import {withRouter} from '../../lib/Router'; | ||
|
|
||
| let urlLocationObject = {}; |
There was a problem hiding this comment.
There are a couple of other options that I would suggest (in this order):
- Do the redirect from
componentDidMountwhere 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.jsvia a param passed tofetchAllloader method (there is aloaderParamssetting for Ion binding.
|
Updated, I couldn't reproduce any race conditions using |
|
FYI - Conflicts |
|
Conflicts resolved |
| 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.
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.
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
Redirect to first reportID if the path is empty
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