diff --git a/web/modals/chat/sidebar-list-modal.react.js b/web/modals/chat/sidebar-list-modal.react.js index c8aebb152..34f0c45b4 100644 --- a/web/modals/chat/sidebar-list-modal.react.js +++ b/web/modals/chat/sidebar-list-modal.react.js @@ -1,143 +1,144 @@ // @flow import { faTimesCircle } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import classNames from 'classnames'; import * as React from 'react'; import { sidebarInfoSelector } from 'lib/selectors/thread-selectors'; import SearchIndex from 'lib/shared/search-index'; import { threadSearchText } from 'lib/shared/thread-utils'; import type { ThreadInfo } from 'lib/types/thread-types'; import chatThreadListCSS from '../../chat/chat-thread-list.css'; import SidebarItem from '../../chat/sidebar-item.react'; import { useSelector } from '../../redux/redux-utils'; import globalCSS from '../../style.css'; import { MagnifyingGlass } from '../../vectors.react'; +import Input from '../input.react'; import { useModalContext } from '../modal-provider.react'; import Modal from '../modal.react'; type Props = { +threadInfo: ThreadInfo, }; function SidebarListModal(props: Props): React.Node { const { threadInfo } = props; const [searchState, setSearchState] = React.useState({ text: '', results: new Set(), }); const { popModal } = useModalContext(); const sidebarInfos = useSelector( state => sidebarInfoSelector(state)[threadInfo.id] ?? [], ); const userInfos = useSelector(state => state.userStore.userInfos); const listData = React.useMemo(() => { if (!searchState.text) { return sidebarInfos; } return sidebarInfos.filter(sidebarInfo => searchState.results.has(sidebarInfo.threadInfo.id), ); }, [sidebarInfos, searchState]); const sidebars = React.useMemo( () => listData.map(item => (
)), [popModal, listData], ); const viewerID = useSelector( state => state.currentUserInfo && state.currentUserInfo.id, ); const searchIndex = React.useMemo(() => { const index = new SearchIndex(); for (const sidebarInfo of sidebarInfos) { const threadInfoFromSidebarInfo = sidebarInfo.threadInfo; index.addEntry( threadInfoFromSidebarInfo.id, threadSearchText(threadInfoFromSidebarInfo, userInfos, viewerID), ); } return index; }, [sidebarInfos, userInfos, viewerID]); React.useEffect(() => { setSearchState(curState => ({ ...curState, results: new Set(searchIndex.getSearchResults(curState.text)), })); }, [searchIndex]); const onChangeSearchText = React.useCallback( (event: SyntheticEvent) => { const searchText = event.currentTarget.value; setSearchState({ text: searchText, results: new Set(searchIndex.getSearchResults(searchText)), }); }, [searchIndex], ); const clearQuery = React.useCallback( (event: SyntheticEvent) => { event.preventDefault(); setSearchState({ text: '', results: [] }); }, [], ); let clearQueryButton = null; if (searchState.text) { clearQueryButton = ( ); } return (
- {clearQueryButton}
    {sidebars}
); } export default SidebarListModal;