UNPKG

stream-chat-react-native-core

Version:

The official React Native and Expo components for Stream Chat, a service for building chat applications

56 lines (50 loc) 1.44 kB
import { ThreadState } from 'stream-chat'; import type { ThreadContextValue } from '../../../contexts/threadContext/ThreadContext'; import { useStateStore } from '../../../hooks'; const selector = (nextValue: ThreadState) => ({ isLoadingNext: nextValue.pagination.isLoadingNext, isLoadingPrev: nextValue.pagination.isLoadingPrev, latestReplies: nextValue.replies, }) as const; export const useCreateThreadContext = ({ allowThreadMessagesInChannel, onAlsoSentToChannelHeaderPress, closeThread, loadMoreThread, openThread, reloadThread, setThreadLoadingMore, thread, threadHasMore, threadInstance, threadLoadingMore, threadMessages, }: ThreadContextValue) => { const { isLoadingNext, isLoadingPrev, latestReplies } = useStateStore(threadInstance?.state, selector) ?? {}; const contextAdapter = threadInstance ? { loadMoreRecentThread: threadInstance.loadNextPage, loadMoreThread: threadInstance.loadPrevPage, threadInstance, threadLoadingMore: isLoadingPrev, threadLoadingMoreRecent: isLoadingNext, threadMessages: latestReplies ?? [], } : {}; return { allowThreadMessagesInChannel, onAlsoSentToChannelHeaderPress, closeThread, loadMoreThread, openThread, reloadThread, setThreadLoadingMore, thread, threadHasMore, threadLoadingMore, threadMessages, ...contextAdapter, }; };