support for favourite button action

This commit is contained in:
Nouman Tahir 2021-09-16 12:59:41 +05:00
parent 82f19fe45b
commit 4745f19f07
2 changed files with 38 additions and 10 deletions

View File

@ -28,7 +28,6 @@ export const ActionPanel = ({isFollowing, isFavourite, onFavouritePress, onFollo
name={'heart'} name={'heart'}
size={20} size={20}
color={EStyleSheet.value(isFavourite?'$primaryRed':'$primaryBlack')} color={EStyleSheet.value(isFavourite?'$primaryRed':'$primaryBlack')}
disabled={isFavourite}
onPress={onFavouritePress} onPress={onFavouritePress}
/> />
</View> </View>

View File

@ -3,7 +3,7 @@ import { useIntl } from 'react-intl'
import { View, Text, ActivityIndicator, Alert } from 'react-native' import { View, Text, ActivityIndicator, Alert } from 'react-native'
import { ProfileStats, StatsData } from './profileStats' import { ProfileStats, StatsData } from './profileStats'
import { MainButton, PercentBar } from '../../..' import { MainButton, PercentBar } from '../../..'
import { checkFavorite } from '../../../../providers/ecency/ecency' import { addFavorite, checkFavorite, deleteFavorite } from '../../../../providers/ecency/ecency'
import { followUser, getFollows, getRelationship, getUser, unfollowUser } from '../../../../providers/hive/dhive' import { followUser, getFollows, getRelationship, getUser, unfollowUser } from '../../../../providers/hive/dhive'
import { getRcPower, getVotingPower } from '../../../../utils/manaBar' import { getRcPower, getVotingPower } from '../../../../utils/manaBar'
import styles from './quickProfileStyles' import styles from './quickProfileStyles'
@ -108,7 +108,7 @@ export const QuickProfileContent = ({
}; };
const _handleFollowUser = async () => { const _onFollowPress = async () => {
try{ try{
const follower = currentAccountName const follower = currentAccountName
const following = username; const following = username;
@ -137,16 +137,45 @@ export const QuickProfileContent = ({
} }
} }
const _onFavouritePress = async () => {
try{
setIsLoading(true);
let favoriteAction;
if (isFavourite) {
favoriteAction = deleteFavorite;
} else {
favoriteAction = addFavorite;
}
await favoriteAction(username)
dispatch(
toastNotification(
intl.formatMessage({
id: isFavourite ? 'alert.success_unfavorite' : 'alert.success_favorite',
}),
),
);
setIsFavourite(!isFavourite);
setIsLoading(false);
}
catch(error){
console.warn('Failed to perform favorite action');
setIsLoading(false);
Alert.alert(
intl.formatMessage({
id: 'alert.fail',
}),
error.message || error.toString(),
);
}
}
//UI CALLBACKS //UI CALLBACKS
const _onFollowPress = () => {
_handleFollowUser()
}
const _onFavouritePress = () => {
}
const _openFullProfile = () => { const _openFullProfile = () => {
let params = { let params = {