Added ability to remove bookmarks
Summary: Here I add the ability to remove bookmarks. If a bookmark already exists, a different dialouge menu appears. Reviewed By: danielbuechele Differential Revision: D16540394 fbshipit-source-id: 5d6737e1efb1a9663519bf17084ef3b55a6ba28e
This commit is contained in:
committed by
Facebook Github Bot
parent
292efb0bb3
commit
fc28b904a0
@@ -13,8 +13,10 @@ import type {Bookmark} from '../flow-types';
|
|||||||
|
|
||||||
type Props = {|
|
type Props = {|
|
||||||
uri: ?string,
|
uri: ?string,
|
||||||
|
edit: boolean,
|
||||||
shouldShow: boolean,
|
shouldShow: boolean,
|
||||||
onHide: ?() => void,
|
onHide: ?() => void,
|
||||||
|
onRemove: string => void,
|
||||||
onSubmit: Bookmark => void,
|
onSubmit: Bookmark => void,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
@@ -47,7 +49,7 @@ const NameInput = styled(Input)({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default (props: Props) => {
|
export default (props: Props) => {
|
||||||
const {shouldShow, onHide, onSubmit, uri} = props;
|
const {edit, shouldShow, onHide, onRemove, onSubmit, uri} = props;
|
||||||
const [commonName, setCommonName] = useState('');
|
const [commonName, setCommonName] = useState('');
|
||||||
if (uri == null || !shouldShow) {
|
if (uri == null || !shouldShow) {
|
||||||
return null;
|
return null;
|
||||||
@@ -57,7 +59,9 @@ export default (props: Props) => {
|
|||||||
{hide => {
|
{hide => {
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<Title>Save to bookmarks...</Title>
|
<Title>
|
||||||
|
{edit ? 'Edit bookmark...' : 'Save to bookmarks...'}
|
||||||
|
</Title>
|
||||||
<NameInput
|
<NameInput
|
||||||
placeholder="Name..."
|
placeholder="Name..."
|
||||||
value={commonName}
|
value={commonName}
|
||||||
@@ -74,6 +78,20 @@ export default (props: Props) => {
|
|||||||
padded>
|
padded>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
|
{edit ? (
|
||||||
|
<Button
|
||||||
|
type="danger"
|
||||||
|
onClick={() => {
|
||||||
|
hide();
|
||||||
|
onRemove(uri);
|
||||||
|
setCommonName('');
|
||||||
|
}}
|
||||||
|
compact
|
||||||
|
padded>
|
||||||
|
Remove
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
type="primary"
|
type="primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
|||||||
@@ -14,7 +14,11 @@ import {
|
|||||||
Timeline,
|
Timeline,
|
||||||
ScrollableFlexColumn,
|
ScrollableFlexColumn,
|
||||||
} from './components';
|
} from './components';
|
||||||
import {readBookmarksFromDB, writeBookmarkToDB} from './util/indexedDB';
|
import {
|
||||||
|
removeBookmark,
|
||||||
|
readBookmarksFromDB,
|
||||||
|
writeBookmarkToDB,
|
||||||
|
} from './util/indexedDB';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
State,
|
State,
|
||||||
@@ -97,8 +101,19 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
|
|||||||
this.setState({bookmarks: newMapRef});
|
this.setState({bookmarks: newMapRef});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
removeBookmark = (uri: string) => {
|
||||||
|
removeBookmark(uri);
|
||||||
|
const newMapRef = this.state.bookmarks;
|
||||||
|
newMapRef.delete(uri);
|
||||||
|
this.setState({bookmarks: newMapRef});
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {bookmarks, shouldShowSaveBookmarkDialog} = this.state;
|
const {
|
||||||
|
bookmarks,
|
||||||
|
saveBookmarkURI,
|
||||||
|
shouldShowSaveBookmarkDialog,
|
||||||
|
} = this.state;
|
||||||
const {navigationEvents} = this.props.persistedState;
|
const {navigationEvents} = this.props.persistedState;
|
||||||
return (
|
return (
|
||||||
<ScrollableFlexColumn>
|
<ScrollableFlexColumn>
|
||||||
@@ -116,9 +131,13 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
|
|||||||
<BookmarksSidebar bookmarks={bookmarks} onNavigate={this.navigateTo} />
|
<BookmarksSidebar bookmarks={bookmarks} onNavigate={this.navigateTo} />
|
||||||
<SaveBookmarkDialog
|
<SaveBookmarkDialog
|
||||||
shouldShow={shouldShowSaveBookmarkDialog}
|
shouldShow={shouldShowSaveBookmarkDialog}
|
||||||
uri={this.state.saveBookmarkURI}
|
uri={saveBookmarkURI}
|
||||||
onHide={() => this.setState({shouldShowSaveBookmarkDialog: false})}
|
onHide={() => this.setState({shouldShowSaveBookmarkDialog: false})}
|
||||||
|
edit={
|
||||||
|
saveBookmarkURI != null ? bookmarks.has(saveBookmarkURI) : false
|
||||||
|
}
|
||||||
onSubmit={this.addBookmark}
|
onSubmit={this.addBookmark}
|
||||||
|
onRemove={this.removeBookmark}
|
||||||
/>
|
/>
|
||||||
</ScrollableFlexColumn>
|
</ScrollableFlexColumn>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -92,3 +92,18 @@ export const readBookmarksFromDB: () => Promise<Map<string, Bookmark>> = () => {
|
|||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const removeBookmark: (uri: string) => Promise<void> = uri => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
openNavigationPluginDB()
|
||||||
|
.then((db: IDBDatabase) => {
|
||||||
|
const bookmarksObjectStore = db
|
||||||
|
.transaction(BOOKMARKS_KEY, 'readwrite')
|
||||||
|
.objectStore(BOOKMARKS_KEY);
|
||||||
|
const request = bookmarksObjectStore.delete(uri);
|
||||||
|
request.onsuccess = resolve;
|
||||||
|
request.onerror = event => reject(event.target.error);
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user