Fixed issue where the location bar wouldn't be updated if there are multiple connected clients

Summary: The location bar doesn't update if there are multiple connected client, if the client we are interested wasn't the first one. The cause of that is that the location bar picked the state of the *first* navigation plugin found, rather than the navigation plugin connected to the selected device and client

Reviewed By: jknoxville

Differential Revision: D19554293

fbshipit-source-id: 46f2a66aa6ba07b510f1f615943eeb6ef8d52622
This commit is contained in:
Michel Weststrate
2020-01-27 04:02:24 -08:00
committed by Facebook Github Bot
parent e9ff9addc6
commit cedb9617c4

View File

@@ -19,6 +19,7 @@ import {PersistedState as NavPluginState} from '../plugins/navigation/types';
import BaseDevice from '../devices/BaseDevice';
import {State as PluginState} from 'src/reducers/pluginStates';
import {platform} from 'os';
import {getPluginKey} from '../utils/pluginUtils';
type State = {
bookmarks: Array<Bookmark>;
@@ -153,10 +154,12 @@ class LocationsButton extends Component<Props, State> {
}
}
const mapStateFromPluginStatesToProps = (pluginStates: PluginState) => {
const pluginKey = Object.keys(pluginStates).find(key =>
/#Navigation$/.test(key),
);
const mapStateFromPluginStatesToProps = (
pluginStates: PluginState,
selectedDevice: BaseDevice | null,
selectedApp: string | null,
) => {
const pluginKey = getPluginKey(selectedApp, selectedDevice, 'Navigation');
let currentURI: string | undefined;
if (pluginKey) {
const navPluginState = pluginStates[pluginKey] as
@@ -170,8 +173,12 @@ const mapStateFromPluginStatesToProps = (pluginStates: PluginState) => {
};
export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
({connections: {selectedDevice}, pluginStates}) => ({
({connections: {selectedDevice, selectedApp}, pluginStates}) => ({
selectedDevice,
...mapStateFromPluginStatesToProps(pluginStates),
...mapStateFromPluginStatesToProps(
pluginStates,
selectedDevice,
selectedApp,
),
}),
)(LocationsButton);