Skip to content

Commit

Permalink
can upload kml from v2
Browse files Browse the repository at this point in the history
  • Loading branch information
micheal-w-wells committed Nov 8, 2023
1 parent af1b2d6 commit f2ddd80
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
11 changes: 9 additions & 2 deletions api/src/paths/admin-defined-shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ GET.apiDoc = {

POST.apiDoc = {
description: 'Creates new Administratively-defined shapes from KML/KMZ data',
security: SECURITY_ON
? [
{
Bearer: ALL_ROLES
}
]
: [],
requestBody: {
description: 'Uploaded KML/KMZ file',
content: {
Expand Down Expand Up @@ -218,9 +225,9 @@ function getAdministrativelyDefinedShapes(): RequestHandler {
* @returns {RequestHandler}
*/
function uploadShape(): RequestHandler {
return async (req, res) => {
return async (req: InvasivesRequest, res) => {
const user_id = req.authContext.user.user_id;
const data = {...req.body};
const user_id = data.user_id;
const title = data.title;
let geoJSON: FeatureCollection;

Expand Down
20 changes: 11 additions & 9 deletions appv2/src/UI/Map/Buttons/KMLShapesUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useState, useContext } from 'react';
import React, { useState, useContext, useEffect } from 'react';
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';

export interface IShapeUploadRequest {
data: string;
Expand All @@ -26,18 +27,23 @@ export const KMLShapesUpload: React.FC<any> = (props) => {
const classes = useStyles();
const [uploadRequests, setUploadRequests] = useState([]);
const [dialogOpen, setDialogOpen] = React.useState(false);
//const api = useInvasivesApi();
const api = useInvasivesApi();
const [resultMessage, setResultMessage] = useState('');
const [uploadClicked, setUploadClicked] = useState(false);

useEffect(() => {
if(uploadRequests.length > 0)
doUpload().then(() => {
props.whenDone();
console.log('done');
});
}, [uploadRequests]);

const doUpload = async () => {
let response;
try {
for (let i = 0; i < uploadRequests.length; i++) {
console.log();
//response = await api.postAdminUploadShape(uploadRequests[i]);
console.log(response);
response = await api.postAdminUploadShape(uploadRequests[i]);
if (response.code !== 201) {
throw new Error(response.message);
}
Expand Down Expand Up @@ -113,10 +119,6 @@ export const KMLShapesUpload: React.FC<any> = (props) => {
open={props.open}
onSave={(files: any) => {
acceptFiles(files);
doUpload().then(() => {
props.whenDone();
console.log('done')
});
}}
showPreviews={true}
previewText={'File will be uploaded to InvasivesBC as ' + props.title}
Expand Down

0 comments on commit f2ddd80

Please sign in to comment.