created bookmarks feature

This commit is contained in:
u-e 2019-01-23 18:00:26 +03:00
parent 2398cf7830
commit 1d0fa0f613
8 changed files with 93 additions and 23 deletions

View File

@ -17,6 +17,7 @@ const UserListItem = ({
handleOnPress,
handleOnLongPress,
isClickable,
text,
}) => (
<TouchableOpacity
onLongPress={() => handleOnLongPress && handleOnLongPress()}
@ -27,7 +28,7 @@ const UserListItem = ({
{itemIndex && <Text style={styles.itemIndex}>{itemIndex}</Text>}
<UserAvatar noAction={userCanPress} style={styles.avatar} username={username} />
<View style={styles.userDescription}>
<Text style={styles.name}>{username}</Text>
<Text style={styles.name}>{text || username}</Text>
{description && <Text style={styles.date}>{description}</Text>}
</View>
{isHasRightItem && (

View File

@ -7,8 +7,7 @@ import { injectIntl } from 'react-intl';
// Services and Actions
import { reblog } from '../../../providers/steem/dsteem';
// Middleware
import { addBookmark } from '../../../providers/esteem/esteem';
// Constants
import OPTIONS from '../../../constants/options/post';
@ -59,6 +58,10 @@ class PostDropdownContainer extends PureComponent {
}, 500);
break;
case '4':
this._addToBookmarks();
break;
default:
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 = () => {
const {
currentAccount, content, isLoggedIn, pinCode, intl,

View File

@ -112,7 +112,7 @@ class PostBody extends PureComponent {
}
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') {

View File

@ -158,7 +158,9 @@
"load_error": "Could not load bookmarks",
"empty_list": "Nothing here",
"deleted": "Bookmark removed",
"search": "Search in bookmarks"
"search": "Search in bookmarks",
"added": "Added to bookmars",
"add": "Add to bookmarks"
},
"favorites": {
"title": "Favorites",
@ -184,7 +186,8 @@
"copy": "copy link",
"reblog": "reblog",
"reply": "reply",
"share": "share"
"share": "share",
"bookmarks": "added to bookmarks"
},
"deep_link": {
"no_existing_user": "No existing user",

View File

@ -1 +1 @@
export default ['copy', 'reblog', 'reply', 'share'];
export default ['copy', 'reblog', 'reply', 'share', 'bookmarks'];

View File

@ -89,7 +89,7 @@ export const getBookmarks = username => api.get(`/bookmarks/${username}`).then(r
* @params id
* @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

View File

@ -4,7 +4,7 @@ import { Alert } from 'react-native';
import { injectIntl } from 'react-intl';
// Services and Actions
import { getFavorites, removeFavorite } from '../../../providers/esteem/esteem';
import { getFavorites, removeFavorite, getBookmarks, removeBookmark } from '../../../providers/esteem/esteem';
// Constants
import ROUTES from '../../../constants/routeNames';
@ -39,6 +39,7 @@ class DraftsContainer extends Component {
_fetchData = () => {
this._getFavorites();
this._getBookmarks();
};
_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) => {
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) => {
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) => {
const dateA = new Date(a.created).getTime();
const dateB = new Date(b.created).getTime();
@ -100,7 +142,9 @@ class DraftsContainer extends Component {
favorites={favorites}
bookmarks={bookmarks}
removeFavorite={this._removeFavorite}
removeBookmark={this._removeBoomark}
handleOnFavoritePress={this._handleOnFavoritePress}
handleOnBookarkPress={this._handleOnBookarkPress}
/>
);
}

View File

@ -26,25 +26,30 @@ class BookmarksScreen extends Component {
constructor(props) {
super(props);
this.state = {
selectedUsername: null,
selectedItemId: null,
activeTab: 0,
};
}
// Component Life Cycles
// Component Functions
_renderItem = (item, index) => {
const { handleOnFavoritePress } = this.props;
_renderItem = (item, index, itemType) => {
const { handleOnFavoritePress, handleOnBookarkPress } = this.props;
const isFavorites = itemType === 'favorites';
const text = isFavorites ? item.account : `${item.author}/${item.permlink}`;
return (
<UserListItem
handleOnLongPress={() => this._handleLongPress(item.account)}
handleOnPress={() => handleOnFavoritePress(item.account)}
handleOnLongPress={() => this._handleLongPress(isFavorites ? item.account : item._id)}
handleOnPress={() => (isFavorites
? handleOnFavoritePress(item.account)
: handleOnBookarkPress(item.permlink, item.author))
}
index={index}
isClickable
username={item.account}
rightText="bok"
subRightText="bok"
text={text}
username={item.author}
/>
);
};
@ -71,7 +76,7 @@ class BookmarksScreen extends Component {
data={data}
keyExtractor={item => item._id}
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) => {
this.setState({ selectedUsername }, () => {
_handleLongPress = (selectedItemId) => {
this.setState({ selectedItemId }, () => {
this.ActionSheet.show();
});
};
render() {
const {
favorites, bookmarks, intl, removeFavorite,
favorites, bookmarks, intl, removeFavorite, removeBookmark,
} = this.props;
const { selectedUsername } = this.state;
const { selectedItemId, activeTab } = this.state;
return (
<View style={globalStyles.container}>
@ -100,6 +105,7 @@ class BookmarksScreen extends Component {
/>
<ScrollableTabView
onChangeTab={(event) => this.setState({ activeTab: event.i })}
style={globalStyles.tabView}
renderTabBar={() => (
<TabBar
@ -137,7 +143,9 @@ class BookmarksScreen extends Component {
cancelButtonIndex={1}
destructiveButtonIndex={0}
onPress={(index) => {
if (index === 0) removeFavorite(selectedUsername);
if (index === 0) {
activeTab === 0 ? removeBookmark(selectedItemId) : removeFavorite(selectedItemId);
}
}}
/>
</View>