(props: Props)
| 52 | }; |
| 53 | |
| 54 | function ThreadPickerModal(props: Props): React.Node { |
| 55 | const { createNewEntry, ...modalProps } = props; |
| 56 | |
| 57 | const onScreenThreadInfos = useOnScreenEntryEditableThreadInfos(); |
| 58 | const searchIndex = useGlobalThreadSearchIndex(); |
| 59 | |
| 60 | invariant( |
| 61 | onScreenThreadInfos.length > 0, |
| 62 | "ThreadPicker can't be open when onScreenThreadInfos is empty", |
| 63 | ); |
| 64 | |
| 65 | const [searchText, setSearchText] = React.useState<string>(''); |
| 66 | const [searchResults, setSearchResults] = React.useState< |
| 67 | $ReadOnlyArray<ThreadInfo>, |
| 68 | >([]); |
| 69 | |
| 70 | const searchRef = React.useRef<?HTMLInputElement>(); |
| 71 | |
| 72 | React.useEffect(() => { |
| 73 | searchRef.current?.focus(); |
| 74 | }, []); |
| 75 | |
| 76 | const onChangeSearchText = React.useCallback( |
| 77 | (text: string) => { |
| 78 | const results = searchIndex.getSearchResults(text); |
| 79 | setSearchText(text); |
| 80 | const threadInfoResults = reorderThreadSearchResults( |
| 81 | onScreenThreadInfos, |
| 82 | results, |
| 83 | ); |
| 84 | setSearchResults(threadInfoResults); |
| 85 | }, |
| 86 | [searchIndex, onScreenThreadInfos], |
| 87 | ); |
| 88 | |
| 89 | const threads = React.useMemo( |
| 90 | () => (searchText ? searchResults : onScreenThreadInfos), |
| 91 | [searchText, onScreenThreadInfos, searchResults], |
| 92 | ); |
| 93 | |
| 94 | const threadPickerContent = React.useMemo(() => { |
| 95 | const options = threads.map(threadInfo => ( |
| 96 | <ThreadPickerOption |
| 97 | threadInfo={threadInfo} |
| 98 | createNewEntry={createNewEntry} |
| 99 | key={threadInfo.id} |
| 100 | onCloseModal={modalProps.onClose} |
| 101 | /> |
| 102 | )); |
| 103 | |
| 104 | if (options.length === 0 && searchText.length > 0) { |
| 105 | return ( |
| 106 | <div className={css.noResultsText}>No results for {searchText}</div> |
| 107 | ); |
| 108 | } else { |
| 109 | return options; |
| 110 | } |
| 111 | }, [threads, createNewEntry, modalProps.onClose, searchText]); |
nothing calls this directly
no test coverage detected