From 6c82ec997ad5f7dc1ce4bb0368b6ce670b6bdb2e Mon Sep 17 00:00:00 2001 From: feruz Date: Wed, 23 Feb 2022 23:06:42 +0200 Subject: [PATCH] community join fix, improve description height --- .../community/container/communityContainer.js | 44 +++++++++++++++---- .../community/screen/communityScreen.js | 6 ++- .../community/screen/communityStyles.js | 8 +++- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/screens/community/container/communityContainer.js b/src/screens/community/container/communityContainer.js index 11fb47e6d..3af8640ff 100644 --- a/src/screens/community/container/communityContainer.js +++ b/src/screens/community/container/communityContainer.js @@ -1,9 +1,12 @@ import { useState, useEffect } from 'react'; import { withNavigation } from 'react-navigation'; import get from 'lodash/get'; -import { connect } from 'react-redux'; +import { connect, useDispatch } from 'react-redux'; +import { useIntl } from 'react-intl'; -import { subscribeCommunity, getCommunity, getSubscriptions } from '../../../providers/hive/dhive'; +import { getCommunity, getSubscriptions } from '../../../providers/hive/dhive'; + +import { subscribeCommunity, leaveCommunity } from '../../../redux/actions/communitiesAction'; import ROUTES from '../../../constants/routeNames'; @@ -11,6 +14,8 @@ const CommunityContainer = ({ children, navigation, currentAccount, pinCode, isL const [data, setData] = useState(null); const [isSubscribed, setIsSubscribed] = useState(false); const tag = get(navigation, 'state.params.tag'); + const dispatch = useDispatch(); + const intl = useIntl(); useEffect(() => { getCommunity(tag) @@ -39,17 +44,38 @@ const CommunityContainer = ({ children, navigation, currentAccount, pinCode, isL const _handleSubscribeButtonPress = () => { const _data = { - isSubscribed: !isSubscribed, + isSubscribed: isSubscribed, communityId: data.name, }; + const screen = 'communitiesScreenDiscoverTab'; + let subscribeAction; + let successToastText = ''; + let failToastText = ''; - subscribeCommunity(currentAccount, pinCode, _data) - .then((result) => { - setIsSubscribed(!isSubscribed); - }) - .catch((e) => { - console.log(e); + if (!_data.isSubscribed) { + subscribeAction = subscribeCommunity; + + successToastText = intl.formatMessage({ + id: 'alert.success_subscribe', }); + failToastText = intl.formatMessage({ + id: 'alert.fail_subscribe', + }); + } else { + subscribeAction = leaveCommunity; + + successToastText = intl.formatMessage({ + id: 'alert.success_leave', + }); + failToastText = intl.formatMessage({ + id: 'alert.fail_leave', + }); + } + + dispatch( + subscribeAction(currentAccount, pinCode, _data, successToastText, failToastText, screen), + ); + setIsSubscribed(!isSubscribed); }; const _handleNewPostButtonPress = () => { diff --git a/src/screens/community/screen/communityScreen.js b/src/screens/community/screen/communityScreen.js index 81f247eed..a9b8a7f14 100644 --- a/src/screens/community/screen/communityScreen.js +++ b/src/screens/community/screen/communityScreen.js @@ -1,5 +1,5 @@ import React from 'react'; -import { View, Text } from 'react-native'; +import { View, Text, ScrollView } from 'react-native'; import { useIntl } from 'react-intl'; // Components @@ -60,7 +60,9 @@ const CommunityScreen = ({ navigation }) => { defaultTitle="" > - {data.description} + + {data.description} + {`${data.subscribers} ${intl.formatMessage({ diff --git a/src/screens/community/screen/communityStyles.js b/src/screens/community/screen/communityStyles.js index 66d3c257e..81d5e7b6b 100644 --- a/src/screens/community/screen/communityStyles.js +++ b/src/screens/community/screen/communityStyles.js @@ -38,6 +38,9 @@ export default EStyleSheet.create({ marginTop: 5, color: '$primaryBlack', }, + descriptionContainer: { + maxHeight: 250, + }, separator: { width: 100, alignSelf: 'center', @@ -54,7 +57,10 @@ export default EStyleSheet.create({ borderWidth: 1, borderColor: '$primaryBlue', }, - collapsibleCard: { alignItems: 'center', marginBottom: 20 }, + collapsibleCard: { + alignItems: 'center', + marginBottom: 20, + }, subscribeButtonText: { color: '$primaryBlue', },