From f50144b15d8a88733b945dbec94950d1dacca9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Tue, 18 Apr 2023 18:17:55 +0200 Subject: [PATCH] Fix channels showing empty (#7291) * Fix channels showing empty * Update interface --- app/client/rest/posts.ts | 4 ++-- app/screens/channel/channel_post_list/channel_post_list.tsx | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/client/rest/posts.ts b/app/client/rest/posts.ts index ce3943205..945570828 100644 --- a/app/client/rest/posts.ts +++ b/app/client/rest/posts.ts @@ -16,7 +16,7 @@ export interface ClientPostsMix { getPostThread: (postId: string, options: FetchPaginatedThreadOptions) => Promise; getPosts: (channelId: string, page?: number, perPage?: number, collapsedThreads?: boolean, collapsedThreadsExtended?: boolean) => Promise; getPostsSince: (channelId: string, since: number, collapsedThreads?: boolean, collapsedThreadsExtended?: boolean) => Promise; - getPostsBefore: (channelId: string, postId: string, page?: number, perPage?: number, collapsedThreads?: boolean, collapsedThreadsExtended?: boolean) => Promise; + getPostsBefore: (channelId: string, postId?: string, page?: number, perPage?: number, collapsedThreads?: boolean, collapsedThreadsExtended?: boolean) => Promise; getPostsAfter: (channelId: string, postId: string, page?: number, perPage?: number, collapsedThreads?: boolean, collapsedThreadsExtended?: boolean) => Promise; getFileInfosForPost: (postId: string) => Promise; getSavedPosts: (userId: string, channelId?: string, teamId?: string, page?: number, perPage?: number) => Promise; @@ -111,7 +111,7 @@ const ClientPosts = >(superclass: TBase) = ); }; - getPostsBefore = async (channelId: string, postId: string, page = 0, perPage = PER_PAGE_DEFAULT, collapsedThreads = false, collapsedThreadsExtended = false) => { + getPostsBefore = async (channelId: string, postId = '', page = 0, perPage = PER_PAGE_DEFAULT, collapsedThreads = false, collapsedThreadsExtended = false) => { this.analytics?.trackAPI('api_posts_get_before', {channel_id: channelId}); return this.doFetch( diff --git a/app/screens/channel/channel_post_list/channel_post_list.tsx b/app/screens/channel/channel_post_list/channel_post_list.tsx index edea06b52..26918f9c8 100644 --- a/app/screens/channel/channel_post_list/channel_post_list.tsx +++ b/app/screens/channel/channel_post_list/channel_post_list.tsx @@ -55,14 +55,14 @@ const ChannelPostList = ({ }, [isCRTEnabled, posts, channelId, serverUrl, appState === 'active']); const onEndReached = useCallback(debounce(async () => { - if (!fetchingPosts.current && canLoadPosts.current && posts.length) { + if (!fetchingPosts.current && canLoadPosts.current) { fetchingPosts.current = true; const lastPost = posts[posts.length - 1]; - const result = await fetchPostsBefore(serverUrl, channelId, lastPost.id); + const result = await fetchPostsBefore(serverUrl, channelId, lastPost?.id || ''); fetchingPosts.current = false; canLoadPosts.current = false; if (!('error' in result)) { - canLoadPosts.current = (result.posts?.length ?? 1) > 0; + canLoadPosts.current = (result.posts?.length ?? 0) > 0; } } }, 500), [channelId, posts]);