added is favorite to profile

This commit is contained in:
u-e 2019-01-11 12:38:33 +03:00
parent 10ca07dfe4
commit 6c60a60d86
4 changed files with 62 additions and 50 deletions

View File

@ -71,6 +71,7 @@ class ProfileSummaryView extends PureComponent {
hoursVP,
intl,
isDarkTheme,
isFavorite,
isFollowing,
isLoggedIn,
isMuted,
@ -116,7 +117,14 @@ class ProfileSummaryView extends PureComponent {
iconType="MaterialCommunityIcons"
/>
)}
{!!date && <TextWithIcon text={date} iconName="calendar" iconType="MaterialCommunityIcons" iconSize={14} />}
{!!date && (
<TextWithIcon
text={date}
iconName="calendar"
iconType="MaterialCommunityIcons"
iconSize={14}
/>
)}
</View>
<Image
style={styles.longImage}
@ -173,44 +181,40 @@ class ProfileSummaryView extends PureComponent {
</TouchableOpacity>
</Fragment>
</View>
{isLoggedIn && (
{isLoggedIn && !isOwnProfile && (
<View style={styles.rightIcons}>
{!isOwnProfile && (
<Fragment>
<IconButton
backgroundColor="transparent"
name="favorite-border"
iconType="MaterialIcons"
size={20}
style={[styles.insetIconStyle]}
color="#c1c5c7"
/>
{isProfileLoading ? (
<ActivityIndicator style={styles.activityIndicator} />
) : (
<IconButton
backgroundColor="transparent"
name={followButtonIcon}
iconType="MaterialCommunityIcons"
onPress={() => handleFollowUnfollowUser(!isFollowing)}
size={20}
color="#c1c5c7"
/>
)}
{isProfileLoading ? (
<ActivityIndicator style={styles.activityIndicator} />
) : (
<DropdownButton
isHasChildIcon
iconName="more-vert"
options={dropdownOpions}
onSelect={this._handleOnDropdownSelect}
noHighlight
iconStyle={styles.dropdownIconStyle}
dropdownStyle={styles.dropdownStyle}
/>
)}
</Fragment>
<IconButton
backgroundColor="transparent"
color={isFavorite ? '#e63535' : '#c1c5c7'}
iconType="MaterialIcons"
name={isFavorite ? 'favorite' : 'favorite-border'}
size={20}
style={[styles.insetIconStyle]}
/>
{isProfileLoading ? (
<ActivityIndicator style={styles.activityIndicator} />
) : (
<IconButton
backgroundColor="transparent"
color="#c1c5c7"
iconType="MaterialCommunityIcons"
name={followButtonIcon}
onPress={() => handleFollowUnfollowUser(!isFollowing)}
size={20}
/>
)}
{isProfileLoading ? (
<ActivityIndicator style={styles.activityIndicator} />
) : (
<DropdownButton
dropdownStyle={styles.dropdownStyle}
iconName="more-vert"
iconStyle={styles.dropdownIconStyle}
isHasChildIcon
noHighlight
onSelect={this._handleOnDropdownSelect}
options={dropdownOpions}
/>
)}
</View>
)}

View File

@ -100,7 +100,7 @@ export const getFavorites = username => api.get(`/favorites/${username}`).then(r
* @params current username
* @params target username
*/
export const isFavorite = (currentUsername, targetUsername) => api.get(`/isfavorite/${currentUsername}/${targetUsername}`).then(resp => resp.data);
export const getIsFavorite = (targetUsername, currentUsername) => api.get(`/isfavorite/${currentUsername}/${targetUsername}`).then(resp => resp.data);
/**
* @params current username

View File

@ -2,7 +2,7 @@ import React, { Component, Fragment } from 'react';
import { connect } from 'react-redux';
import { withNavigation } from 'react-navigation';
// Utilitites
// Providers
import {
followUser,
unfollowUser,
@ -14,6 +14,9 @@ import {
getIsMuted,
} from '../../../providers/steem/dsteem';
// Esteem providers
import { getIsFavorite } from '../../../providers/esteem/esteem';
// Constants
import { default as ROUTES } from '../../../constants/routeNames';
@ -26,6 +29,7 @@ class ProfileContainer extends Component {
this.state = {
comments: [],
follows: {},
isFavorite: false,
isFollowing: false,
isMuted: false,
isProfileLoading: false,
@ -194,12 +198,15 @@ class ProfileContainer extends Component {
const { isLoggedIn, currentAccount } = this.props;
let _isFollowing;
let _isMuted;
let _isFavorite;
let _follows;
if (isLoggedIn) {
if (isLoggedIn && currentAccount.name !== username) {
_isFollowing = await getIsFollowing(username, currentAccount.name);
_isMuted = _isFollowing ? false : await getIsMuted(username, currentAccount.name);
_isFavorite = getIsFavorite(username, currentAccount.name);
}
await getFollows(username).then((res) => {
@ -210,6 +217,7 @@ class ProfileContainer extends Component {
follows: _follows,
isFollowing: _isFollowing,
isMuted: _isMuted,
isFavorite: _isFavorite,
});
}
};
@ -262,18 +270,19 @@ class ProfileContainer extends Component {
render() {
const {
avatar,
comments,
error,
follows,
isProfileLoading,
isFavorite,
isFollowing,
isMuted,
isProfileLoading,
isReady,
isReverseHeader,
selectedQuickProfile,
user,
username,
avatar,
selectedQuickProfile,
} = this.state;
const { isDarkTheme, isLoggedIn } = this.props;
@ -282,7 +291,6 @@ class ProfileContainer extends Component {
<ProfileScreen
about={user && user.about && user.about.profile}
avatar={avatar}
selectedQuickProfile={selectedQuickProfile}
comments={comments}
error={error}
follows={follows}
@ -290,12 +298,14 @@ class ProfileContainer extends Component {
handleMuteUnmuteUser={this._handleMuteUnmuteUser}
handleOnFollowsPress={this._handleFollowsPress}
isDarkTheme={isDarkTheme}
isFavorite={isFavorite}
isFollowing={isFollowing}
isLoggedIn={isLoggedIn}
isMuted={isMuted}
isProfileLoading={isProfileLoading}
isReady={isReady}
isReverseHeader={isReverseHeader}
selectedQuickProfile={selectedQuickProfile}
selectedUser={user}
username={username}
/>

View File

@ -61,6 +61,7 @@ class ProfileScreen extends PureComponent {
handleOnFollowsPress,
intl,
isDarkTheme,
isFavorite,
isFollowing,
isLoggedIn,
isMuted,
@ -133,6 +134,7 @@ class ProfileScreen extends PureComponent {
intl={intl}
isDarkTheme={isDarkTheme}
isFollowing={isFollowing}
isFavorite={isFavorite}
isLoggedIn={isLoggedIn}
isMuted={isMuted}
isOwnProfile={!isReverseHeader}
@ -195,11 +197,7 @@ class ProfileScreen extends PureComponent {
id: 'profile.wallet',
})}
>
{selectedUser ? (
<Wallet selectedUser={selectedUser} />
) : (
<WalletDetailsPlaceHolder />
)}
{selectedUser ? <Wallet selectedUser={selectedUser} /> : <WalletDetailsPlaceHolder />}
</View>
</ScrollableTabView>
</View>