Skip to content

Commit

Permalink
Include LinearProgress within tooltip component
Browse files Browse the repository at this point in the history
  • Loading branch information
JorgeMartinezG committed May 17, 2021
1 parent 1d5057e commit e8d0e89
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
9 changes: 8 additions & 1 deletion src/components/MapView/MapTooltip/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React from 'react';
import { useSelector } from 'react-redux';
import { Popup } from 'react-mapbox-gl';
import { createStyles, withStyles, WithStyles } from '@material-ui/core';
import {
createStyles,
withStyles,
WithStyles,
LinearProgress,
} from '@material-ui/core';
import { tooltipSelector } from '../../../context/tooltipStateSlice';

function MapTooltip({ classes }: TooltipProps) {
Expand All @@ -21,6 +26,8 @@ function MapTooltip({ classes }: TooltipProps) {
{key}: {value.data}
</h4>
))}

{popup.wmsGetFeatureInfoLoading ? <LinearProgress /> : null}
</Popup>
) : null;
}
Expand Down
36 changes: 15 additions & 21 deletions src/components/MapView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ import {
} from '../../context/mapStateSlice/selectors';
import { addLayer, setMap, updateDateRange } from '../../context/mapStateSlice';
import {
showPopup,
hidePopup,
addPopupData,
setWMSGetFeatureInfoLoading,
} from '../../context/tooltipStateSlice';
import {
availableDatesSelector,
Expand Down Expand Up @@ -240,28 +240,22 @@ function MapView({ classes }: MapViewProps) {
).format('YYYY-MM-DD');

const params = getFeatureInfoParams(map, evt, dateFromRef);
dispatch(setWMSGetFeatureInfoLoading(true));
makeFeatureInfoRequest(featureInfoLayers, params).then(
(result: any) => {
if (!result) {
return;
(result: { [name: string]: string } | null) => {
if (result) {
Object.keys(result).forEach((k: string) => {
dispatch(
addPopupData({
[k]: {
data: result[k],
coordinates: evt.lngLat,
},
}),
);
});
}
Object.keys(result).forEach(k => {
dispatch(
addPopupData({
[k]: {
data: result[k],
coordinates: evt.lngLat,
},
}),
);
});

dispatch(
showPopup({
coordinates: evt.lngLat,
locationName: '',
}),
);
dispatch(setWMSGetFeatureInfoLoading(false));
},
);
}}
Expand Down
13 changes: 12 additions & 1 deletion src/context/tooltipStateSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { merge } from 'lodash';
import type { RootState } from './store';

export interface PopupData {
[key: string]: { data: number; coordinates: GeoJSON.Position };
[key: string]: { data: number | string; coordinates: GeoJSON.Position };
}

export interface MapTooltipState {
coordinates?: GeoJSON.Position;
locationName: string;
data: PopupData;
showing: boolean;
wmsGetFeatureInfoLoading: boolean;
}

type ShowPopupType = {
Expand All @@ -22,6 +23,7 @@ const initialState: MapTooltipState = {
locationName: '',
data: {},
showing: false,
wmsGetFeatureInfoLoading: false,
};

export const tooltipStateSlice = createSlice({
Expand Down Expand Up @@ -66,6 +68,14 @@ export const tooltipStateSlice = createSlice({
...state,
coordinates: payload,
}),

setWMSGetFeatureInfoLoading: (
state,
{ payload }: PayloadAction<boolean>,
) => ({
...state,
wmsGetFeatureInfoLoading: payload,
}),
},
});

Expand All @@ -84,6 +94,7 @@ export const {
hidePopup,
showPopup,
setPopupCoordinates,
setWMSGetFeatureInfoLoading,
} = tooltipStateSlice.actions;

export default tooltipStateSlice.reducer;

0 comments on commit e8d0e89

Please sign in to comment.