Bookmark from TitleBar

Summary: Add action to bookmark current location

Reviewed By: passy

Differential Revision: D17419666

fbshipit-source-id: 69e845e802260c150ae2f17649cea05bea1ae4ec
This commit is contained in:
Daniel Büchele
2019-09-17 10:15:33 -07:00
committed by Facebook Github Bot
parent bd1fc342c8
commit 108c49f572
3 changed files with 45 additions and 23 deletions

View File

@@ -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<Props, State> {
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 (
<DropdownButton
onMouseDown={this.updateBookmarks}
compact={true}
dropdown={[
{
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.uri,
100,
),
};
}),
]}>
dropdown={dropdown}>
{(currentURI && shortenText(currentURI)) || '(none)'}
</DropdownButton>
);