Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect if site has been added to Favorites #1538

Merged
merged 2 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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