Skip to content

Commit

Permalink
Merge pull request #188 from hotosm/feat/add-project-image
Browse files Browse the repository at this point in the history
feat: download fligh plan
  • Loading branch information
nrjadkry authored Sep 3, 2024
2 parents d066a9d + 713d83a commit 5b9a3c0
Showing 1 changed file with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useGetIndividualTaskQuery } from '@Api/tasks';
import { useTypedDispatch, useTypedSelector } from '@Store/hooks';
import { setSecondPageState } from '@Store/actions/droneOperatorTask';
import hasErrorBoundary from '@Utils/hasErrorBoundary';
import { toast } from 'react-toastify';
import UploadsBox from './UploadsBox';
import DescriptionBox from './DescriptionBox';

Expand Down Expand Up @@ -83,13 +84,30 @@ const DroneOperatorDescriptionBox = () => {
];

const handleDownloadFlightPlan = () => {
const link = document.createElement('a');
// link.setAttribute('download', '');
link.download = 'flight_plan.kmz';
link.href = `${BASE_URL}/waypoint/task/${taskId}/?project_id=${projectId}&download=true`;
document.body.appendChild(link);
link.click();
link.remove();
fetch(
`${BASE_URL}/waypoint/task/${taskId}/?project_id=${projectId}&download=true`,
)
.then(response => {
if (!response.ok) {
throw new Error(`Network response was ${response.statusText}`);
}
return response.blob();
})
.then(blob => {
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
// link.setAttribute('download', '');
link.href = url;
link.download = 'flight_plan.kmz';
document.body.appendChild(link);
link.click();
link.remove();
window.URL.revokeObjectURL(url);
})
.catch(error =>
toast.error(`There wan an error while downloading file
${error}`),
);
};

return (
Expand Down

0 comments on commit 5b9a3c0

Please sign in to comment.