Passed
Push — feature/azure-webapp-pipeline-... ( 271549...3c88ad )
by Grant
07:11 queued 10s
created

resources/assets/js/hooks/classificationHooks.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 29
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 24
mnd 1
bc 1
fnc 1
dl 0
loc 29
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
rs 10
1
import { useEffect } from "react";
2
import { useSelector } from "react-redux";
3
import { DispatchType } from "../configureStore";
4
import { Classification } from "../models/types";
5
import {
6
  getClassifications,
7
  classificationsIsLoading,
8
} from "../store/Classification/classificationSelector";
9
import { loadClassificationsIntoState } from "../store/Classification/classificationActions";
10
11
// eslint-disable-next-line import/prefer-default-export
12
export function useLoadClassifications(
13
  dispatch: DispatchType,
14
): {
15
  classifications: Classification[];
16
  isLoadingClassifications: boolean;
17
} {
18
  const classifications = useSelector(getClassifications);
19
  const isLoading = useSelector(classificationsIsLoading);
20
21
  useEffect((): void => {
22
    if (classifications.length === 0 && !isLoading) {
23
      dispatch(loadClassificationsIntoState());
24
    }
25
  }, [classifications.length, isLoading, dispatch]);
26
27
  return { classifications, isLoadingClassifications: isLoading };
28
}
29