Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cleanup ML types and defaults #2305

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/InfiniteScrollPaginator/InfiniteScroll.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { PropsWithChildren, useEffect, useLayoutEffect, useRef } from 'react';
import type { PaginatorProps } from '../../types/types';
import { deprecationAndReplacementWarning } from '../../utils/deprecationWarning';
import { DEFAULT_LOAD_PAGE_SCROLL_THRESHOLD } from '../../constants/limits';

/**
* Prevents Chrome hangups
Expand Down Expand Up @@ -61,7 +62,7 @@ export const InfiniteScroll = (props: PropsWithChildren<InfiniteScrollProps>) =>
loadMoreNewer,
loadNextPage,
loadPreviousPage,
threshold = 250,
threshold = DEFAULT_LOAD_PAGE_SCROLL_THRESHOLD,
useCapture = false,
...elementProps
} = props;
Expand Down
16 changes: 10 additions & 6 deletions src/components/MessageList/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ import type { MessageProps } from '../Message/types';
import type { StreamMessage } from '../../context/ChannelStateContext';

import type { DefaultStreamChatGenerics } from '../../types/types';
import { DEFAULT_NEXT_CHANNEL_PAGE_SIZE } from '../../constants/limits';
import {
DEFAULT_LOAD_PAGE_SCROLL_THRESHOLD,
DEFAULT_NEXT_CHANNEL_PAGE_SIZE,
} from '../../constants/limits';

type MessageListWithContextProps<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
Expand All @@ -57,7 +60,10 @@ const MessageListWithContext = <
groupStyles,
hideDeletedMessages = false,
hideNewMessageSeparator = false,
internalInfiniteScrollProps,
internalInfiniteScrollProps: {
threshold: loadMoreScrollThreshold = DEFAULT_LOAD_PAGE_SCROLL_THRESHOLD,
...restInternalInfiniteScrollProps
} = {},
messageActions = Object.keys(MESSAGE_ACTIONS),
messages = [],
notifications,
Expand Down Expand Up @@ -93,8 +99,6 @@ const MessageListWithContext = <
UnreadMessagesNotification = DefaultUnreadMessagesNotification,
} = useComponentContext<StreamChatGenerics>('MessageList');

const loadMoreScrollThreshold = internalInfiniteScrollProps?.threshold || 250;

const {
hasNewMessages,
isMessageListScrolledToBottom,
Expand Down Expand Up @@ -240,8 +244,8 @@ const MessageListWithContext = <
}
loadNextPage={loadMoreNewer}
loadPreviousPage={loadMore}
{...props.internalInfiniteScrollProps}
threshold={loadMoreScrollThreshold}
{...restInternalInfiniteScrollProps}
>
<ul className='str-chat__ul' ref={setUlElement}>
{elements}
Expand Down Expand Up @@ -319,7 +323,7 @@ export type MessageListProps<
/** Hides the DateSeparator component when new messages are received in a channel that's watched but not active, defaults to false */
hideNewMessageSeparator?: boolean;
/** Overrides the default props passed to [InfiniteScroll](https://github.com/GetStream/stream-chat-react/blob/master/src/components/InfiniteScrollPaginator/InfiniteScroll.tsx) */
internalInfiniteScrollProps?: InfiniteScrollProps;
internalInfiniteScrollProps?: Partial<InfiniteScrollProps>;
/** Function called when latest messages should be loaded, after the list has jumped at an earlier message set */
jumpToLatestMessage?: () => Promise<void>;
/** Whether or not the list is currently loading more items */
Expand Down
1 change: 1 addition & 0 deletions src/constants/limits.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const DEFAULT_INITIAL_CHANNEL_PAGE_SIZE = 25;
export const DEFAULT_NEXT_CHANNEL_PAGE_SIZE = 100;
export const DEFAULT_THREAD_PAGE_SIZE = 50;
export const DEFAULT_LOAD_PAGE_SCROLL_THRESHOLD = 250;
Loading