diff --git a/web/modals/threads/sidebars/sidebars-modal.react.js b/web/modals/threads/sidebars/sidebars-modal.react.js index 5a63a0fa1..66c322f0a 100644 --- a/web/modals/threads/sidebars/sidebars-modal.react.js +++ b/web/modals/threads/sidebars/sidebars-modal.react.js @@ -1,103 +1,118 @@ // @flow import * as React from 'react'; import { useFilteredChildThreads } from 'lib/hooks/child-threads.js'; -import { threadInChatList, threadIsSidebar } from 'lib/shared/thread-utils.js'; +import { + threadIsSidebar, + useThreadsInChatList, +} from 'lib/shared/thread-utils.js'; +import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; import SidebarList from './sidebar-list.react.js'; import css from './sidebars-modal.css'; import Tabs, { type TabData } from '../../../components/tabs.react.js'; import SearchModal from '../../search-modal.react.js'; type SidebarTab = 'All Threads' | 'My Threads'; const tabsData: $ReadOnlyArray> = [ { id: 'All Threads', header: 'All Threads', }, { id: 'My Threads', header: 'My Threads', }, ]; type ContentProps = { +searchText: string, +threadID: string, +defaultTab: SidebarTab, }; function SidebarsModalContent(props: ContentProps): React.Node { const { searchText, threadID, defaultTab } = props; const [tab, setTab] = React.useState(defaultTab); const tabs = React.useMemo( () => , [tab], ); const sidebarList = useFilteredChildThreads(threadID, { predicate: threadIsSidebar, searchText, }); + const sidebarThreadInfos: $ReadOnlyArray = React.useMemo( + () => sidebarList.map(chatItem => chatItem.threadInfo), + [sidebarList], + ); + + const visibleSidebarThreadInfos = useThreadsInChatList(sidebarThreadInfos); + const visibleSidebarThreadIDs = React.useMemo( + () => new Set(visibleSidebarThreadInfos.map(thread => thread.id)), + [visibleSidebarThreadInfos], + ); + const tabContent = React.useMemo(() => { if (tab === 'All Threads') { return ; } const sidebarsChatListVisibleInChat = sidebarList.filter(chatItem => - threadInChatList(chatItem.threadInfo), + visibleSidebarThreadIDs.has(chatItem.threadInfo.id), ); return ; - }, [sidebarList, tab]); + }, [sidebarList, tab, visibleSidebarThreadIDs]); const sidebarsModalContent = React.useMemo( () => (
{tabs} {tabContent}
), [tabContent, tabs], ); return sidebarsModalContent; } type Props = { +threadID: string, +onClose: () => void, +defaultTab?: SidebarTab, }; function SidebarsModal(props: Props): React.Node { const { threadID, onClose, defaultTab = 'All Threads' } = props; const sidebarsContent = React.useCallback( (searchText: string) => ( ), [defaultTab, threadID], ); return ( {sidebarsContent} ); } export default SidebarsModal;