mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-19 19:31:54 +03:00
avoid new posts pop for wrong filter
This commit is contained in:
parent
692c3bb526
commit
786827a793
@ -52,6 +52,7 @@ const PostsContainer = ({
|
|||||||
isFeedScreen = false,
|
isFeedScreen = false,
|
||||||
}) => {
|
}) => {
|
||||||
const appState = useRef(AppState.currentState);
|
const appState = useRef(AppState.currentState);
|
||||||
|
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
let _postFetchTimer = null;
|
let _postFetchTimer = null;
|
||||||
@ -71,7 +72,7 @@ const PostsContainer = ({
|
|||||||
const subscribingCommunities = useSelector(
|
const subscribingCommunities = useSelector(
|
||||||
(state) => state.communities.subscribingCommunitiesInFeedScreen,
|
(state) => state.communities.subscribingCommunitiesInFeedScreen,
|
||||||
);
|
);
|
||||||
// const [posts, setPosts] = useState(isConnected ? [] : feedPosts);
|
|
||||||
const [isNoPost, setIsNoPost] = useState(false);
|
const [isNoPost, setIsNoPost] = useState(false);
|
||||||
const [sessionUser, setSessionUser] = useState(username);
|
const [sessionUser, setSessionUser] = useState(username);
|
||||||
const [promotedPosts, setPromotedPosts] = useState([]);
|
const [promotedPosts, setPromotedPosts] = useState([]);
|
||||||
@ -107,7 +108,7 @@ const PostsContainer = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const _scheduleLatestPostsCheck = (firstPost) => {
|
const _scheduleLatestPostsCheck = (firstPost, filter = selectedFilterValue) => {
|
||||||
const refetchTime = __DEV__ ? 5000 : 600000;
|
const refetchTime = __DEV__ ? 5000 : 600000;
|
||||||
if (_postFetchTimer) {
|
if (_postFetchTimer) {
|
||||||
clearTimeout(_postFetchTimer);
|
clearTimeout(_postFetchTimer);
|
||||||
@ -128,7 +129,7 @@ const PostsContainer = ({
|
|||||||
|
|
||||||
_postFetchTimer = setTimeout(() => {
|
_postFetchTimer = setTimeout(() => {
|
||||||
const isLatestPostsCheck = true;
|
const isLatestPostsCheck = true;
|
||||||
_loadPosts(null, isLatestPostsCheck);
|
_loadPosts(filter, isLatestPostsCheck);
|
||||||
}, timeLeft);
|
}, timeLeft);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -200,13 +201,14 @@ const PostsContainer = ({
|
|||||||
//cache latest posts for main tab for returning user
|
//cache latest posts for main tab for returning user
|
||||||
else if (isFeedScreen) {
|
else if (isFeedScreen) {
|
||||||
//schedule refetch of new posts by checking time of current post
|
//schedule refetch of new posts by checking time of current post
|
||||||
_scheduleLatestPostsCheck(nextPosts[0]);
|
_scheduleLatestPostsCheck(nextPosts[0], state.currentFilter);
|
||||||
|
|
||||||
if (filter == (get(currentAccount, 'name', null) == null ? 'hot' : 'friends')) {
|
if (filter == (get(currentAccount, 'name', null) == null ? 'hot' : 'friends')) {
|
||||||
_setInitPosts(nextPosts);
|
_setInitPosts(nextPosts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//update stat
|
||||||
cachedEntry.startAuthor = _posts[_posts.length - 1] && _posts[_posts.length - 1].author;
|
cachedEntry.startAuthor = _posts[_posts.length - 1] && _posts[_posts.length - 1].author;
|
||||||
cachedEntry.startPermlink = _posts[_posts.length - 1] && _posts[_posts.length - 1].permlink;
|
cachedEntry.startPermlink = _posts[_posts.length - 1] && _posts[_posts.length - 1].permlink;
|
||||||
cachedEntry.posts = _posts;
|
cachedEntry.posts = _posts;
|
||||||
@ -251,7 +253,7 @@ const PostsContainer = ({
|
|||||||
_setFeedPosts(data.posts, data.scrollPosition);
|
_setFeedPosts(data.posts, data.scrollPosition);
|
||||||
|
|
||||||
if (filter !== 'feed' && isFeedScreen) {
|
if (filter !== 'feed' && isFeedScreen) {
|
||||||
_scheduleLatestPostsCheck(data.posts[0]);
|
_scheduleLatestPostsCheck(data.posts[0], filter);
|
||||||
setNewPostsPopupPictures(null);
|
setNewPostsPopupPictures(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,7 +268,7 @@ const PostsContainer = ({
|
|||||||
const data = state.cachedData[filter];
|
const data = state.cachedData[filter];
|
||||||
_setFeedPosts(data.posts, data.scrollPosition);
|
_setFeedPosts(data.posts, data.scrollPosition);
|
||||||
if (isFeedScreen) {
|
if (isFeedScreen) {
|
||||||
_scheduleLatestPostsCheck(data.posts[0]);
|
_scheduleLatestPostsCheck(data.posts[0], 'feed');
|
||||||
setNewPostsPopupPictures(null);
|
setNewPostsPopupPictures(null);
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
@ -354,6 +356,7 @@ const PostsContainer = ({
|
|||||||
isLoggedIn && setSelectedFeedSubfilterIndex(selectedFeedSubfilterIndex || 0);
|
isLoggedIn && setSelectedFeedSubfilterIndex(selectedFeedSubfilterIndex || 0);
|
||||||
setIsNoPost(false);
|
setIsNoPost(false);
|
||||||
|
|
||||||
|
setNewPostsPopupPictures(null);
|
||||||
_loadPosts();
|
_loadPosts();
|
||||||
|
|
||||||
if (changeForceLoadPostState) {
|
if (changeForceLoadPostState) {
|
||||||
@ -385,6 +388,7 @@ const PostsContainer = ({
|
|||||||
cacheDispatch({
|
cacheDispatch({
|
||||||
type: 'reset-cur-filter-cache',
|
type: 'reset-cur-filter-cache',
|
||||||
});
|
});
|
||||||
|
setNewPostsPopupPictures(null);
|
||||||
_loadPosts();
|
_loadPosts();
|
||||||
}
|
}
|
||||||
}, [refreshing]);
|
}, [refreshing]);
|
||||||
@ -507,10 +511,15 @@ const PostsContainer = ({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (newPosts.length > 0) {
|
const isRightFilter =
|
||||||
|
cache.currentFilter === 'feed'
|
||||||
|
? cache.currentSubFilter === reducerFilter
|
||||||
|
: cache.currentFilter === reducerFilter;
|
||||||
|
|
||||||
|
if (newPosts.length > 0 && isRightFilter) {
|
||||||
setNewPostsPopupPictures(newPosts.map((post) => get(post, 'avatar', '')));
|
setNewPostsPopupPictures(newPosts.map((post) => get(post, 'avatar', '')));
|
||||||
} else {
|
} else {
|
||||||
_scheduleLatestPostsCheck(posts[0]);
|
_scheduleLatestPostsCheck(posts[0], cache.currentFilter);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -809,7 +818,7 @@ const PostsContainer = ({
|
|||||||
cache.currentFilter !== 'feed' ? cache.currentFilter : cache.currentSubFilter;
|
cache.currentFilter !== 'feed' ? cache.currentFilter : cache.currentSubFilter;
|
||||||
const posts = cache.cachedData[cacheFilter].posts;
|
const posts = cache.cachedData[cacheFilter].posts;
|
||||||
if (posts.length > 0) {
|
if (posts.length > 0) {
|
||||||
_scheduleLatestPostsCheck(posts[0]);
|
_scheduleLatestPostsCheck(posts[0], cache.currentFilter);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user