From df12aefaa3217a1832ebb5087f10fd01ec845fb7 Mon Sep 17 00:00:00 2001 From: Micheal Wells Date: Mon, 4 Dec 2023 16:13:41 -0800 Subject: [PATCH] slicker reload of server boundaries on kml upload --- appv2/src/UI/Map/Buttons/KMLShapesUpload.tsx | 4 ++++ appv2/src/state/actions.tsx | 2 ++ appv2/src/state/sagas/map.ts | 14 +++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/appv2/src/UI/Map/Buttons/KMLShapesUpload.tsx b/appv2/src/UI/Map/Buttons/KMLShapesUpload.tsx index 51654c88c..9890a3e31 100644 --- a/appv2/src/UI/Map/Buttons/KMLShapesUpload.tsx +++ b/appv2/src/UI/Map/Buttons/KMLShapesUpload.tsx @@ -3,6 +3,8 @@ import { Box, Button, Theme, Typography } from '@mui/material'; import { DropzoneDialog } from 'mui-file-dropzone'; import makeStyles from '@mui/styles/makeStyles'; import { useInvasivesApi } from 'hooks/useInvasivesApi'; +import { useDispatch } from 'react-redux'; +import { INIT_SERVER_BOUNDARIES_GET, REFETCH_SERVER_BOUNDARIES } from 'state/actions'; export interface IShapeUploadRequest { data: string; @@ -30,12 +32,14 @@ export const KMLShapesUpload: React.FC = (props) => { const api = useInvasivesApi(); const [resultMessage, setResultMessage] = useState(''); const [uploadClicked, setUploadClicked] = useState(false); + const dispatch = useDispatch(); useEffect(() => { if(uploadRequests.length > 0) doUpload().then(() => { props.whenDone(); console.log('done'); + dispatch({ type: REFETCH_SERVER_BOUNDARIES}) }); }, [uploadRequests]); diff --git a/appv2/src/state/actions.tsx b/appv2/src/state/actions.tsx index d0115a58b..2e0fdb34d 100644 --- a/appv2/src/state/actions.tsx +++ b/appv2/src/state/actions.tsx @@ -24,6 +24,8 @@ export const AUTH_CLEAR_ROLES = 'AUTH_CLEAR_ROLES'; export const AUTH_REFRESH_ROLES_ERROR = 'AUTH_REFRESH_ROLES_ERROR'; export const AUTH_REFRESH_ROLES_COMPLETE = 'AUTH_REFRESH_ROLES_COMPLETE'; +export const REFETCH_SERVER_BOUNDARIES = 'REFETCH_SERVER_BOUNDARIES'; + export const OPEN_NEW_RECORD_MENU = 'OPEN_NEW_RECORD_MENU' export const CLOSE_NEW_RECORD_MENU = 'CLOSE_NEW_RECORD_MENU' export const USERINFO_LOAD_COMPLETE = 'USERINFO_LOAD_COMPLETE'; diff --git a/appv2/src/state/sagas/map.ts b/appv2/src/state/sagas/map.ts index 435e70a19..89d5eff81 100644 --- a/appv2/src/state/sagas/map.ts +++ b/appv2/src/state/sagas/map.ts @@ -1,4 +1,4 @@ -import { all, debounce, fork, put, select, take, takeEvery, takeLatest, throttle } from 'redux-saga/effects'; +import { all, call, debounce, fork, put, select, take, takeEvery, takeLatest, throttle } from 'redux-saga/effects'; import { ACTIVITIES_GEOJSON_GET_ONLINE, ACTIVITIES_GEOJSON_GET_REQUEST, @@ -42,6 +42,7 @@ import { RECORD_SET_TO_EXCEL_FAILURE, RECORD_SET_TO_EXCEL_REQUEST, RECORD_SET_TO_EXCEL_SUCCESS, + REFETCH_SERVER_BOUNDARIES, REMOVE_CLIENT_BOUNDARY, REMOVE_SERVER_BOUNDARY, SET_CURRENT_OPEN_SET, @@ -186,10 +187,13 @@ function* handle_MAP_INIT_REQUEST(action) { }; const recordSets = oldAppState?.recordSets ? oldAppState.recordSets : defaultRecordSet; + /* const serverShapesServerResponse = yield InvasivesAPI_Call('GET', '/admin-defined-shapes/'); const shapes = serverShapesServerResponse.data.result; yield put({ type: INIT_SERVER_BOUNDARIES_GET, payload: { data: shapes } }); + */ + yield call(refetchServerBoundaries) let newMapState = {}; for (const rs in recordSets) { newMapState[rs] = {}; @@ -247,6 +251,12 @@ function* handle_MAP_INIT_REQUEST(action) { }); } +function* refetchServerBoundaries() { + const serverShapesServerResponse = yield InvasivesAPI_Call('GET', '/admin-defined-shapes/'); + const shapes = serverShapesServerResponse.data.result; + yield put({ type: INIT_SERVER_BOUNDARIES_GET, payload: { data: shapes } }); +} + function* handle_SORT_COLUMN_STATE_UPDATE(action) { const mapState = yield select(selectMap); const filters = mapState?.layers?.[action.payload.id]?.filters; @@ -784,6 +794,8 @@ function* activitiesPageSaga() { takeEvery(DRAW_CUSTOM_LAYER, handle_DRAW_CUSTOM_LAYER), takeEvery(CUSTOM_LAYER_DRAWN, handle_CUSTOM_LAYER_DRAWN), + takeEvery(REFETCH_SERVER_BOUNDARIES, refetchServerBoundaries), + takeEvery(REMOVE_SERVER_BOUNDARY, handle_REMOVE_SERVER_BOUNDARY), takeEvery(RECORDSET_CLEAR_FILTERS, handle_UserFilterChange), takeEvery(RECORDSET_REMOVE_FILTER, handle_UserFilterChange),