Skip to content

Commit

Permalink
Fix GA loading disappearing
Browse files Browse the repository at this point in the history
  • Loading branch information
john681611 committed Oct 17, 2023
1 parent 500a896 commit b793386
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions application/frontend/src/pages/GapAnalysis/GapAnalysis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ export const GapAnalysis = () => {
);
const [gapAnalysis, setGapAnalysis] = useState<Record<string, GapAnalysisPathStart>>();
const [activeIndex, SetActiveIndex] = useState<string>();
const [loading, setLoading] = useState<boolean>(false);
const [loadingStandards, setLoadingStandards] = useState<boolean>(false);
const [loadingGA, setLoadingGA] = useState<boolean>(false);
const [error, setError] = useState<string | null | object>(null);
const { apiUrl } = useEnvironment();

Expand All @@ -142,36 +143,36 @@ export const GapAnalysis = () => {
useEffect(() => {
const fetchData = async () => {
const result = await axios.get(`${apiUrl}/standards`);
setLoading(false);
setLoadingStandards(false);
setStandardOptions(
standardOptionsDefault.concat(result.data.sort().map((x) => ({ key: x, text: x, value: x })))
);
};

setLoading(true);
setLoadingStandards(true);
fetchData().catch((e) => {
setLoading(false);
setLoadingStandards(false);
setError(e.response.data.message ?? e.message);
});
}, [setStandardOptions, setLoading, setError]);
}, [setStandardOptions, setLoadingStandards, setError]);

useEffect(() => {
const fetchData = async () => {
const result = await axios.get(
`${apiUrl}/map_analysis?standard=${BaseStandard}&standard=${CompareStandard}`
);
setLoading(false);
setLoadingGA(false);
setGapAnalysis(result.data);
};

if (!BaseStandard || !CompareStandard || BaseStandard === CompareStandard) return;
setGapAnalysis(undefined);
setLoading(true);
setLoadingGA(true);
fetchData().catch((e) => {
setLoading(false);
setLoadingGA(false);
setError(e.response.data.message ?? e.message);
});
}, [BaseStandard, CompareStandard, setGapAnalysis, setLoading, setError]);
}, [BaseStandard, CompareStandard, setGapAnalysis, setLoadingGA, setError]);

const handleAccordionClick = (e, titleProps) => {
const { index } = titleProps;
Expand Down Expand Up @@ -226,7 +227,7 @@ export const GapAnalysis = () => {
</Table.Row>
</Table.Header>
<Table.Body>
<LoadingAndErrorIndicator loading={loading} error={error} />
<LoadingAndErrorIndicator loading={loadingGA || loadingStandards} error={error} />
{gapAnalysis && (
<>
{Object.keys(gapAnalysis)
Expand Down

0 comments on commit b793386

Please sign in to comment.