All files / src/routes/pages Connector.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 38 39 40 41 42 43 44 45 46                                                                                           
import { useLocation } from 'react-router-dom';
import { FC } from 'react';
import { ErrorResponse } from '../../models/errorResponse';
import { Pending } from '../../models/pending';
import {
  AllConnectors,
  Loading,
  RegisterConnector,
  SearchConnectorForm,
  SearchConnectorResult,
  Title,
} from '../../components';
import { useFetchSearchConnector } from '../../hooks/useFetchSearchConnector';
import { SearchConnectorsResponse } from '../../models/searchConnectorResponse';
import { useFetchAllConnectors } from '../../hooks/useFetchAllConnectors';
import { AllConnectorsResponse } from '../../models/allConnectorsResponse';
 
const Connector: FC = () => {
  const location = useLocation();
  const searchParams = new URLSearchParams(location.search);
  const keywords = searchParams.get('keywords') || '';
  // get all connectors result
  const initialResult: AllConnectorsResponse | ErrorResponse | Pending = useFetchAllConnectors();
  // get search result
  const result: SearchConnectorsResponse | ErrorResponse | Pending = useFetchSearchConnector(keywords);
  return (
    <>
      <Title title="端子名管理" />
      <RegisterConnector />
      <SearchConnectorForm keywords={keywords} />
      {keywords === '' ? (
        // 検索欄が空
        <AllConnectors result={initialResult} />
      ) : result === 'pending' ? (
        // 処理中
        <Loading />
      ) : (
        // fetch結果
        <SearchConnectorResult result={result} />
      )}
    </>
  );
};
 
export default Connector;