All files / src/routes/pages Home.tsx

0% Statements 0/27
0% Branches 0/1
0% Functions 0/1
0% Lines 0/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                                                                         
import { useLocation } from 'react-router-dom';
import { FC, useState } from 'react';
import { SearchItemsResponse } from '../../models/searchItemResponse';
import { useFetchSearchItemWithUseEffect } from '../../hooks/useFetchSearchItemWithUseEffect';
import { ErrorResponse } from '../../models/errorResponse';
import { Pending } from '../../models/pending';
import { Loading, Menu, SearchItemForm, SearchItemIsRentButton, SearchItemResultList } from '../../components';
 
const Home: FC = () => {
  const location = useLocation();
  const searchParams = new URLSearchParams(location.search);
  const keywords = searchParams.get('keywords') || '';
  // get search result
  const result: SearchItemsResponse | ErrorResponse | Pending = useFetchSearchItemWithUseEffect(keywords);
  // filter
  const [isRent, setIsRent] = useState<boolean>(false);
  return (
    <>
      <Menu />
      <SearchItemForm keywords={keywords} />
      <SearchItemIsRentButton setIsRent={setIsRent} />
      {keywords === '' ? (
        // 検索欄が空
        <></>
      ) : result === 'pending' ? (
        // 処理中
        <Loading />
      ) : (
        // fetch結果
        <SearchItemResultList result={result} isRent={isRent} />
      )}
    </>
  );
};
 
export default Home;