Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Commit

Permalink
Shows header before data is fetched
Browse files Browse the repository at this point in the history
  • Loading branch information
madsnedergaard committed Nov 12, 2022
1 parent 9ef0af8 commit d8430a0
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions web/src/features/panels/Zone/ZoneDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import useGetZone from 'api/getZone';
import LoadingOrError from 'components/LoadingOrError';
import { useAtom } from 'jotai';
import { Navigate, useParams } from 'react-router-dom';
import { timeAverageAtom } from 'utils/state';
Expand All @@ -8,23 +7,23 @@ import { ZoneHeader } from './ZoneHeader';
export default function ZoneDetails(): JSX.Element {
const { zoneId } = useParams();
const [timeAverage] = useAtom(timeAverageAtom);
const { isLoading, isError, error, data } = useGetZone(timeAverage, zoneId, {
const { error, data, status } = useGetZone(timeAverage, zoneId, {
enabled: Boolean(zoneId),
});

if (!zoneId) {
return <Navigate to="/" replace />;
}

if (isLoading || isError) {
return <LoadingOrError error={error as Error} />;
}

// TODO: Handle error state
// TODO: Handle loading state nicely (let's keep country name in the header)
console.error(error);
console.log('I should do something with all this data', data);

return (
<div>
<ZoneHeader zoneId={zoneId} />
<ZoneHeader zoneId={zoneId} date="" isEstimated isAggregated />
{status === 'loading' && 'Loading...'}
</div>
);
}

0 comments on commit d8430a0

Please sign in to comment.