Fix channels showing empty (#7291)

* Fix channels showing empty

* Update interface
This commit is contained in:
Daniel Espino García 2023-04-18 18:17:55 +02:00 committed by GitHub
parent c12f70a3eb
commit f50144b15d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -16,7 +16,7 @@ export interface ClientPostsMix {
getPostThread: (postId: string, options: FetchPaginatedThreadOptions) => Promise<PostResponse>;
getPosts: (channelId: string, page?: number, perPage?: number, collapsedThreads?: boolean, collapsedThreadsExtended?: boolean) => Promise<PostResponse>;
getPostsSince: (channelId: string, since: number, collapsedThreads?: boolean, collapsedThreadsExtended?: boolean) => Promise<PostResponse>;
getPostsBefore: (channelId: string, postId: string, page?: number, perPage?: number, collapsedThreads?: boolean, collapsedThreadsExtended?: boolean) => Promise<PostResponse>;
getPostsBefore: (channelId: string, postId?: string, page?: number, perPage?: number, collapsedThreads?: boolean, collapsedThreadsExtended?: boolean) => Promise<PostResponse>;
getPostsAfter: (channelId: string, postId: string, page?: number, perPage?: number, collapsedThreads?: boolean, collapsedThreadsExtended?: boolean) => Promise<PostResponse>;
getFileInfosForPost: (postId: string) => Promise<FileInfo[]>;
getSavedPosts: (userId: string, channelId?: string, teamId?: string, page?: number, perPage?: number) => Promise<PostResponse>;
@ -111,7 +111,7 @@ const ClientPosts = <TBase extends Constructor<ClientBase>>(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(

View file

@ -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]);