handling logged out user in tabbedPosts, ignoring momentum load calls

This commit is contained in:
Nouman Tahir 2021-04-08 20:16:58 +05:00
parent 004b8b3fb3
commit aa3fce6877
3 changed files with 19 additions and 5 deletions

View File

@ -16,6 +16,8 @@ interface postsListContainerProps extends FlatListProps<any> {
isRefreshing:boolean;
}
let _onEndReachedCalledDuringMomentum = true;
const postsListContainer = ({
promotedPosts,
isFeedScreen,
@ -24,6 +26,7 @@ const postsListContainer = ({
isLoading,
...props
}:postsListContainerProps, ref) => {
const flatListRef = useRef(null);
const [imageHeights, setImageHeights] = useState(new Map<string, number>());
@ -88,7 +91,12 @@ const postsListContainer = ({
return null;
};
const _onEndReached = () => {
if (onLoadPosts && !_onEndReachedCalledDuringMomentum) {
onLoadPosts(false);
_onEndReachedCalledDuringMomentum = true;
}
};
const _renderItem = ({ item, index }:{item:any, index:number}) => {
@ -150,7 +158,10 @@ const postsListContainer = ({
initialNumToRender={3}
windowSize={5}
extraData={imageHeights}
onEndReached={()=>{if(onLoadPosts){onLoadPosts(false)}}}
onEndReached={_onEndReached}
onMomentumScrollBegin={() => {
_onEndReachedCalledDuringMomentum = false;
}}
ListFooterComponent={_renderFooter}
refreshControl={
<RefreshControl

View File

@ -228,7 +228,7 @@ const TabEmptyView = ({
//render related operations
if ((filterKey === 'feed' || filterKey === 'blog') && !isLoggedIn) {
if ((filterKey === 'feed' || filterKey === 'blog' || filterKey === 'friends' || filterKey === 'communities') && !isLoggedIn) {
return (
<NoPost
imageStyle={styles.noImage}

View File

@ -53,9 +53,12 @@ const TabContent = ({
isRefreshing:false,
} as TabMeta)
setSessionUser(username);
_loadPosts();
if(username || (filterKey !== 'friends' && filterKey !== 'communities')){
_loadPosts(true);
_getPromotedPosts();
}
}
const _loadPosts = async (shouldReset:boolean = false) => {