From e1b0af0f4b29d87839764be95003ad50fa7e42ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Wed, 11 Sep 2019 03:01:18 -0700 Subject: [PATCH] LocationsButton Summary: _typescript_ Reviewed By: jknoxville Differential Revision: D17284485 fbshipit-source-id: 7de710e7302413bc4735f0b0e31770c045a84fe6 --- src/chrome/LocationsButton.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/chrome/LocationsButton.tsx b/src/chrome/LocationsButton.tsx index 43b771a75..9da8e73a6 100644 --- a/src/chrome/LocationsButton.tsx +++ b/src/chrome/LocationsButton.tsx @@ -16,12 +16,14 @@ import {State as PluginState} from 'src/reducers/pluginStates'; type State = { bookmarks: Array; + hasRetrievedBookmarks: boolean; + retreivingBookmarks: boolean; }; type OwnProps = {}; type StateFromProps = { - currentURI: string; + currentURI: string | undefined; selectedDevice: BaseDevice | null | undefined; }; @@ -51,7 +53,7 @@ const shortenText = (text: string, MAX_CHARACTERS = 30): string => { type Props = OwnProps & StateFromProps & DispatchFromProps; class LocationsButton extends Component { - state = { + state: State = { bookmarks: [], hasRetrievedBookmarks: false, retreivingBookmarks: false, @@ -109,10 +111,16 @@ class LocationsButton extends Component { } const mapStateFromPluginStatesToProps = (pluginStates: PluginState) => { - const navPluginState = pluginStates[ - Object.keys(pluginStates).find(key => /#Navigation$/.test(key)) - ] as (NavPluginState | null); - const currentURI = navPluginState && navPluginState.currentURI; + const pluginKey = Object.keys(pluginStates).find(key => + /#Navigation$/.test(key), + ); + let currentURI: string | undefined; + if (pluginKey) { + const navPluginState = pluginStates[pluginKey] as + | NavPluginState + | undefined; + currentURI = navPluginState && navPluginState.currentURI; + } return { currentURI, };