fix flip of post list (#6234)

This commit is contained in:
Elias Nahum 2022-05-05 14:09:30 -04:00 committed by GitHub
parent 9d3c7c9496
commit 58719c82dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 12 deletions

View file

@ -11,7 +11,6 @@ import {Screens} from '@constants';
import {useServerUrl} from '@context/server';
import {debounce} from '@helpers/api/general';
import {useIsTablet} from '@hooks/device';
import {sortPostsByNewest} from '@utils/post';
import Intro from './intro';
@ -44,7 +43,7 @@ const ChannelPostList = ({
const onEndReached = useCallback(debounce(async () => {
if (!fetchingPosts.current && canLoadPosts.current && posts.length) {
fetchingPosts.current = true;
const lastPost = sortPostsByNewest(posts)[0];
const lastPost = posts[posts.length - 1];
const result = await fetchPostsBefore(serverUrl, channelId, lastPost.id);
canLoadPosts.current = ((result as ProcessedPosts).posts?.length ?? 1) > 0;
fetchingPosts.current = false;

View file

@ -62,16 +62,6 @@ export function shouldIgnorePost(post: Post): boolean {
return Post.IGNORE_POST_TYPES.includes(post.type);
}
export const sortPostsByNewest = (posts: PostModel[]) => {
return posts.sort((a, b) => {
if (a.createAt > b.createAt) {
return 1;
}
return -1;
});
};
export const processPostsFetched = (data: PostResponse) => {
const order = data.order;
const posts = Object.values(data.posts) as Post[];