From 84f9a1d8b5210a68d20a36614359e86ea963d3fa Mon Sep 17 00:00:00 2001 From: Benjamin Elo Date: Sun, 28 Jul 2019 12:46:10 -0700 Subject: [PATCH] Added ability to save bookmarks in Nav Plugin Summary: This is a glue commit that glues all the components I've added in the past together. Favouriting a page (i.e. clicking on the star) adds it as a bookmark. There's four main parts to make your rreview easier: 1. Add bookmarks and favouriting to all the components that support it, including their parents. (NavigationInfoBox, SearchBar, Timeline) 2. Persist bookmarks using the indexedDB. (index.js) 3. Add saving to db through the SaveBookmarksDialog 4. Various other changes due to a changed architecture. i.e. moving bookmarks from persistedState to state. Still to come. 1. Removing bookmarks. 2. Pressing enter to save the bookmarks when the SaveBookmarksDialog pops up. 3. Alphabetizing bookmarks? Order seems to jump around. Reviewed By: jknoxville Differential Revision: D16518013 fbshipit-source-id: 2e0cef14123c611db43cca360bc66dc4c05b11ed --- .../__tests__/testNavigationPlugin.node.js | 2 - .../navigation/components/BookmarksSidebar.js | 6 +- .../components/NavigationInfoBox.js | 5 +- .../components/SaveBookmarkDialog.js | 27 +++++++-- .../navigation/components/SearchBar.js | 33 +++++++---- src/plugins/navigation/components/Timeline.js | 12 ++-- src/plugins/navigation/index.js | 59 ++++++++++++++++--- 7 files changed, 107 insertions(+), 37 deletions(-) diff --git a/src/plugins/navigation/__tests__/testNavigationPlugin.node.js b/src/plugins/navigation/__tests__/testNavigationPlugin.node.js index bab2dfcd2..1642dd230 100644 --- a/src/plugins/navigation/__tests__/testNavigationPlugin.node.js +++ b/src/plugins/navigation/__tests__/testNavigationPlugin.node.js @@ -12,14 +12,12 @@ import type {PersistedState} from '../'; function constructPersistedStateMock(): PersistedState { return { - bookmarks: [], navigationEvents: [], }; } function constructPersistedStateMockWithEvents(): PersistedState { return { - bookmarks: [], navigationEvents: [ { uri: 'mock://this_is_a_mock_uri/mock/1', diff --git a/src/plugins/navigation/components/BookmarksSidebar.js b/src/plugins/navigation/components/BookmarksSidebar.js index 7c681871d..791cc93b7 100644 --- a/src/plugins/navigation/components/BookmarksSidebar.js +++ b/src/plugins/navigation/components/BookmarksSidebar.js @@ -11,7 +11,7 @@ import {DetailSidebar, FlexCenter, styled, colors} from 'flipper'; import type {Bookmark} from '../'; type Props = {| - bookmarks: Array, + bookmarks: Map, onNavigate: string => void, |}; @@ -57,11 +57,11 @@ export default (props: Props) => { const {bookmarks, onNavigate} = props; return ( - {bookmarks.length === 0 ? ( + {bookmarks.size === 0 ? ( No Bookmarks ) : ( - {bookmarks.map(bookmark => ( + {[...bookmarks.values()].map(bookmark => (
void, onFavorite: (query: string) => void, @@ -52,7 +53,7 @@ const NavigationInfoBoxContainer = styled('div')({ }); export default (props: Props) => { - const {uri} = props; + const {uri, isBookmarked} = props; if (uri == null) { return ( @@ -65,7 +66,7 @@ export default (props: Props) => {
props.onFavorite(uri)} /> diff --git a/src/plugins/navigation/components/SaveBookmarkDialog.js b/src/plugins/navigation/components/SaveBookmarkDialog.js index 057e328a7..3009d673e 100644 --- a/src/plugins/navigation/components/SaveBookmarkDialog.js +++ b/src/plugins/navigation/components/SaveBookmarkDialog.js @@ -7,12 +7,15 @@ */ import {Button, FlexColumn, Input, Sheet, styled} from 'flipper'; +import {useState} from 'react'; + +import type {Bookmark} from '../'; type Props = {| uri: ?string, shouldShow: boolean, onHide: ?() => void, - onSubmit: ?(uri: string) => void, + onSubmit: Bookmark => void, |}; const Container = styled(FlexColumn)({ @@ -45,6 +48,7 @@ const NameInput = styled(Input)({ export default (props: Props) => { const {shouldShow, onHide, onSubmit, uri} = props; + const [commonName, setCommonName] = useState(''); if (uri == null || !shouldShow) { return null; } else { @@ -54,19 +58,30 @@ export default (props: Props) => { return ( Save to bookmarks... - + setCommonName(event.target.value)} + /> {uri} -