mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-04 07:05:20 +03:00
created bookmarks feature
This commit is contained in:
parent
2398cf7830
commit
1d0fa0f613
@ -17,6 +17,7 @@ const UserListItem = ({
|
|||||||
handleOnPress,
|
handleOnPress,
|
||||||
handleOnLongPress,
|
handleOnLongPress,
|
||||||
isClickable,
|
isClickable,
|
||||||
|
text,
|
||||||
}) => (
|
}) => (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onLongPress={() => handleOnLongPress && handleOnLongPress()}
|
onLongPress={() => handleOnLongPress && handleOnLongPress()}
|
||||||
@ -27,7 +28,7 @@ const UserListItem = ({
|
|||||||
{itemIndex && <Text style={styles.itemIndex}>{itemIndex}</Text>}
|
{itemIndex && <Text style={styles.itemIndex}>{itemIndex}</Text>}
|
||||||
<UserAvatar noAction={userCanPress} style={styles.avatar} username={username} />
|
<UserAvatar noAction={userCanPress} style={styles.avatar} username={username} />
|
||||||
<View style={styles.userDescription}>
|
<View style={styles.userDescription}>
|
||||||
<Text style={styles.name}>{username}</Text>
|
<Text style={styles.name}>{text || username}</Text>
|
||||||
{description && <Text style={styles.date}>{description}</Text>}
|
{description && <Text style={styles.date}>{description}</Text>}
|
||||||
</View>
|
</View>
|
||||||
{isHasRightItem && (
|
{isHasRightItem && (
|
||||||
|
@ -7,8 +7,7 @@ import { injectIntl } from 'react-intl';
|
|||||||
|
|
||||||
// Services and Actions
|
// Services and Actions
|
||||||
import { reblog } from '../../../providers/steem/dsteem';
|
import { reblog } from '../../../providers/steem/dsteem';
|
||||||
|
import { addBookmark } from '../../../providers/esteem/esteem';
|
||||||
// Middleware
|
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import OPTIONS from '../../../constants/options/post';
|
import OPTIONS from '../../../constants/options/post';
|
||||||
@ -59,6 +58,10 @@ class PostDropdownContainer extends PureComponent {
|
|||||||
}, 500);
|
}, 500);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case '4':
|
||||||
|
this._addToBookmarks();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -73,6 +76,17 @@ class PostDropdownContainer extends PureComponent {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_addToBookmarks = () => {
|
||||||
|
const { currentAccount, content, intl } = this.props;
|
||||||
|
addBookmark(currentAccount.name, content.author, content.permlink)
|
||||||
|
.then(() => {
|
||||||
|
Alert.alert(intl.formatMessage({ id: 'bookmarks.added' }));
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
Alert.alert(intl.formatMessage({ id: 'alert.fail' }));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
_reblog = () => {
|
_reblog = () => {
|
||||||
const {
|
const {
|
||||||
currentAccount, content, isLoggedIn, pinCode, intl,
|
currentAccount, content, isLoggedIn, pinCode, intl,
|
||||||
|
@ -112,7 +112,7 @@ class PostBody extends PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_className === 'text-justify') {
|
if (_className === 'text-justify') {
|
||||||
node.attribs.style = 'text-align: justify; text-justify: inter-word; letter-spacing: 1.2px;';
|
node.attribs.style = 'text-align: justify; text-justify: inter-word; letter-spacing: 0px;';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_className === 'phishy') {
|
if (_className === 'phishy') {
|
||||||
|
@ -158,7 +158,9 @@
|
|||||||
"load_error": "Could not load bookmarks",
|
"load_error": "Could not load bookmarks",
|
||||||
"empty_list": "Nothing here",
|
"empty_list": "Nothing here",
|
||||||
"deleted": "Bookmark removed",
|
"deleted": "Bookmark removed",
|
||||||
"search": "Search in bookmarks"
|
"search": "Search in bookmarks",
|
||||||
|
"added": "Added to bookmars",
|
||||||
|
"add": "Add to bookmarks"
|
||||||
},
|
},
|
||||||
"favorites": {
|
"favorites": {
|
||||||
"title": "Favorites",
|
"title": "Favorites",
|
||||||
@ -184,7 +186,8 @@
|
|||||||
"copy": "copy link",
|
"copy": "copy link",
|
||||||
"reblog": "reblog",
|
"reblog": "reblog",
|
||||||
"reply": "reply",
|
"reply": "reply",
|
||||||
"share": "share"
|
"share": "share",
|
||||||
|
"bookmarks": "added to bookmarks"
|
||||||
},
|
},
|
||||||
"deep_link": {
|
"deep_link": {
|
||||||
"no_existing_user": "No existing user",
|
"no_existing_user": "No existing user",
|
||||||
|
@ -1 +1 @@
|
|||||||
export default ['copy', 'reblog', 'reply', 'share'];
|
export default ['copy', 'reblog', 'reply', 'share', 'bookmarks'];
|
||||||
|
@ -89,7 +89,7 @@ export const getBookmarks = username => api.get(`/bookmarks/${username}`).then(r
|
|||||||
* @params id
|
* @params id
|
||||||
* @params current username
|
* @params current username
|
||||||
*/
|
*/
|
||||||
export const removeBookmark = (id, username) => api.delete(`/bookmarks/${username}/${id}`);
|
export const removeBookmark = (username, id) => api.delete(`/bookmarks/${username}/${id}`);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @params current username
|
* @params current username
|
||||||
|
@ -4,7 +4,7 @@ import { Alert } from 'react-native';
|
|||||||
import { injectIntl } from 'react-intl';
|
import { injectIntl } from 'react-intl';
|
||||||
|
|
||||||
// Services and Actions
|
// Services and Actions
|
||||||
import { getFavorites, removeFavorite } from '../../../providers/esteem/esteem';
|
import { getFavorites, removeFavorite, getBookmarks, removeBookmark } from '../../../providers/esteem/esteem';
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import ROUTES from '../../../constants/routeNames';
|
import ROUTES from '../../../constants/routeNames';
|
||||||
@ -39,6 +39,7 @@ class DraftsContainer extends Component {
|
|||||||
|
|
||||||
_fetchData = () => {
|
_fetchData = () => {
|
||||||
this._getFavorites();
|
this._getFavorites();
|
||||||
|
this._getBookmarks();
|
||||||
};
|
};
|
||||||
|
|
||||||
_getFavorites = () => {
|
_getFavorites = () => {
|
||||||
@ -55,6 +56,20 @@ class DraftsContainer extends Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_getBookmarks = () => {
|
||||||
|
const { currentAccount, intl } = this.props;
|
||||||
|
this.setState({ isLoading: true });
|
||||||
|
|
||||||
|
getBookmarks(currentAccount.name)
|
||||||
|
.then((data) => {
|
||||||
|
this.setState({ bookmarks: this._sortData(data), isLoading: false });
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
Alert.alert(intl.formatMessage({ id: 'bookmarks.load_error' }));
|
||||||
|
this.setState({ isLoading: false });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
_removeFavorite = (selectedUsername) => {
|
_removeFavorite = (selectedUsername) => {
|
||||||
const { currentAccount, intl } = this.props;
|
const { currentAccount, intl } = this.props;
|
||||||
|
|
||||||
@ -70,6 +85,21 @@ class DraftsContainer extends Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_removeBoomark = (id) => {
|
||||||
|
const { currentAccount, intl } = this.props;
|
||||||
|
|
||||||
|
removeBookmark(currentAccount.name, id)
|
||||||
|
.then(() => {
|
||||||
|
const { bookmarks } = this.state;
|
||||||
|
const newBookmarks = [...bookmarks].filter(bookmark => bookmark._id !== id);
|
||||||
|
|
||||||
|
this.setState({ bookmarks: this._sortData(newBookmarks) });
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
Alert.alert(intl.formatMessage({ id: 'alert.fail' }));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
_handleOnFavoritePress = (username) => {
|
_handleOnFavoritePress = (username) => {
|
||||||
const { navigation } = this.props;
|
const { navigation } = this.props;
|
||||||
|
|
||||||
@ -82,6 +112,18 @@ class DraftsContainer extends Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_handleOnBookarkPress = (permlink, author) => {
|
||||||
|
const { navigation } = this.props;
|
||||||
|
|
||||||
|
navigation.navigate({
|
||||||
|
routeName: ROUTES.SCREENS.POST,
|
||||||
|
params: {
|
||||||
|
permlink,
|
||||||
|
author,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
_sortData = data => data.sort((a, b) => {
|
_sortData = data => data.sort((a, b) => {
|
||||||
const dateA = new Date(a.created).getTime();
|
const dateA = new Date(a.created).getTime();
|
||||||
const dateB = new Date(b.created).getTime();
|
const dateB = new Date(b.created).getTime();
|
||||||
@ -100,7 +142,9 @@ class DraftsContainer extends Component {
|
|||||||
favorites={favorites}
|
favorites={favorites}
|
||||||
bookmarks={bookmarks}
|
bookmarks={bookmarks}
|
||||||
removeFavorite={this._removeFavorite}
|
removeFavorite={this._removeFavorite}
|
||||||
|
removeBookmark={this._removeBoomark}
|
||||||
handleOnFavoritePress={this._handleOnFavoritePress}
|
handleOnFavoritePress={this._handleOnFavoritePress}
|
||||||
|
handleOnBookarkPress={this._handleOnBookarkPress}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -26,25 +26,30 @@ class BookmarksScreen extends Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
selectedUsername: null,
|
selectedItemId: null,
|
||||||
|
activeTab: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Component Life Cycles
|
// Component Life Cycles
|
||||||
|
|
||||||
// Component Functions
|
// Component Functions
|
||||||
_renderItem = (item, index) => {
|
_renderItem = (item, index, itemType) => {
|
||||||
const { handleOnFavoritePress } = this.props;
|
const { handleOnFavoritePress, handleOnBookarkPress } = this.props;
|
||||||
|
const isFavorites = itemType === 'favorites';
|
||||||
|
const text = isFavorites ? item.account : `${item.author}/${item.permlink}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<UserListItem
|
<UserListItem
|
||||||
handleOnLongPress={() => this._handleLongPress(item.account)}
|
handleOnLongPress={() => this._handleLongPress(isFavorites ? item.account : item._id)}
|
||||||
handleOnPress={() => handleOnFavoritePress(item.account)}
|
handleOnPress={() => (isFavorites
|
||||||
|
? handleOnFavoritePress(item.account)
|
||||||
|
: handleOnBookarkPress(item.permlink, item.author))
|
||||||
|
}
|
||||||
index={index}
|
index={index}
|
||||||
isClickable
|
isClickable
|
||||||
username={item.account}
|
text={text}
|
||||||
rightText="bok"
|
username={item.author}
|
||||||
subRightText="bok"
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -71,7 +76,7 @@ class BookmarksScreen extends Component {
|
|||||||
data={data}
|
data={data}
|
||||||
keyExtractor={item => item._id}
|
keyExtractor={item => item._id}
|
||||||
removeClippedSubviews={false}
|
removeClippedSubviews={false}
|
||||||
renderItem={({ item, index }) => this._renderItem(item, index)}
|
renderItem={({ item, index }) => this._renderItem(item, index, type)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
@ -79,17 +84,17 @@ class BookmarksScreen extends Component {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
_handleLongPress = (selectedUsername) => {
|
_handleLongPress = (selectedItemId) => {
|
||||||
this.setState({ selectedUsername }, () => {
|
this.setState({ selectedItemId }, () => {
|
||||||
this.ActionSheet.show();
|
this.ActionSheet.show();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
favorites, bookmarks, intl, removeFavorite,
|
favorites, bookmarks, intl, removeFavorite, removeBookmark,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const { selectedUsername } = this.state;
|
const { selectedItemId, activeTab } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={globalStyles.container}>
|
<View style={globalStyles.container}>
|
||||||
@ -100,6 +105,7 @@ class BookmarksScreen extends Component {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<ScrollableTabView
|
<ScrollableTabView
|
||||||
|
onChangeTab={(event) => this.setState({ activeTab: event.i })}
|
||||||
style={globalStyles.tabView}
|
style={globalStyles.tabView}
|
||||||
renderTabBar={() => (
|
renderTabBar={() => (
|
||||||
<TabBar
|
<TabBar
|
||||||
@ -137,7 +143,9 @@ class BookmarksScreen extends Component {
|
|||||||
cancelButtonIndex={1}
|
cancelButtonIndex={1}
|
||||||
destructiveButtonIndex={0}
|
destructiveButtonIndex={0}
|
||||||
onPress={(index) => {
|
onPress={(index) => {
|
||||||
if (index === 0) removeFavorite(selectedUsername);
|
if (index === 0) {
|
||||||
|
activeTab === 0 ? removeBookmark(selectedItemId) : removeFavorite(selectedItemId);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
Loading…
Reference in New Issue
Block a user