import React, { useCallback } from 'react'; import { PagePathLabel, UserPicture } from '@growi/ui/dist/components'; import { useDebounce } from 'usehooks-ts'; import { useSWRxSearch } from '~/stores/search'; import { SearchMenuItem } from './SearchMenuItem'; type Props = { searchKeyword: string, getItemProps: any, highlightedIndex: number | null, } export const SearchResultMenuItem = (props: Props): JSX.Element => { const { searchKeyword, highlightedIndex, getItemProps } = props; const debouncedKeyword = useDebounce(searchKeyword, 500); const isEmptyKeyword = searchKeyword.trim().length === 0; const { data: searchResult, isLoading } = useSWRxSearch(isEmptyKeyword ? null : debouncedKeyword, null, { limit: 10 }); const getFiexdIndex = useCallback((index: number | null) => { if (index == null) { return -1; } return (isEmptyKeyword ? 1 : 3) + index; }, [isEmptyKeyword]); if (isLoading) { return ( <> Searching...
> ); } if (isEmptyKeyword || searchResult == null || searchResult.data.length === 0) { return <>>; } return ( <> {searchResult?.data .map((item, index) => (