Skip to content

Commit

Permalink
Merge pull request #1045 from NSUWAL123/fix-download-submission-ref
Browse files Browse the repository at this point in the history
fix (projectInfo): submissionJsonDownload - api fetch technuique chan…
  • Loading branch information
varun2948 authored Dec 14, 2023
2 parents c25d6fd + 4a938ef commit 5e4fd9a
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 3 deletions.
84 changes: 84 additions & 0 deletions src/frontend/src/api/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,90 @@ export const getDownloadProjectSubmission: Function = (url: string) => {
};
};

export const getDownloadProjectSubmissionJson: Function = (url: string) => {
return async (dispatch) => {
dispatch(
CoreModules.TaskActions.GetDownloadProjectSubmissionLoading({
type: 'json',
loading: true,
}),
);

const getProjectSubmission = async (url: string) => {
try {
const response = await CoreModules.axios.post(url);
dispatch(
CommonActions.SetSnackBar({
open: true,
message: response.data.Message,
variant: 'success',
duration: 3000,
}),
);

const checkStatus = async () => {
let statusResponse;
do {
const submissionResponse = await CoreModules.axios.post(
`${url}&background_task_id=${response.data.task_id}`,
);
statusResponse = submissionResponse.data;
if (statusResponse.status === 'PENDING') {
await new Promise((resolve) => setTimeout(resolve, 2000));
}
} while (statusResponse.status === 'PENDING');
return statusResponse;
};
const finalStatus = await checkStatus();
if (finalStatus.status === 'FAILED') {
dispatch(
CommonActions.SetSnackBar({
open: true,
message: finalStatus.message,
variant: 'error',
duration: 3000,
}),
);
return;
}
var a = document.createElement('a');
a.href = finalStatus;
a.download = 'Submissions';
a.click();
dispatch(
CoreModules.TaskActions.GetDownloadProjectSubmissionLoading({
type: 'json',
loading: false,
}),
);
} catch (error) {
dispatch(
CommonActions.SetSnackBar({
open: true,
message: 'Something went wrong.',
variant: 'error',
duration: 3000,
}),
);
dispatch(
CoreModules.TaskActions.GetDownloadProjectSubmissionLoading({
type: 'json',
loading: false,
}),
);
} finally {
dispatch(
CoreModules.TaskActions.GetDownloadProjectSubmissionLoading({
type: 'json',
loading: false,
}),
);
}
};
await getProjectSubmission(url);
};
};

export const fetchConvertToOsmDetails: Function = (url: string) => {
return async (dispatch) => {
dispatch(CoreModules.TaskActions.FetchConvertToOsmLoading(true));
Expand Down
12 changes: 9 additions & 3 deletions src/frontend/src/views/ProjectInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import ProjectInfomap from '../components/ProjectInfo/ProjectInfomap';
import environment from '../environment';
import { ProjectActions } from '../store/slices/ProjectSlice';

import { ConvertXMLToJOSM, fetchConvertToOsmDetails, fetchInfoTask, getDownloadProjectSubmission } from '../api/task';
import {
ConvertXMLToJOSM,
fetchConvertToOsmDetails,
fetchInfoTask,
getDownloadProjectSubmission,
getDownloadProjectSubmissionJson,
} from '../api/task';
import AssetModules from '../shared/AssetModules';
import { ProjectById } from '../api/Project';
import ProjectInfoCountCard from '../components/ProjectInfo/ProjectInfoCountCard';
Expand Down Expand Up @@ -49,8 +55,8 @@ const ProjectInfo = () => {
);
} else if (downloadType === 'json') {
dispatch(
getDownloadProjectSubmission(
`${import.meta.env.VITE_API_URL}/submission/download?project_id=${decodedId}&export_json=true`,
getDownloadProjectSubmissionJson(
`${import.meta.env.VITE_API_URL}/submission/download-submission?project_id=${decodedId}`,
),
);
}
Expand Down

0 comments on commit 5e4fd9a

Please sign in to comment.