import { debounce } from 'lodash'; import React from 'react'; import { useRef } from 'react'; import { FormattedMessage } from 'react-intl'; import { expandConversations } from 'soapbox/actions/conversations'; import ScrollableList from 'soapbox/components/scrollable_list'; import { useAppDispatch, useAppSelector } from 'soapbox/hooks'; import Conversation from '../components/conversation'; import type { VirtuosoHandle } from 'react-virtuoso'; const ConversationsList: React.FC = () => { const dispatch = useAppDispatch(); const ref = useRef(null); const conversations = useAppSelector((state) => state.conversations.get('items')); const isLoading = useAppSelector((state) => state.conversations.get('isLoading', true)); const getCurrentIndex = (id: string) => conversations.findIndex((x: any) => x.get('id') === id); const handleMoveUp = (id: string) => { const elementIndex = getCurrentIndex(id) - 1; selectChild(elementIndex); }; const handleMoveDown = (id: string) => { const elementIndex = getCurrentIndex(id) + 1; selectChild(elementIndex); }; const selectChild = (index: number) => { ref.current?.scrollIntoView({ index, behavior: 'smooth', done: () => { const element = document.querySelector(`#direct-list [data-index="${index}"] .focusable`); if (element) { element.focus(); } }, }); }; const handleLoadOlder = debounce(() => { const maxId = conversations.getIn([-1, 'id']); if (maxId) dispatch(expandConversations({ maxId })); }, 300, { leading: true }); return ( } > {conversations.map((item: any) => ( ))} ); }; export default ConversationsList;