-
-
Notifications
You must be signed in to change notification settings - Fork 676
Decouple Navigation from Redux (Part 1) #4274
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
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
38cb1dd
nav state: Remove several unnecessary fixture details about nav state.
chrisbobbe 3390f00
NavigationService: Add, to start taking nav responsibility from Redux.
chrisbobbe 0e2cc0b
navSelectors: Dissolve `getCanGoBack`.
chrisbobbe da76372
AppWithNavigation: Use `state.nav` instead of `getNav`.
chrisbobbe 3ad1d1b
store: Spell out `getNav` here, before we reimplement `getNav`.
chrisbobbe 026bcdc
navSelectors: Get data from `NavigationService`, not from Redux.
chrisbobbe b0a54c5
navActions: Make `navigateBack` a non-thunk action creator.
chrisbobbe f5ca194
RealmScreen [nfc]: Give `initialRealm` a better name.
chrisbobbe c70947c
navActions [nfc]: Use a params object for `navigateToRealmScreen`.
chrisbobbe cc6e919
navActions: Let `navigateToRealmScreen` take `initial`.
chrisbobbe e2c102d
navActions: Add "reset" actions, to be used in initial navigation.
chrisbobbe 5e409a5
AppNavigator: Set `initialRouteName` to 'loading'.
chrisbobbe a770a34
navReducer: Transplant away `REHYDRATE` logic.
chrisbobbe a34d3ba
navReducer [nfc]: Remove an `initial: true` params hack.
chrisbobbe e41a953
navReducer: Transplant away `LOGOUT` logic.
chrisbobbe c3ffa52
navReducer: Transplant away `ACCOUNT_SWITCH` logic.
chrisbobbe 45c4775
navReducer: Transplant away `LOGIN_SUCCESS` logic.
chrisbobbe f1f041a
navReducer: Use `getNavigationRoutes`.
chrisbobbe 8049976
navReducer: Transplant away `INITIAL_FETCH_COMPLETE` logic.
chrisbobbe 2821bea
fetchActions: Compare all routes to 'main', not just the first.
chrisbobbe 2e049c4
InitialNavigationDispatcher: Clarify and improve `doInitialNavigation`.
chrisbobbe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* @flow strict-local */ | ||
| import type { Node as React$Node } from 'react'; | ||
| import { PureComponent } from 'react'; | ||
|
|
||
| import type { Dispatch, Account } from '../types'; | ||
| import { resetToAccountPicker, resetToRealmScreen, resetToMainTabs } from '../actions'; | ||
| import { connect } from '../react-redux'; | ||
| import { getIsHydrated, hasAuth as getHasAuth, getHaveServerData } from '../selectors'; | ||
|
|
||
| type SelectorProps = $ReadOnly<{| | ||
| isHydrated: boolean, | ||
| hasAuth: boolean, | ||
| accounts: Account[], | ||
| haveServerData: boolean, | ||
| |}>; | ||
|
|
||
| type Props = $ReadOnly<{| | ||
| children: React$Node, | ||
|
|
||
| dispatch: Dispatch, | ||
| ...SelectorProps, | ||
| |}>; | ||
|
|
||
| class InitialNavigationDispatcher extends PureComponent<Props> { | ||
| componentDidMount() { | ||
| if (this.props.isHydrated) { | ||
| this.doInitialNavigation(); | ||
| } | ||
| } | ||
|
|
||
| componentDidUpdate(prevProps) { | ||
| if (!prevProps.isHydrated && this.props.isHydrated) { | ||
| this.doInitialNavigation(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Data has been loaded, so open the app to the right screen. | ||
| * | ||
| * Not to be called before the REHYDRATE action, and not to be | ||
| * called more than once. | ||
| */ | ||
| doInitialNavigation = () => { | ||
| const { hasAuth, accounts, haveServerData, dispatch } = this.props; | ||
|
|
||
| // If the active account is not logged in, bring the user as close | ||
| // as we can to AuthScreen, the place where they can log in. | ||
| if (!hasAuth) { | ||
| if (accounts.length > 1) { | ||
| // We can't guess which account, of multiple, the user wants | ||
| // to use. Let them pick one. | ||
| dispatch(resetToAccountPicker()); | ||
| return; | ||
| } else if (accounts.length === 1) { | ||
| // We already know the realm, so give that to the realm | ||
| // screen. If that screen finds that the realm is valid, it'll | ||
| // send the user along to AuthScreen for that realm right | ||
| // away. If this means you're on the AuthScreen when you don't | ||
| // want to be (i.e., you want to choose a different realm), | ||
| // you can always go back to RealmScreen. | ||
| dispatch(resetToRealmScreen({ initial: true, realm: accounts[0].realm })); | ||
| return; | ||
| } else { | ||
| // Just go to the realm screen and have the user type out the | ||
| // realm. | ||
| dispatch(resetToRealmScreen({ initial: true })); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| // If there's an active, logged-in account but no server data, then behave | ||
| // like `ACCOUNT_SWITCH`: show loading screen. Crucially, `sessionReducer` | ||
| // will have set `needsInitialFetch`, too, so we really will be loading. | ||
| if (!haveServerData) { | ||
| // We're already on the loading screen -- see `initialRouteName` | ||
| // in `AppNavigator`. | ||
| return; | ||
| } | ||
|
|
||
| // Great: we have an active, logged-in account, and server data for it. | ||
| // Show the main UI. | ||
| dispatch(resetToMainTabs()); | ||
| }; | ||
|
|
||
| render() { | ||
| return this.props.children; | ||
| } | ||
| } | ||
|
|
||
| export default connect(state => ({ | ||
| hasAuth: getHasAuth(state), | ||
| accounts: state.accounts, | ||
| haveServerData: getHaveServerData(state), | ||
| isHydrated: getIsHydrated(state), | ||
| }))(InitialNavigationDispatcher); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.