Skip to content

Commit

Permalink
slicker reload of server boundaries on kml upload
Browse files Browse the repository at this point in the history
  • Loading branch information
micheal-w-wells committed Dec 5, 2023
1 parent 78a5988 commit df12aef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions appv2/src/UI/Map/Buttons/KMLShapesUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -30,12 +32,14 @@ export const KMLShapesUpload: React.FC<any> = (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]);

Expand Down
2 changes: 2 additions & 0 deletions appv2/src/state/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
14 changes: 13 additions & 1 deletion appv2/src/state/sagas/map.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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] = {};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit df12aef

Please sign in to comment.