fix muting, unfollow and profile action loader

This commit is contained in:
feruz 2020-01-17 06:48:36 +02:00
parent c9d6d843f7
commit 816a265e8b
4 changed files with 56 additions and 25 deletions

View File

@ -56,7 +56,7 @@ class ProfileSummaryView extends PureComponent {
// This funciton should have switch case but now only has one option therefor // This funciton should have switch case but now only has one option therefor
// temporarily I created with if statments // temporarily I created with if statments
if (index === '0' && handleMuteUnmuteUser) { if (index === 0 && handleMuteUnmuteUser) {
handleMuteUnmuteUser(!isMuted); handleMuteUnmuteUser(!isMuted);
} }
}; };
@ -201,18 +201,14 @@ class ProfileSummaryView extends PureComponent {
style={[styles.insetIconStyle]} style={[styles.insetIconStyle]}
onPress={() => handleOnFavoritePress(isFavorite)} onPress={() => handleOnFavoritePress(isFavorite)}
/> />
{isProfileLoading ? ( <IconButton
<ActivityIndicator style={styles.activityIndicator} /> backgroundColor="transparent"
) : ( color="#c1c5c7"
<IconButton iconType="MaterialCommunityIcons"
backgroundColor="transparent" name={followButtonIcon}
color="#c1c5c7" onPress={() => handleFollowUnfollowUser(!isFollowing)}
iconType="MaterialCommunityIcons" size={20}
name={followButtonIcon} />
onPress={() => handleFollowUnfollowUser(!isFollowing)}
size={20}
/>
)}
{isProfileLoading ? ( {isProfileLoading ? (
<ActivityIndicator style={styles.activityIndicator} /> <ActivityIndicator style={styles.activityIndicator} />
) : ( ) : (

View File

@ -282,6 +282,12 @@
"permission_text": "Please, go to phone Settings and change eSteem app permissions.", "permission_text": "Please, go to phone Settings and change eSteem app permissions.",
"success_rebloged": "Reblogged!", "success_rebloged": "Reblogged!",
"already_rebloged": "You have already reblogged!", "already_rebloged": "You have already reblogged!",
"success_favorite": "Favorite added!",
"success_unfavorite": "Favorite removed!",
"success_follow": "Follow success!",
"success_mute": "Mute success!",
"success_unmute": "Unmute success!",
"success_unfollow": "Unfollow success!",
"warning": "Warning", "warning": "Warning",
"invalid_pincode": "Invalid PIN code, please check and try again.", "invalid_pincode": "Invalid PIN code, please check and try again.",
"remove_alert": "Are you sure you want to remove?", "remove_alert": "Are you sure you want to remove?",

View File

@ -4,6 +4,7 @@ import { connect } from 'react-redux';
import { withNavigation } from 'react-navigation'; import { withNavigation } from 'react-navigation';
import { get, has, unionBy } from 'lodash'; import { get, has, unionBy } from 'lodash';
import { Alert } from 'react-native'; import { Alert } from 'react-native';
import { injectIntl } from 'react-intl';
// Providers // Providers
import { import {
@ -23,6 +24,7 @@ import { getIsFavorite, addFavorite, removeFavorite } from '../providers/esteem/
// Utilitites // Utilitites
import { getRcPower, getVotingPower } from '../utils/manaBar'; import { getRcPower, getVotingPower } from '../utils/manaBar';
import { toastNotification } from '../redux/actions/uiAction';
// Constants // Constants
import { default as ROUTES } from '../constants/routeNames'; import { default as ROUTES } from '../constants/routeNames';
@ -101,7 +103,7 @@ class ProfileContainer extends Component {
_handleFollowUnfollowUser = async isFollowAction => { _handleFollowUnfollowUser = async isFollowAction => {
const { isFollowing, username } = this.state; const { isFollowing, username } = this.state;
const { currentAccount, pinCode } = this.props; const { currentAccount, pinCode, dispatch, intl } = this.props;
const follower = get(currentAccount, 'name', ''); const follower = get(currentAccount, 'name', '');
const following = username; const following = username;
@ -122,6 +124,13 @@ class ProfileContainer extends Component {
following, following,
}) })
.then(() => { .then(() => {
dispatch(
toastNotification(
intl.formatMessage({
id: isFollowing ? 'alert.success_unfollow' : 'alert.success_follow',
}),
),
);
this._profileActionDone(); this._profileActionDone();
}) })
.catch(err => { .catch(err => {
@ -129,11 +138,7 @@ class ProfileContainer extends Component {
}); });
}; };
_handleMuteUnmuteUser = isMuteAction => { _handleMuteUnmuteUser = async isMuteAction => {
this.setState({
isProfileLoading: true,
});
if (isMuteAction) { if (isMuteAction) {
this._muteUser(); this._muteUser();
} else { } else {
@ -143,15 +148,26 @@ class ProfileContainer extends Component {
_muteUser = () => { _muteUser = () => {
const { username } = this.state; const { username } = this.state;
const { currentAccount, pinCode } = this.props; const { currentAccount, pinCode, dispatch, intl } = this.props;
const follower = currentAccount.name; const follower = currentAccount.name;
const following = username; const following = username;
this.setState({
isProfileLoading: true,
});
ignoreUser(currentAccount, pinCode, { ignoreUser(currentAccount, pinCode, {
follower, follower,
following, following,
}) })
.then(() => { .then(() => {
dispatch(
toastNotification(
intl.formatMessage({
id: 'alert.success_mute',
}),
),
);
this._profileActionDone(); this._profileActionDone();
}) })
.catch(err => { .catch(err => {
@ -161,7 +177,9 @@ class ProfileContainer extends Component {
_profileActionDone = (error = null) => { _profileActionDone = (error = null) => {
const { username } = this.state; const { username } = this.state;
this.setState({
isProfileLoading: false,
});
if (error) { if (error) {
this.setState( this.setState(
{ {
@ -255,10 +273,14 @@ class ProfileContainer extends Component {
}; };
_handleOnFavoritePress = (isFavorite = false) => { _handleOnFavoritePress = (isFavorite = false) => {
const { currentAccount } = this.props; const { currentAccount, dispatch, intl } = this.props;
const { username } = this.state; const { username } = this.state;
let favoriteAction; let favoriteAction;
this.setState({
isProfileLoading: true,
});
if (isFavorite) { if (isFavorite) {
favoriteAction = removeFavorite; favoriteAction = removeFavorite;
} else { } else {
@ -266,7 +288,14 @@ class ProfileContainer extends Component {
} }
favoriteAction(currentAccount.name, username).then(() => { favoriteAction(currentAccount.name, username).then(() => {
this.setState({ isFavorite: !isFavorite }); dispatch(
toastNotification(
intl.formatMessage({
id: isFavorite ? 'alert.success_unfavorite' : 'alert.success_favorite',
}),
),
);
this.setState({ isFavorite: !isFavorite, isProfileLoading: false });
}); });
}; };
@ -404,5 +433,5 @@ const mapStateToProps = state => ({
isHideImage: state.ui.hidePostsThumbnails, isHideImage: state.ui.hidePostsThumbnails,
}); });
export default connect(mapStateToProps)(withNavigation(ProfileContainer)); export default connect(mapStateToProps)(injectIntl(withNavigation(ProfileContainer)));
/* eslint-enable */ /* eslint-enable */

View File

@ -831,7 +831,7 @@ export const unfollowUser = async (currentAccount, pin, data) => {
{ {
follower: `${data.follower}`, follower: `${data.follower}`,
following: `${data.following}`, following: `${data.following}`,
what: [''], what: [],
}, },
]), ]),
required_auths: [], required_auths: [],