Skip to content

Commit

Permalink
fix: adjust ChannelActionContextValue type (#2434)
Browse files Browse the repository at this point in the history
### 🎯 Goal

Adjust `ChannelActionContextValue` type to include new
`highlightDuration` parameter, pair the types to the functions so that
we don't forget in the future (in case we need to adjust).
  • Loading branch information
arnautov-anton authored Jun 21, 2024
1 parent 11e606f commit 977ec39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,9 @@ const ChannelInner = <

const clearHighlightedMessageTimeoutId = useRef<ReturnType<typeof setTimeout> | null>(null);

const jumpToMessage = useCallback(
const jumpToMessage: ChannelActionContextValue<StreamChatGenerics>['jumpToMessage'] = useCallback(
async (
messageId: string,
messageId,
messageLimit = DEFAULT_JUMP_TO_PAGE_SIZE,
highlightDuration = DEFAULT_HIGHLIGHT_DURATION,
) => {
Expand Down Expand Up @@ -794,7 +794,7 @@ const ChannelInner = <
[channel, loadMoreFinished],
);

const jumpToLatestMessage = useCallback(async () => {
const jumpToLatestMessage: ChannelActionContextValue<StreamChatGenerics>['jumpToLatestMessage'] = useCallback(async () => {
await channel.state.loadMessageIntoState('latest');
// FIXME: we cannot rely on constant value 25 as the page size can be customized by integrators
const hasMoreOlder = channel.state.messages.length >= 25;
Expand All @@ -804,7 +804,7 @@ const ChannelInner = <
});
}, [channel, loadMoreFinished]);

const jumpToFirstUnreadMessage = useCallback(
const jumpToFirstUnreadMessage: ChannelActionContextValue<StreamChatGenerics>['jumpToFirstUnreadMessage'] = useCallback(
async (
queryMessageLimit = DEFAULT_JUMP_TO_PAGE_SIZE,
highlightDuration = DEFAULT_HIGHLIGHT_DURATION,
Expand Down
7 changes: 5 additions & 2 deletions src/context/ChannelActionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,12 @@ export type ChannelActionContextValue<
message: UpdatedMessage<StreamChatGenerics>,
options?: UpdateMessageOptions,
) => Promise<UpdateMessageAPIResponse<StreamChatGenerics> | void>;
jumpToFirstUnreadMessage: (queryMessageLimit?: number) => Promise<void>;
jumpToFirstUnreadMessage: (
queryMessageLimit?: number,
highlightDuration?: number,
) => Promise<void>;
jumpToLatestMessage: () => Promise<void>;
jumpToMessage: (messageId: string, limit?: number) => Promise<void>;
jumpToMessage: (messageId: string, limit?: number, highlightDuration?: number) => Promise<void>;
loadMore: (limit?: number) => Promise<number>;
loadMoreNewer: (limit?: number) => Promise<number>;
loadMoreThread: () => Promise<void>;
Expand Down

0 comments on commit 977ec39

Please sign in to comment.