Skip to content

Commit

Permalink
Detect if site has been added to Favorites (#1538)
Browse files Browse the repository at this point in the history
* Detect if site has been added to Favorites

Previously we were `Alert`ing after attempting to `addBookmark`.

Instead, we remove the option from the menu entirely.

closes: #1511

* Rename isFavorite -> isBookmark
  • Loading branch information
rickycodes authored May 6, 2020
1 parent 9b13054 commit 94228fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
29 changes: 16 additions & 13 deletions app/components/Views/BrowserTab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1167,11 +1167,6 @@ export class BrowserTab extends PureComponent {

addBookmark = () => {
this.toggleOptionsIfNeeded();
// Check it doesn't exist already
if (this.props.bookmarks.filter(i => i.url === this.state.inputValue).length) {
Alert.alert(strings('browser.error'), strings('browser.bookmark_already_exists'));
return false;
}
this.checkForPageMeta(() =>
this.props.navigation.push('AddBookmarkView', {
title: this.state.currentPageTitle || '',
Expand Down Expand Up @@ -1498,14 +1493,16 @@ export class BrowserTab extends PureComponent {
{strings('browser.reload')}
</Text>
</Button>
<Button onPress={this.addBookmark} style={styles.option}>
<View style={styles.optionIconWrapper}>
<Icon name="star" size={16} style={styles.optionIcon} />
</View>
<Text style={styles.optionText} numberOfLines={1}>
{strings('browser.add_to_favorites')}
</Text>
</Button>
{!this.isBookmark() && (
<Button onPress={this.addBookmark} style={styles.option}>
<View style={styles.optionIconWrapper}>
<Icon name="star" size={16} style={styles.optionIcon} />
</View>
<Text style={styles.optionText} numberOfLines={1}>
{strings('browser.add_to_favorites')}
</Text>
</Button>
)}
<Button onPress={this.share} style={styles.option}>
<View style={styles.optionIconWrapper}>
<Icon name="share" size={15} style={styles.optionIcon} />
Expand Down Expand Up @@ -1865,6 +1862,12 @@ export class BrowserTab extends PureComponent {
return activeTab === id;
};

isBookmark = () => {
const { bookmarks, navigation } = this.props;
const currentUrl = navigation.getParam('url', null);
return bookmarks.some(({ url }) => url === currentUrl);
};

isHomepage = (url = null) => {
const currentPage = url || this.state.inputValue;
const { host: currentHost, pathname: currentPathname } = getUrlObj(currentPage);
Expand Down
1 change: 0 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,6 @@
"bookmark": "Bookmark",
"add_to_favorites": "Add to Favorites",
"error": "Ooops!",
"bookmark_already_exists": "You already bookmarked this url",
"cancel": "Cancel",
"go_back": "Go back",
"go_forward": "Go forward",
Expand Down
1 change: 0 additions & 1 deletion locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@
"bookmark": "Marcar",
"add_to_favorites": "Agregar a favorites",
"error": "Ooops!",
"bookmark_already_exists": "Ya agregaste esta url a tus favoritos",
"cancel": "Cancelar",
"go_back": "Atrás",
"go_forward": "Avanzar",
Expand Down

0 comments on commit 94228fa

Please sign in to comment.