diff --git a/src/chrome/LocationsButton.tsx b/src/chrome/LocationsButton.tsx index 1e66e4483..e6b3e0f49 100644 --- a/src/chrome/LocationsButton.tsx +++ b/src/chrome/LocationsButton.tsx @@ -9,7 +9,10 @@ import {Button, styled} from 'flipper'; import {connect} from 'react-redux'; import React, {Component} from 'react'; import {State as Store} from '../reducers'; -import {readBookmarksFromDB} from '../plugins/navigation/util/indexedDB'; +import { + readBookmarksFromDB, + writeBookmarkToDB, +} from '../plugins/navigation/util/indexedDB'; import {PersistedState as NavPluginState} from '../plugins/navigation/types'; import BaseDevice from '../devices/BaseDevice'; import {State as PluginState} from 'src/reducers/pluginStates'; @@ -32,7 +35,7 @@ type DispatchFromProps = {}; type Bookmark = { uri: string; - commonName: string; + commonName: string | null; }; const DropdownButton = styled(Button)({ @@ -103,28 +106,48 @@ class LocationsButton extends Component { render() { const {currentURI} = this.props; const {bookmarks} = this.state; + + const dropdown: any[] = [ + { + label: 'Bookmarks', + enabled: false, + }, + ...bookmarks.map((bookmark, i) => { + return { + click: () => { + this.goToLocation(bookmark.uri); + }, + accelerator: i < 9 ? `CmdOrCtrl+${i + 1}` : undefined, + label: shortenText( + (bookmark.commonName ? bookmark.commonName + ' - ' : '') + + bookmark.uri, + 100, + ), + }; + }), + ]; + + if (currentURI) { + dropdown.push( + {type: 'separator'}, + { + label: 'Bookmark Current Location', + click: async () => { + await writeBookmarkToDB({ + uri: currentURI, + commonName: null, + }); + this.updateBookmarks(); + }, + }, + ); + } + return ( { - return { - click: () => { - this.goToLocation(bookmark.uri); - }, - accelerator: i < 9 ? `CmdOrCtrl+${i + 1}` : undefined, - label: shortenText( - bookmark.commonName + ' - ' + bookmark.uri, - 100, - ), - }; - }), - ]}> + dropdown={dropdown}> {(currentURI && shortenText(currentURI)) || '(none)'} ); diff --git a/src/plugins/navigation/index.tsx b/src/plugins/navigation/index.tsx index 7868d55ec..d8c5c5550 100644 --- a/src/plugins/navigation/index.tsx +++ b/src/plugins/navigation/index.tsx @@ -147,8 +147,7 @@ export default class extends FlipperPlugin { addBookmark = (bookmark: Bookmark) => { const newBookmark = { uri: bookmark.uri, - commonName: - bookmark.commonName.length > 0 ? bookmark.commonName : bookmark.uri, + commonName: bookmark.commonName, }; writeBookmarkToDB(newBookmark); diff --git a/src/plugins/navigation/types.tsx b/src/plugins/navigation/types.tsx index 39cbb62a2..8d84f703a 100644 --- a/src/plugins/navigation/types.tsx +++ b/src/plugins/navigation/types.tsx @@ -32,7 +32,7 @@ export type NavigationEvent = { export type Bookmark = { uri: URI; - commonName: string; + commonName: string | null; }; export type AutoCompleteProvider = {