All files / src/routes/pages Color.tsx

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

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 38 39 40 41                                                                                 
import { useLocation } from 'react-router-dom';
import { FC } from 'react';
import { ErrorResponse } from '../../models/errorResponse';
import { Pending } from '../../models/pending';
import { AllColorsResponse } from '../../models/allColorsResponse';
import { SearchColorsResponse } from '../../models/searchColorResponse';
import SearchColorForm from '../../components/color/search/SearchColorForm';
import RegisterColor from '../../components/color/register/RegisterColor';
import { AllColors, Loading, SearchColorResult, Title } from '../../components';
import { useFetchAllColors } from '../../hooks/useFetchAllColors';
import { useFetchSearchColor } from '../../hooks/useFetchSearchColor';
 
const Color: FC = () => {
  const location = useLocation();
  const searchParams = new URLSearchParams(location.search);
  const keywords = searchParams.get('keywords') || '';
  // get all colors result
  const initialResult: AllColorsResponse | ErrorResponse | Pending = useFetchAllColors();
  // get search result
  const result: SearchColorsResponse | ErrorResponse | Pending = useFetchSearchColor(keywords);
  return (
    <>
      <Title title="ケーブル識別色管理" />
      <RegisterColor />
      <SearchColorForm keywords={keywords} />
      {keywords === '' ? (
        // 検索欄が空
        <AllColors result={initialResult} />
      ) : result === 'pending' ? (
        // 処理中
        <Loading />
      ) : (
        // fetch結果
        <SearchColorResult result={result} />
      )}
    </>
  );
};
 
export default Color;