-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Update ion when clicking links #416
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
|
This is the linting error |
tgolen
left a comment
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 change in this PR fixes the bug, but I don't think it's fixing the source of the bug, just one symptom of it. The bug can be described technically like this:
- User starts out in the app so CURRENT_URL is
/ - APP_REDIRECT_TO is set to
/Band user is taken to/B - User clicks on a link for
/C - CURRENT_URL is set to
/C - APP_REDIRECT_TO is set to
/Bagain, but user stays on/C
This is because the value of APP_REDIRECT_TO in Ion did not trigger a state change to trigger <Redirect>. Setting state to the same value it previously had doesn't trigger a state change in React.
This PR doesn't fix the root cause because this bug will happen on any internal application link.
In order to fix the root problem, I think that any time CURRENT_URL is the same as APP_REDIRECT_TO, then APP_REDIRECT_TO should be cleared out. This way, the next time APP_REDIRECT_TO is set, <Redirect> will be properly triggered. In practice, this is the change in Expensify.js:
recordCurrentRoute({match}) {
Ion.set(IONKEYS.CURRENT_URL, match.url);
if (match.url === this.props.redirectTo) {
Ion.set(IONKEYS.APP_REDIRECT_TO, '');
}
}
There is one other change that I think should happen in this PR to clean up the code. I'm going to be clearing this up in the README so it's more clear moving forward, but the UI part of the app should avoid calling Ion directly in almost all cases. That's what actions are for. I would like to see:
- A new action created
actions/App.js - The
recordCurrentRoute()method moved into that Action - Change
Expensify.jsto interact with the Action
Then we would also:
- Add a method to that action called
redirect() - Change any UI code that is calling
Ion.set(IONKEYS.APP_REDIRECT_TO)to call the action method instead
src/page/home/sidebar/SidebarLink.js
Outdated
| isUnread: false, | ||
| }; | ||
|
|
||
| const onClick = (props) => { |
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.
No need to pass all the props, just pass props.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.
If this method is moved to be inside of render() then there is no need to pass props at all, and it should make the eslint prop error go away.
|
Updated based off your comments. The only one I didn't change to use |
tgolen
left a comment
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.
For the multi-set... just remove APP_REDIRECT_TO from the multiSet() and call redirect() directly. Then, if the multiSet() only has a single key left in it, you can convert it to just a normal set().
src/lib/actions/App.js
Outdated
| * @param {object} match | ||
| * @param {string} currentRedirectTo | ||
| */ | ||
| function recordCurrentRoute(match, currentRedirectTo) { |
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.
This will be more apparent as my refactoring PRs get merged, but there is a better pattern for accessing the currentRedirectTo. Take a look at this code that was just merged to see how an action is properly supposed to access data that is inside of Ion. Let me know if you have any questions on how to implement it.
Currently, only the Report.js action has been refactored to use this, but I am submitting another PR right now to refactor everything else.
Will that mess up anything with the promises? Right now we're returning the |
…ites-updateIonWhenClickingLinks
|
Ah, in my refactoring (you can see the PR here) most of the promise chains are getting removed so that shouldn't be an issue any longer. If you want to wait to replace that |
|
Cool, I'll do that. Updated to connect to Ion correctly! (I was trying to do |
tgolen
left a comment
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.
This looks great! Thanks
Fixes #394
Because links in the sidebar were only changing the route without letting Ion know, we were having issues where chats would not be rendered due to the state not actually updating.
The flow went like this:
Expensifycomponent's state toredirectTo: xxxxExpensifycomponent's state toredirectTo: xxxxagain, but since that's already the state, we don't actually render the chat we want toThis PR makes it so that we always update the state via
Ionto have the correctredirectTo.