Skip to content

Commit

Permalink
refactor: Make data loading state more obvious for maps
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Feb 17, 2022
1 parent e50781c commit a788a30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 13 additions & 2 deletions app/charts/map/chart-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,18 @@ export const ChartMapVisualization = ({
}
}, [areaLayer, dimensions, observations, symbolDimensionIri, geoCoordinates]);

if (measures && dimensions && observations) {
const areaLayerPrepared =
areaDimensionIri !== "" ? areaLayer !== undefined : true;
const symbolLayerPrepared =
symbolDimensionIri !== "" ? symbolLayer !== undefined : true;

if (
measures &&
dimensions &&
observations &&
areaLayerPrepared &&
symbolLayerPrepared
) {
return (
<ChartMapPrototype
observations={observations}
Expand All @@ -167,7 +178,7 @@ export const ChartMapVisualization = ({
geoShapes={geoShapes}
/>
);
} else if (fetching) {
} else if (fetching || !areaLayerPrepared || !symbolLayerPrepared) {
return <Loading />;
} else if (error) {
return <LoadingDataError />;
Expand Down
6 changes: 3 additions & 3 deletions app/charts/map/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ export const MapComponent = () => {
);

const baseLayerStyle = useMemo(() => getBaseLayerStyle({ locale }), [locale]);
const featuresLoaded =
features.areaLayer !== undefined || features.symbolLayer !== undefined;

return (
<Box>
Expand All @@ -208,9 +210,7 @@ export const MapComponent = () => {
<ZoomButton iconName="add" handleClick={zoomIn} />
<ZoomButton iconName="minus" handleClick={zoomOut} />
</Box>
{(areaLayer.data.length > 0
? shapes.features !== undefined
: features.symbolLayer?.points.length !== undefined) && (
{featuresLoaded && (
<DeckGL
viewState={viewState}
onViewStateChange={onViewStateChange}
Expand Down

0 comments on commit a788a30

Please sign in to comment.