Added LocationsButton when Navigation Plugin is active

Summary:
Here I've added the LocationsButton to the TitleBar in Flipper. This allows the user to navigate to saved bookmarks, or display the current page URI without ever opening the Navigation Plugin (Except to add bookmarks). The challenge of this diff was having a TitleBar child be controlled by a plugin.

The LocationsButton pulls bookmarks straight from the database whenever a mouseDown event is called on the button. (The Electron popup menu does not respond to props changes, so the menu is opened on mouse up and getting the bookmarks from the database occurs on mouse down... This seems to work fine).

The nav plugin on the Android side will now also send a welcome message alerting the app to created a persisted state for the navigation plugin, which shows the button in the TitleBar.

Let me know if I can answer any questions.

Reviewed By: danielbuechele

Differential Revision: D16786330

fbshipit-source-id: afc95348d9b7ec4ee041f42bb4d022f58c6bb969
This commit is contained in:
Benjamin Elo
2019-08-14 05:24:39 -07:00
committed by Facebook Github Bot
parent 0f270c9f48
commit 1ae3b90019
6 changed files with 118 additions and 25 deletions

View File

@@ -44,6 +44,7 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
static defaultPersistedState: PersistedState = {
navigationEvents: [],
bookmarks: new Map<string, Bookmark>(),
currentURI: '',
bookmarksProvider: new DefaultProvider(),
appMatchPatterns: [],
appMatchPatternsProvider: new DefaultProvider(),
@@ -53,7 +54,6 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
shouldShowSaveBookmarkDialog: false,
saveBookmarkURI: null,
shouldShowURIErrorDialog: false,
currentURI: '',
requiredParameters: [],
};
@@ -66,6 +66,8 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
case 'nav_event':
return {
...persistedState,
currentURI:
payload.uri == null ? persistedState.currentURI : payload.uri,
navigationEvents: [
{
uri: payload.uri === undefined ? null : payload.uri,
@@ -110,7 +112,7 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
};
navigateTo = (query: string) => {
this.setState({currentURI: query});
this.props.setPersistedState({currentURI: query});
const requiredParameters = getRequiredParameters(query);
if (requiredParameters.length === 0) {
this.getDevice().then(device => {
@@ -156,7 +158,6 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
render() {
const {
currentURI,
saveBookmarkURI,
shouldShowSaveBookmarkDialog,
shouldShowURIErrorDialog,
@@ -165,6 +166,7 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
const {
bookmarks,
bookmarksProvider,
currentURI,
appMatchPatternsProvider,
navigationEvents,
} = this.props.persistedState;