Merge pull request #1727 from ecency/bugfix/community

Fixed community bugs
This commit is contained in:
Feruz M 2020-07-19 17:34:00 +03:00 committed by GitHub
commit ea8dbf1a1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 75 additions and 42 deletions

View File

@ -25,6 +25,7 @@ class TagContainer extends PureComponent {
this.state = {
label: props.value,
isCommunity: false,
};
}
// Component Life Cycle Functions
@ -35,6 +36,7 @@ class TagContainer extends PureComponent {
.then((r) => {
this.setState({
label: r,
isCommunity: value !== r,
});
return r;
})
@ -43,12 +45,13 @@ class TagContainer extends PureComponent {
// Component Functions
_handleOnTagPress = () => {
const { navigation, onPress, value } = this.props;
const { isCommunity } = this.state;
if (onPress) {
onPress();
} else {
navigation.navigate({
routeName: ROUTES.SCREENS.TAG_RESULT,
routeName: isCommunity ? ROUTES.SCREENS.COMMUNITY : ROUTES.SCREENS.TAG_RESULT,
params: {
tag: value,
},

View File

@ -8,7 +8,7 @@ import { subscribeCommunity } from '../../../providers/steem/dsteem';
import ROUTES from '../../../constants/routeNames';
const CommunityContainer = ({ children, navigation, currentAccount, pinCode }) => {
const CommunityContainer = ({ children, navigation, currentAccount, pinCode, isLoggedIn }) => {
const [data, setData] = useState(null);
const [isSubscribed, setIsSubscribed] = useState(false);
const tag = get(navigation, 'state.params.tag');
@ -22,8 +22,10 @@ const CommunityContainer = ({ children, navigation, currentAccount, pinCode }) =
useEffect(() => {
if (data) {
getSubscriptions(currentAccount.username).then((result) => {
const _isSubscribed = result.some((item) => item[0] === data.name);
setIsSubscribed(_isSubscribed);
if (result) {
const _isSubscribed = result.some((item) => item[0] === data.name);
setIsSubscribed(_isSubscribed);
}
});
}
}, [data]);
@ -54,7 +56,8 @@ const CommunityContainer = ({ children, navigation, currentAccount, pinCode }) =
data,
handleSubscribeButtonPress: _handleSubscribeButtonPress,
handleNewPostButtonPress: _handleNewPostButtonPress,
isSubscribed: isSubscribed,
isSubscribed,
isLoggedIn,
})
);
};
@ -62,6 +65,7 @@ const CommunityContainer = ({ children, navigation, currentAccount, pinCode }) =
const mapStateToProps = (state) => ({
currentAccount: state.account.currentAccount,
pinCode: state.application.pin,
isLoggedIn: state.application.isLoggedIn,
});
export default connect(mapStateToProps)(withNavigation(CommunityContainer));

View File

@ -31,11 +31,17 @@ const TagResultScreen = ({ navigation }) => {
return (
<CommunityContainer>
{({ data, handleSubscribeButtonPress, handleNewPostButtonPress, isSubscribed }) => (
{({
data,
handleSubscribeButtonPress,
handleNewPostButtonPress,
isSubscribed,
isLoggedIn,
}) => (
<View style={styles.container}>
<Header isReverse hideUser />
{data ? (
<CollapsibleCard title={data.title} isTitleCenter defaultTitle="">
<CollapsibleCard title={data.title} isTitleCenter defaultTitle="" expanded>
<View style={styles.collapsibleCard}>
<Text style={styles.description}>{data.description}</Text>
<View style={styles.separator} />
@ -50,22 +56,24 @@ const TagResultScreen = ({ navigation }) => {
</Text>
<View style={styles.separator} />
<View style={{ flexDirection: 'row' }}>
<Tag
style={styles.subscribeButton}
textStyle={!isSubscribed && styles.subscribeButtonText}
value={
isSubscribed
? intl.formatMessage({
id: 'search_result.communities.subscribe',
})
: intl.formatMessage({
id: 'search_result.communities.unsubscribe',
})
}
isPin={isSubscribed}
isFilter
onPress={handleSubscribeButtonPress}
/>
{isLoggedIn && (
<Tag
style={styles.subscribeButton}
textStyle={isSubscribed && styles.subscribeButtonText}
value={
!isSubscribed
? intl.formatMessage({
id: 'search_result.communities.subscribe',
})
: intl.formatMessage({
id: 'search_result.communities.unsubscribe',
})
}
isPin={!isSubscribed}
isFilter
onPress={handleSubscribeButtonPress}
/>
)}
<Tag
style={styles.subscribeButton}
value={intl.formatMessage({

View File

@ -731,7 +731,7 @@ class EditorContainer extends Component {
uploadedImage,
} = this.state;
const tags = navigation.state.params.tags;
const tags = navigation.state.params && navigation.state.params.tags;
return (
<EditorScreen

View File

@ -7,7 +7,14 @@ import ROUTES from '../../../constants/routeNames';
import { getCommunities, getSubscriptions } from '../../../providers/steem/steem';
import { subscribeCommunity } from '../../../providers/steem/dsteem';
const CommunitiesContainer = ({ children, navigation, searchValue, currentAccount, pinCode }) => {
const CommunitiesContainer = ({
children,
navigation,
searchValue,
currentAccount,
pinCode,
isLoggedIn,
}) => {
const [data, setData] = useState();
const [filterIndex, setFilterIndex] = useState(0);
const [query, setQuery] = useState('');
@ -31,7 +38,9 @@ const CommunitiesContainer = ({ children, navigation, searchValue, currentAccoun
useEffect(() => {
if (data) {
getSubscriptions(currentAccount.username).then((result) => {
setAllSubscriptions(result);
if (result) {
setAllSubscriptions(result);
}
});
}
}, [data]);
@ -64,6 +73,7 @@ const CommunitiesContainer = ({ children, navigation, searchValue, currentAccoun
handleOnVotersDropdownSelect: _handleOnVotersDropdownSelect,
handleOnPress: _handleOnPress,
handleSubscribeButtonPress: _handleSubscribeButtonPress,
isLoggedIn,
})
);
};
@ -71,6 +81,7 @@ const CommunitiesContainer = ({ children, navigation, searchValue, currentAccoun
const mapStateToProps = (state) => ({
currentAccount: state.account.currentAccount,
pinCode: state.application.pin,
isLoggedIn: state.application.isLoggedIn,
});
export default connect(mapStateToProps)(withNavigation(CommunitiesContainer));

View File

@ -21,6 +21,7 @@ const UserListItem = ({
name,
handleSubscribeButtonPress,
isSubscribed,
isLoggedIn,
}) => {
const [subscribed, setSubscribed] = useState(isSubscribed);
const intl = useIntl();
@ -40,22 +41,24 @@ const UserListItem = ({
<View style={styles.content}>
<View style={styles.header}>
<Text style={styles.title}>{title}</Text>
<Tag
style={styles.subscribeButton}
textStyle={!subscribed && styles.subscribeButtonText}
value={
subscribed
? intl.formatMessage({
id: 'search_result.communities.subscribe',
})
: intl.formatMessage({
id: 'search_result.communities.unsubscribe',
})
}
isPin={subscribed}
isFilter
onPress={_handleSubscribeButtonPress}
/>
{isLoggedIn && (
<Tag
style={styles.subscribeButton}
textStyle={subscribed && styles.subscribeButtonText}
value={
!subscribed
? intl.formatMessage({
id: 'search_result.communities.subscribe',
})
: intl.formatMessage({
id: 'search_result.communities.unsubscribe',
})
}
isPin={!subscribed}
isFilter
onPress={_handleSubscribeButtonPress}
/>
)}
</View>
{!!about && <Text style={styles.about}>{about}</Text>}
<View style={styles.separator} />

View File

@ -24,6 +24,7 @@ const CommunitiesScreen = ({ navigation, searchValue }) => {
handleOnVotersDropdownSelect,
handleOnPress,
handleSubscribeButtonPress,
isLoggedIn,
}) => (
<>
<FilterBar
@ -44,6 +45,7 @@ const CommunitiesScreen = ({ navigation, searchValue }) => {
allSubscriptions={allSubscriptions}
handleOnPress={handleOnPress}
handleSubscribeButtonPress={handleSubscribeButtonPress}
isLoggedIn={isLoggedIn}
/>
</>
)}

View File

@ -13,6 +13,7 @@ const VotersDisplayView = ({
handleOnPress,
handleSubscribeButtonPress,
allSubscriptions,
isLoggedIn,
}) => {
const _renderItem = (item, index) => {
const isSubscribed = allSubscriptions.some((sub) => sub[0] === item.name);
@ -32,6 +33,7 @@ const VotersDisplayView = ({
handleOnPress={handleOnPress}
handleSubscribeButtonPress={handleSubscribeButtonPress}
isSubscribed={isSubscribed}
isLoggedIn={isLoggedIn}
/>
);
};