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:
Benjamin Elo
2019-07-29 04:20:45 -07:00
committed by Facebook Github Bot
parent 292efb0bb3
commit fc28b904a0
3 changed files with 57 additions and 5 deletions

View File

@@ -14,7 +14,11 @@ import {
Timeline,
ScrollableFlexColumn,
} from './components';
import {readBookmarksFromDB, writeBookmarkToDB} from './util/indexedDB';
import {
removeBookmark,
readBookmarksFromDB,
writeBookmarkToDB,
} from './util/indexedDB';
import type {
State,
@@ -97,8 +101,19 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
this.setState({bookmarks: newMapRef});
};
removeBookmark = (uri: string) => {
removeBookmark(uri);
const newMapRef = this.state.bookmarks;
newMapRef.delete(uri);
this.setState({bookmarks: newMapRef});
};
render() {
const {bookmarks, shouldShowSaveBookmarkDialog} = this.state;
const {
bookmarks,
saveBookmarkURI,
shouldShowSaveBookmarkDialog,
} = this.state;
const {navigationEvents} = this.props.persistedState;
return (
<ScrollableFlexColumn>
@@ -116,9 +131,13 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
<BookmarksSidebar bookmarks={bookmarks} onNavigate={this.navigateTo} />
<SaveBookmarkDialog
shouldShow={shouldShowSaveBookmarkDialog}
uri={this.state.saveBookmarkURI}
uri={saveBookmarkURI}
onHide={() => this.setState({shouldShowSaveBookmarkDialog: false})}
edit={
saveBookmarkURI != null ? bookmarks.has(saveBookmarkURI) : false
}
onSubmit={this.addBookmark}
onRemove={this.removeBookmark}
/>
</ScrollableFlexColumn>
);