mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-20 03:42:10 +03:00
handing empty view and pull to refresh in subscribed community tab
This commit is contained in:
parent
8fe151d44d
commit
423eaad521
@ -48,4 +48,9 @@ export default EStyleSheet.create({
|
|||||||
tabbarItem: {
|
tabbarItem: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
},
|
},
|
||||||
|
noContentText: {
|
||||||
|
textAlign: 'center',
|
||||||
|
marginVertical: 32,
|
||||||
|
color: '$primaryBlack',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { View, FlatList, TouchableOpacity, Text, ActivityIndicator } from 'react-native';
|
import {
|
||||||
|
View,
|
||||||
|
FlatList,
|
||||||
|
TouchableOpacity,
|
||||||
|
ActivityIndicator,
|
||||||
|
Text,
|
||||||
|
RefreshControl,
|
||||||
|
} from 'react-native';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
|
|
||||||
import { Tag, UserAvatar } from '../../index';
|
import { Tag, UserAvatar } from '../../index';
|
||||||
@ -8,73 +15,83 @@ import { ListPlaceHolder } from '../../basicUIElements';
|
|||||||
import DEFAULT_IMAGE from '../../../assets/no_image.png';
|
import DEFAULT_IMAGE from '../../../assets/no_image.png';
|
||||||
|
|
||||||
import styles from './subscribedCommunitiesListStyles';
|
import styles from './subscribedCommunitiesListStyles';
|
||||||
|
import globalStyles from '../../../globalStyles';
|
||||||
|
|
||||||
const SubscribedCommunitiesListView = ({
|
const SubscribedCommunitiesListView = ({
|
||||||
data,
|
data,
|
||||||
subscribingCommunities,
|
subscribingCommunities,
|
||||||
handleOnPress,
|
handleOnPress,
|
||||||
handleSubscribeButtonPress,
|
handleSubscribeButtonPress,
|
||||||
|
handleGetSubscriptions,
|
||||||
|
isLoading,
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
const _renderEmptyContent = () => {
|
const _renderEmptyContent = () => {
|
||||||
return (
|
return isLoading ? (
|
||||||
<>
|
<>
|
||||||
<ListPlaceHolder />
|
<ListPlaceHolder />
|
||||||
</>
|
</>
|
||||||
|
) : (
|
||||||
|
<Text style={[globalStyles.subTitle, styles.noContentText]}>
|
||||||
|
{intl.formatMessage({ id: 'empty_screen.nothing_here' })}
|
||||||
|
</Text>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const _renderListItem = ({ item, index }) => (
|
||||||
|
<View style={[styles.communityWrapper, index % 2 !== 0 && styles.itemWrapperGray]}>
|
||||||
|
<View style={{ flex: 3, flexDirection: 'row', alignItems: 'center' }}>
|
||||||
|
<TouchableOpacity onPress={() => handleOnPress(item[0])}>
|
||||||
|
<UserAvatar username={item[0]} defaultSource={DEFAULT_IMAGE} noAction />
|
||||||
|
</TouchableOpacity>
|
||||||
|
<TouchableOpacity onPress={() => handleOnPress(item[0])}>
|
||||||
|
<Text style={styles.community}>{item[1]}</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
<View>
|
||||||
|
{subscribingCommunities.hasOwnProperty(item[0]) &&
|
||||||
|
subscribingCommunities[item[0]].loading ? (
|
||||||
|
<View style={{ width: 65, alignItems: 'center', justifyContent: 'center' }}>
|
||||||
|
<ActivityIndicator />
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
<Tag
|
||||||
|
style={styles.subscribeButton}
|
||||||
|
textStyle={item[4] && styles.subscribeButtonText}
|
||||||
|
value={
|
||||||
|
!item[4]
|
||||||
|
? intl.formatMessage({
|
||||||
|
id: 'search_result.communities.subscribe',
|
||||||
|
})
|
||||||
|
: intl.formatMessage({
|
||||||
|
id: 'search_result.communities.unsubscribe',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
isPin={!item[4]}
|
||||||
|
isFilter
|
||||||
|
onPress={() =>
|
||||||
|
handleSubscribeButtonPress(
|
||||||
|
{
|
||||||
|
isSubscribed: item[4],
|
||||||
|
communityId: item[0],
|
||||||
|
},
|
||||||
|
'communitiesScreenJoinedTab',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FlatList
|
<FlatList
|
||||||
data={data}
|
data={data}
|
||||||
keyExtractor={(item, index) => index.toString()}
|
keyExtractor={(item, index) => index.toString()}
|
||||||
renderItem={({ item, index }) => (
|
renderItem={_renderListItem}
|
||||||
<View style={[styles.communityWrapper, index % 2 !== 0 && styles.itemWrapperGray]}>
|
|
||||||
<View style={{ flex: 3, flexDirection: 'row', alignItems: 'center' }}>
|
|
||||||
<TouchableOpacity onPress={() => handleOnPress(item[0])}>
|
|
||||||
<UserAvatar username={item[0]} defaultSource={DEFAULT_IMAGE} noAction />
|
|
||||||
</TouchableOpacity>
|
|
||||||
<TouchableOpacity onPress={() => handleOnPress(item[0])}>
|
|
||||||
<Text style={styles.community}>{item[1]}</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
</View>
|
|
||||||
<View>
|
|
||||||
{subscribingCommunities.hasOwnProperty(item[0]) &&
|
|
||||||
subscribingCommunities[item[0]].loading ? (
|
|
||||||
<View style={{ width: 65, alignItems: 'center', justifyContent: 'center' }}>
|
|
||||||
<ActivityIndicator />
|
|
||||||
</View>
|
|
||||||
) : (
|
|
||||||
<Tag
|
|
||||||
style={styles.subscribeButton}
|
|
||||||
textStyle={item[4] && styles.subscribeButtonText}
|
|
||||||
value={
|
|
||||||
!item[4]
|
|
||||||
? intl.formatMessage({
|
|
||||||
id: 'search_result.communities.subscribe',
|
|
||||||
})
|
|
||||||
: intl.formatMessage({
|
|
||||||
id: 'search_result.communities.unsubscribe',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
isPin={!item[4]}
|
|
||||||
isFilter
|
|
||||||
onPress={() =>
|
|
||||||
handleSubscribeButtonPress(
|
|
||||||
{
|
|
||||||
isSubscribed: item[4],
|
|
||||||
communityId: item[0],
|
|
||||||
},
|
|
||||||
'communitiesScreenJoinedTab',
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
)}
|
|
||||||
ListEmptyComponent={_renderEmptyContent}
|
ListEmptyComponent={_renderEmptyContent}
|
||||||
|
refreshControl={<RefreshControl refreshing={isLoading} onRefresh={handleGetSubscriptions} />}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -17,6 +17,7 @@ const CommunitiesContainer = ({ children, navigation }) => {
|
|||||||
|
|
||||||
const [discovers, setDiscovers] = useState([]);
|
const [discovers, setDiscovers] = useState([]);
|
||||||
const [subscriptions, setSubscriptions] = useState([]);
|
const [subscriptions, setSubscriptions] = useState([]);
|
||||||
|
const [isSubscriptionsLoading, setIsSubscriptionsLoading] = useState(false);
|
||||||
|
|
||||||
const currentAccount = useSelector((state) => state.account.currentAccount);
|
const currentAccount = useSelector((state) => state.account.currentAccount);
|
||||||
const pinCode = useSelector((state) => state.application.pin);
|
const pinCode = useSelector((state) => state.application.pin);
|
||||||
@ -28,21 +29,7 @@ const CommunitiesContainer = ({ children, navigation }) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getSubscriptions(currentAccount.username).then((subs) => {
|
_getSubscriptions();
|
||||||
subs.forEach((item) => item.push(true));
|
|
||||||
getCommunities('', 50, null, 'rank').then((communities) => {
|
|
||||||
communities.forEach((community) =>
|
|
||||||
Object.assign(community, {
|
|
||||||
isSubscribed: subs.some(
|
|
||||||
(subscribedCommunity) => subscribedCommunity[0] === community.name,
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
setSubscriptions(subs);
|
|
||||||
setDiscovers(shuffle(communities));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -97,6 +84,31 @@ const CommunitiesContainer = ({ children, navigation }) => {
|
|||||||
setSubscriptions(subscribedsData);
|
setSubscriptions(subscribedsData);
|
||||||
}, [subscribingCommunitiesInJoinedTab]);
|
}, [subscribingCommunitiesInJoinedTab]);
|
||||||
|
|
||||||
|
const _getSubscriptions = () => {
|
||||||
|
setIsSubscriptionsLoading(true);
|
||||||
|
getSubscriptions(currentAccount.username)
|
||||||
|
.then((subs) => {
|
||||||
|
setIsSubscriptionsLoading(false);
|
||||||
|
subs.forEach((item) => item.push(true));
|
||||||
|
getCommunities('', 50, null, 'rank').then((communities) => {
|
||||||
|
communities.forEach((community) =>
|
||||||
|
Object.assign(community, {
|
||||||
|
isSubscribed: subs.some(
|
||||||
|
(subscribedCommunity) => subscribedCommunity[0] === community.name,
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
setSubscriptions(subs);
|
||||||
|
setDiscovers(shuffle(communities));
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.warn('Failed to get subscriptions', err);
|
||||||
|
setIsSubscriptionsLoading(false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Component Functions
|
// Component Functions
|
||||||
const _handleOnPress = (name) => {
|
const _handleOnPress = (name) => {
|
||||||
navigation.navigate({
|
navigation.navigate({
|
||||||
@ -146,6 +158,8 @@ const CommunitiesContainer = ({ children, navigation }) => {
|
|||||||
subscribingCommunitiesInJoinedTab,
|
subscribingCommunitiesInJoinedTab,
|
||||||
handleOnPress: _handleOnPress,
|
handleOnPress: _handleOnPress,
|
||||||
handleSubscribeButtonPress: _handleSubscribeButtonPress,
|
handleSubscribeButtonPress: _handleSubscribeButtonPress,
|
||||||
|
handleGetSubscriptions: _getSubscriptions,
|
||||||
|
isSubscriptionsLoading,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -55,6 +55,8 @@ const CommunitiesScreen = ({ navigation, searchValue }) => {
|
|||||||
handleSubscribeButtonPress,
|
handleSubscribeButtonPress,
|
||||||
subscribingCommunitiesInDiscoverTab,
|
subscribingCommunitiesInDiscoverTab,
|
||||||
subscribingCommunitiesInJoinedTab,
|
subscribingCommunitiesInJoinedTab,
|
||||||
|
handleGetSubscriptions,
|
||||||
|
isSubscriptionsLoading,
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
@ -77,6 +79,8 @@ const CommunitiesScreen = ({ navigation, searchValue }) => {
|
|||||||
subscribingCommunities={subscribingCommunitiesInJoinedTab}
|
subscribingCommunities={subscribingCommunitiesInJoinedTab}
|
||||||
handleSubscribeButtonPress={handleSubscribeButtonPress}
|
handleSubscribeButtonPress={handleSubscribeButtonPress}
|
||||||
handleOnPress={handleOnPress}
|
handleOnPress={handleOnPress}
|
||||||
|
handleGetSubscriptions={handleGetSubscriptions}
|
||||||
|
isLoading={isSubscriptionsLoading}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<View
|
<View
|
||||||
|
Loading…
Reference in New Issue
Block a user