SearchResultMenuItem.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import React from 'react';
  2. import { PagePathLabel, UserPicture } from '@growi/ui/dist/components';
  3. import { useDebounce } from 'usehooks-ts';
  4. import { useSWRxSearch } from '~/stores/search';
  5. type Props = {
  6. searchKeyword: string,
  7. }
  8. export const SearchResultMenuItem = (props: Props): JSX.Element => {
  9. const { searchKeyword } = props;
  10. const debouncedKeyword = useDebounce(searchKeyword, 500);
  11. const { data: searchResult } = useSWRxSearch(debouncedKeyword, null, { limit: 10 });
  12. if (searchResult == null || searchResult.data.length === 0) {
  13. return <></>;
  14. }
  15. return (
  16. <>
  17. <table>
  18. <tbody>
  19. {searchResult.data?.map(pageWithMeta => (
  20. <tr key={pageWithMeta.data._id}>
  21. <div className="ps-1 mb-2">
  22. <UserPicture />
  23. <span className="ms-3 text-break text-wrap"><PagePathLabel path={pageWithMeta.data.path} /></span>
  24. <span className="ms-3">{pageWithMeta.data.seenUsers.length}</span>
  25. </div>
  26. </tr>
  27. ))}
  28. </tbody>
  29. </table>
  30. <div className="border-top mt-2 mb-2" />
  31. </>
  32. );
  33. };