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,28 +15,31 @@ 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>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
const _renderListItem = ({ item, index }) => (
|
||||||
<FlatList
|
|
||||||
data={data}
|
|
||||||
keyExtractor={(item, index) => index.toString()}
|
|
||||||
renderItem={({ item, index }) => (
|
|
||||||
<View style={[styles.communityWrapper, index % 2 !== 0 && styles.itemWrapperGray]}>
|
<View style={[styles.communityWrapper, index % 2 !== 0 && styles.itemWrapperGray]}>
|
||||||
<View style={{ flex: 3, flexDirection: 'row', alignItems: 'center' }}>
|
<View style={{ flex: 3, flexDirection: 'row', alignItems: 'center' }}>
|
||||||
<TouchableOpacity onPress={() => handleOnPress(item[0])}>
|
<TouchableOpacity onPress={() => handleOnPress(item[0])}>
|
||||||
@ -73,8 +83,15 @@ const SubscribedCommunitiesListView = ({
|
|||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
)}
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FlatList
|
||||||
|
data={data}
|
||||||
|
keyExtractor={(item, index) => index.toString()}
|
||||||
|
renderItem={_renderListItem}
|
||||||
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