From 4745f19f07f3bc12496aa272b76d633322fc7bb8 Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Thu, 16 Sep 2021 12:59:41 +0500 Subject: [PATCH] support for favourite button action --- .../children/actionPanel.tsx | 1 - .../children/quickProfileContent.tsx | 47 +++++++++++++++---- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/components/organisms/quickProfileModal/children/actionPanel.tsx b/src/components/organisms/quickProfileModal/children/actionPanel.tsx index d0e593f6a..44a6fbc00 100644 --- a/src/components/organisms/quickProfileModal/children/actionPanel.tsx +++ b/src/components/organisms/quickProfileModal/children/actionPanel.tsx @@ -28,7 +28,6 @@ export const ActionPanel = ({isFollowing, isFavourite, onFavouritePress, onFollo name={'heart'} size={20} color={EStyleSheet.value(isFavourite?'$primaryRed':'$primaryBlack')} - disabled={isFavourite} onPress={onFavouritePress} /> diff --git a/src/components/organisms/quickProfileModal/children/quickProfileContent.tsx b/src/components/organisms/quickProfileModal/children/quickProfileContent.tsx index a1e6cbad8..25816e630 100644 --- a/src/components/organisms/quickProfileModal/children/quickProfileContent.tsx +++ b/src/components/organisms/quickProfileModal/children/quickProfileContent.tsx @@ -3,7 +3,7 @@ import { useIntl } from 'react-intl' import { View, Text, ActivityIndicator, Alert } from 'react-native' import { ProfileStats, StatsData } from './profileStats' 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 { getRcPower, getVotingPower } from '../../../../utils/manaBar' import styles from './quickProfileStyles' @@ -108,7 +108,7 @@ export const QuickProfileContent = ({ }; - const _handleFollowUser = async () => { + const _onFollowPress = async () => { try{ const follower = currentAccountName const following = username; @@ -136,17 +136,46 @@ export const QuickProfileContent = ({ Alert.alert(intl.formatMessage({id:'alert.fail'}), err.message) } } + + 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 - const _onFollowPress = () => { - _handleFollowUser() - } - - const _onFavouritePress = () => { - - } const _openFullProfile = () => { let params = {