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:
committed by
Facebook Github Bot
parent
bd1fc342c8
commit
108c49f572
@@ -9,7 +9,10 @@ import {Button, styled} from 'flipper';
|
|||||||
import {connect} from 'react-redux';
|
import {connect} from 'react-redux';
|
||||||
import React, {Component} from 'react';
|
import React, {Component} from 'react';
|
||||||
import {State as Store} from '../reducers';
|
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 {PersistedState as NavPluginState} from '../plugins/navigation/types';
|
||||||
import BaseDevice from '../devices/BaseDevice';
|
import BaseDevice from '../devices/BaseDevice';
|
||||||
import {State as PluginState} from 'src/reducers/pluginStates';
|
import {State as PluginState} from 'src/reducers/pluginStates';
|
||||||
@@ -32,7 +35,7 @@ type DispatchFromProps = {};
|
|||||||
|
|
||||||
type Bookmark = {
|
type Bookmark = {
|
||||||
uri: string;
|
uri: string;
|
||||||
commonName: string;
|
commonName: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DropdownButton = styled(Button)({
|
const DropdownButton = styled(Button)({
|
||||||
@@ -103,11 +106,8 @@ class LocationsButton extends Component<Props, State> {
|
|||||||
render() {
|
render() {
|
||||||
const {currentURI} = this.props;
|
const {currentURI} = this.props;
|
||||||
const {bookmarks} = this.state;
|
const {bookmarks} = this.state;
|
||||||
return (
|
|
||||||
<DropdownButton
|
const dropdown: any[] = [
|
||||||
onMouseDown={this.updateBookmarks}
|
|
||||||
compact={true}
|
|
||||||
dropdown={[
|
|
||||||
{
|
{
|
||||||
label: 'Bookmarks',
|
label: 'Bookmarks',
|
||||||
enabled: false,
|
enabled: false,
|
||||||
@@ -119,12 +119,35 @@ class LocationsButton extends Component<Props, State> {
|
|||||||
},
|
},
|
||||||
accelerator: i < 9 ? `CmdOrCtrl+${i + 1}` : undefined,
|
accelerator: i < 9 ? `CmdOrCtrl+${i + 1}` : undefined,
|
||||||
label: shortenText(
|
label: shortenText(
|
||||||
bookmark.commonName + ' - ' + bookmark.uri,
|
(bookmark.commonName ? bookmark.commonName + ' - ' : '') +
|
||||||
|
bookmark.uri,
|
||||||
100,
|
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={dropdown}>
|
||||||
{(currentURI && shortenText(currentURI)) || '(none)'}
|
{(currentURI && shortenText(currentURI)) || '(none)'}
|
||||||
</DropdownButton>
|
</DropdownButton>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -147,8 +147,7 @@ export default class extends FlipperPlugin<State, any, PersistedState> {
|
|||||||
addBookmark = (bookmark: Bookmark) => {
|
addBookmark = (bookmark: Bookmark) => {
|
||||||
const newBookmark = {
|
const newBookmark = {
|
||||||
uri: bookmark.uri,
|
uri: bookmark.uri,
|
||||||
commonName:
|
commonName: bookmark.commonName,
|
||||||
bookmark.commonName.length > 0 ? bookmark.commonName : bookmark.uri,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
writeBookmarkToDB(newBookmark);
|
writeBookmarkToDB(newBookmark);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export type NavigationEvent = {
|
|||||||
|
|
||||||
export type Bookmark = {
|
export type Bookmark = {
|
||||||
uri: URI;
|
uri: URI;
|
||||||
commonName: string;
|
commonName: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AutoCompleteProvider = {
|
export type AutoCompleteProvider = {
|
||||||
|
|||||||
Reference in New Issue
Block a user