import classNames from 'clsx'; import React, { useRef, useState } from 'react'; import { useDispatch } from 'react-redux'; import { Virtuoso } from 'react-virtuoso'; import { fetchChats } from 'soapbox/actions/chats'; import PullToRefresh from 'soapbox/components/pull-to-refresh'; import { Stack } from 'soapbox/components/ui'; import PlaceholderChat from 'soapbox/features/placeholder/components/placeholder-chat'; import { useChats } from 'soapbox/queries/chats'; import ChatListItem from './chat-list-item'; import Blankslate from './chat-pane/blankslate'; interface IChatList { onClickChat: (chat: any) => void, useWindowScroll?: boolean, fade?: boolean, searchValue?: string } const ChatList: React.FC = ({ onClickChat, useWindowScroll = false, searchValue, fade }) => { const dispatch = useDispatch(); const chatListRef = useRef(null); const { chatsQuery: { data: chats, isFetching, hasNextPage, fetchNextPage } } = useChats(searchValue); const [isNearBottom, setNearBottom] = useState(false); const [isNearTop, setNearTop] = useState(true); const isEmpty = (!chats || chats.length === 0); const handleLoadMore = () => { if (hasNextPage && !isFetching) { fetchNextPage(); } }; const handleRefresh = () => { return dispatch(fetchChats()) as any; }; const renderEmpty = () => { if (isFetching) { return ( ); } else { return ; } }; return (
{isEmpty ? renderEmpty() : ( setNearTop(atTop)} atBottomStateChange={(atBottom) => setNearBottom(atBottom)} useWindowScroll={useWindowScroll} data={chats} endReached={handleLoadMore} itemContent={(_index, chat) => } components={{ ScrollSeekPlaceholder: () => , // Footer: () => hasNextPage ? : null, EmptyPlaceholder: renderEmpty, }} /> )} {fade && ( <>
)}
); }; export default ChatList;