community join fix, improve description height

This commit is contained in:
feruz 2022-02-23 23:06:42 +02:00
parent 3ec42e91b9
commit 6c82ec997a
3 changed files with 46 additions and 12 deletions

View File

@ -1,9 +1,12 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import { withNavigation } from 'react-navigation'; import { withNavigation } from 'react-navigation';
import get from 'lodash/get'; 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'; import ROUTES from '../../../constants/routeNames';
@ -11,6 +14,8 @@ const CommunityContainer = ({ children, navigation, currentAccount, pinCode, isL
const [data, setData] = useState(null); const [data, setData] = useState(null);
const [isSubscribed, setIsSubscribed] = useState(false); const [isSubscribed, setIsSubscribed] = useState(false);
const tag = get(navigation, 'state.params.tag'); const tag = get(navigation, 'state.params.tag');
const dispatch = useDispatch();
const intl = useIntl();
useEffect(() => { useEffect(() => {
getCommunity(tag) getCommunity(tag)
@ -39,17 +44,38 @@ const CommunityContainer = ({ children, navigation, currentAccount, pinCode, isL
const _handleSubscribeButtonPress = () => { const _handleSubscribeButtonPress = () => {
const _data = { const _data = {
isSubscribed: !isSubscribed, isSubscribed: isSubscribed,
communityId: data.name, communityId: data.name,
}; };
const screen = 'communitiesScreenDiscoverTab';
let subscribeAction;
let successToastText = '';
let failToastText = '';
subscribeCommunity(currentAccount, pinCode, _data) if (!_data.isSubscribed) {
.then((result) => { subscribeAction = subscribeCommunity;
setIsSubscribed(!isSubscribed);
}) successToastText = intl.formatMessage({
.catch((e) => { id: 'alert.success_subscribe',
console.log(e);
}); });
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 = () => { const _handleNewPostButtonPress = () => {

View File

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { View, Text } from 'react-native'; import { View, Text, ScrollView } from 'react-native';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
// Components // Components
@ -60,7 +60,9 @@ const CommunityScreen = ({ navigation }) => {
defaultTitle="" defaultTitle=""
> >
<View style={styles.collapsibleCard}> <View style={styles.collapsibleCard}>
<Text style={styles.description}>{data.description}</Text> <ScrollView style={styles.descriptionContainer}>
<Text style={styles.description}>{data.description}</Text>
</ScrollView>
<View style={styles.separator} /> <View style={styles.separator} />
<Text style={styles.stats}> <Text style={styles.stats}>
{`${data.subscribers} ${intl.formatMessage({ {`${data.subscribers} ${intl.formatMessage({

View File

@ -38,6 +38,9 @@ export default EStyleSheet.create({
marginTop: 5, marginTop: 5,
color: '$primaryBlack', color: '$primaryBlack',
}, },
descriptionContainer: {
maxHeight: 250,
},
separator: { separator: {
width: 100, width: 100,
alignSelf: 'center', alignSelf: 'center',
@ -54,7 +57,10 @@ export default EStyleSheet.create({
borderWidth: 1, borderWidth: 1,
borderColor: '$primaryBlue', borderColor: '$primaryBlue',
}, },
collapsibleCard: { alignItems: 'center', marginBottom: 20 }, collapsibleCard: {
alignItems: 'center',
marginBottom: 20,
},
subscribeButtonText: { subscribeButtonText: {
color: '$primaryBlue', color: '$primaryBlue',
}, },