Skip to content

Commit

Permalink
Fix tasks api replacement (#973)
Browse files Browse the repository at this point in the history
* fix (projectById): project/:id api splitted where now taskList is fetched from tasks/task-list/:id

* fix (projectById): dispatch - dispatch projectById parameters changed

* fix (qrCodeComponent): qrcode - fetch qrcode from /tasks/task-list/ api

* code cleanup: comments removed
  • Loading branch information
NSUWAL123 authored Nov 6, 2023
1 parent f7177ed commit 64d646b
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 107 deletions.
5 changes: 2 additions & 3 deletions src/frontend/src/api/Files.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const ProjectFilesById = (url, taskId) => {
cancelToken: source.token,
});
const resp = fileJson.data;
const taskIndex = resp.project_tasks.findIndex((task) => task.id == taskId);
const getQrcodeByIndex = resp.project_tasks[taskIndex].qr_code_base64;
const taskIndex = resp.findIndex((task) => task.id == taskId);
const getQrcodeByIndex = resp[taskIndex].qr_code_base64;
setQrcode(getQrcodeByIndex);
setLoading(false);
} catch (error) {
Expand All @@ -34,6 +34,5 @@ export const ProjectFilesById = (url, taskId) => {

return cleanUp;
}, [taskId]);

return { loading, qrcode };
};
48 changes: 26 additions & 22 deletions src/frontend/src/api/Project.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { ProjectActions } from '../store/slices/ProjectSlice';
import CoreModules from '../shared/CoreModules';
import environment from '../environment';
export const ProjectById = (url, existingProjectList, projectId) => {

export const ProjectById = (existingProjectList, projectId) => {
return async (dispatch) => {
// dispatch(HomeActions.HomeProjectLoading(true))
const fetchProjectById = async (url, existingProjectList) => {
const fetchProjectById = async (projectId, existingProjectList) => {
try {
const project = await CoreModules.axios.get(url);
const project = await CoreModules.axios.get(`${import.meta.env.VITE_API_URL}/projects/${projectId}`);
const taskList = await CoreModules.axios.get(
`${import.meta.env.VITE_API_URL}/tasks/task-list?project_id=${projectId}`,
);
const taskBbox = await CoreModules.axios.get(
`${import.meta.env.VITE_API_URL}/tasks/point_on_surface?project_id=${projectId}`,
);
const resp = project.data;
const persistingValues = resp.project_tasks.map((data) => {
const projectResp = project.data;
const taskListResp = taskList.data;
const persistingValues = taskListResp.map((data) => {
return {
id: data.id,
project_task_name: data.project_task_name,
Expand All @@ -24,7 +28,7 @@ export const ProjectById = (url, existingProjectList, projectId) => {
};
});
// added centroid from another api to projecttaskboundries
const projectTaskBoundries = [{ id: resp.id, taskBoundries: persistingValues }];
const projectTaskBoundries = [{ id: projectResp.id, taskBoundries: persistingValues }];
const mergedBboxIntoTask = projectTaskBoundries[0].taskBoundries.map((projectTask) => {
const filteredTaskIdCentroid = taskBbox.data.find((task) => task.id === projectTask.id).point[0];
return {
Expand All @@ -37,28 +41,28 @@ export const ProjectById = (url, existingProjectList, projectId) => {
);
dispatch(
ProjectActions.SetProjectInfo({
id: resp.id,
outline_geojson: resp.outline_geojson,
priority: resp.priority || 2,
priority_str: resp.priority_str || 'MEDIUM',
title: resp.project_info?.[0]?.name,
location_str: resp.location_str,
description: resp.project_info[0]?.description,
short_description: resp.project_info[0]?.short_description,
num_contributors: resp.num_contributors,
total_tasks: resp.total_tasks,
tasks_mapped: resp.tasks_mapped,
tasks_validated: resp.tasks_validated,
xform_title: resp.xform_title,
tasks_bad: resp.tasks_bad,
id: projectResp.id,
outline_geojson: projectResp.outline_geojson,
priority: projectResp.priority || 2,
priority_str: projectResp.priority_str || 'MEDIUM',
title: projectResp.project_info?.[0]?.name,
location_str: projectResp.location_str,
description: projectResp.project_info[0]?.description,
short_description: projectResp.project_info[0]?.short_description,
num_contributors: projectResp.num_contributors,
total_tasks: projectResp.total_tasks,
tasks_mapped: projectResp.tasks_mapped,
tasks_validated: projectResp.tasks_validated,
xform_title: projectResp.xform_title,
tasks_bad: projectResp.tasks_bad,
}),
);
} catch (error) {
// console.log('error :', error)
}
};

await fetchProjectById(url, existingProjectList);
await fetchProjectById(projectId, existingProjectList);
dispatch(ProjectActions.SetNewProjectTrigger());
};
};
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/components/QrcodeComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ const TasksComponent = ({ type, task, defaultTheme }) => {
const dispatch = CoreModules.useAppDispatch();
const [open, setOpen] = useState(false);
const params = CoreModules.useParams();

const { loading, qrcode } = ProjectFilesById(
`${import.meta.env.VITE_API_URL}/projects/${environment.decode(params.id)}`,
`${import.meta.env.VITE_API_URL}/tasks/task-list?project_id=${environment.decode(params.id)}`,
task,
);

Expand Down
19 changes: 2 additions & 17 deletions src/frontend/src/views/NewProjectDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,11 @@ const Home = () => {
dispatch(ProjectActions.SetNewProjectTrigger());
if (state.projectTaskBoundries.findIndex((project) => project.id == environment.decode(encodedId)) == -1) {
dispatch(ProjectActions.SetProjectTaskBoundries([]));

dispatch(
ProjectById(
`${import.meta.env.VITE_API_URL}/projects/${environment.decode(encodedId)}`,
state.projectTaskBoundries,
environment.decode(encodedId),
),
state.projectTaskBoundries,
);
dispatch(ProjectById(state.projectTaskBoundries, environment.decode(encodedId)));
// dispatch(ProjectBuildingGeojsonService(`${import.meta.env.VITE_API_URL}/projects/${environment.decode(encodedId)}/features`))
} else {
dispatch(ProjectActions.SetProjectTaskBoundries([]));
dispatch(
ProjectById(
`${import.meta.env.VITE_API_URL}/projects/${environment.decode(encodedId)}`,
state.projectTaskBoundries,
environment.decode(encodedId),
),
state.projectTaskBoundries,
);
dispatch(ProjectById(state.projectTaskBoundries, environment.decode(encodedId)));
}
if (Object.keys(state.projectInfo)?.length == 0) {
dispatch(ProjectActions.SetProjectInfo(projectInfo));
Expand Down
18 changes: 2 additions & 16 deletions src/frontend/src/views/ProjectDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,12 @@ const Home = () => {
dispatch(ProjectActions.SetNewProjectTrigger());
if (state.projectTaskBoundries.findIndex((project) => project.id == environment.decode(encodedId)) == -1) {
dispatch(ProjectActions.SetProjectTaskBoundries([]));
dispatch(ProjectById(state.projectTaskBoundries, environment.decode(encodedId)));

dispatch(
ProjectById(
`${import.meta.env.VITE_API_URL}/projects/${environment.decode(encodedId)}`,
state.projectTaskBoundries,
environment.decode(encodedId),
),
state.projectTaskBoundries,
);
// dispatch(ProjectBuildingGeojsonService(`${import.meta.env.VITE_API_URL}/projects/${environment.decode(encodedId)}/features`))
} else {
dispatch(ProjectActions.SetProjectTaskBoundries([]));
dispatch(
ProjectById(
`${import.meta.env.VITE_API_URL}/projects/${environment.decode(encodedId)}`,
state.projectTaskBoundries,
environment.decode(encodedId),
),
state.projectTaskBoundries,
);
dispatch(ProjectById(state.projectTaskBoundries, environment.decode(encodedId)));
}
if (Object.keys(state.projectInfo).length == 0) {
dispatch(ProjectActions.SetProjectInfo(projectInfo));
Expand Down
18 changes: 2 additions & 16 deletions src/frontend/src/views/ProjectInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,12 @@ const ProjectInfo = () => {
dispatch(ProjectActions.SetNewProjectTrigger());
if (state.projectTaskBoundries.findIndex((project) => project.id == environment.decode(encodedId)) == -1) {
dispatch(ProjectActions.SetProjectTaskBoundries([]));
dispatch(ProjectById(state.projectTaskBoundries, environment.decode(encodedId)));

dispatch(
ProjectById(
`${import.meta.env.VITE_API_URL}/projects/${environment.decode(encodedId)}`,
state.projectTaskBoundries,
environment.decode(encodedId),
),
state.projectTaskBoundries,
);
// dispatch(ProjectBuildingGeojsonService(`${import.meta.env.VITE_API_URL}/projects/${environment.decode(encodedId)}/features`))
} else {
dispatch(ProjectActions.SetProjectTaskBoundries([]));
dispatch(
ProjectById(
`${import.meta.env.VITE_API_URL}/projects/${environment.decode(encodedId)}`,
state.projectTaskBoundries,
environment.decode(encodedId),
),
state.projectTaskBoundries,
);
dispatch(ProjectById(state.projectTaskBoundries, environment.decode(encodedId)));
}
if (Object.keys(state.projectInfo).length == 0) {
dispatch(ProjectActions.SetProjectInfo(projectInfo));
Expand Down
18 changes: 2 additions & 16 deletions src/frontend/src/views/Submissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,10 @@ const Submissions = () => {
// Requesting Task Boundaries on Page Load
useEffect(() => {
if (state.projectTaskBoundries.findIndex((project) => project.id == environment.decode(encodedId)) == -1) {
dispatch(
ProjectById(
`${import.meta.env.VITE_API_URL}/projects/${environment.decode(encodedId)}`,
state.projectTaskBoundries,
environment.decode(encodedId),
),
state.projectTaskBoundries,
);
dispatch(ProjectById(state.projectTaskBoundries, environment.decode(encodedId)));
} else {
dispatch(ProjectActions.SetProjectTaskBoundries([]));
dispatch(
ProjectById(
`${import.meta.env.VITE_API_URL}/projects/${environment.decode(encodedId)}`,
state.projectTaskBoundries,
environment.decode(encodedId),
),
state.projectTaskBoundries,
);
dispatch(ProjectById(state.projectTaskBoundries, environment.decode(encodedId)));
}
if (Object.keys(state.projectInfo).length == 0) {
dispatch(ProjectActions.SetProjectInfo(projectInfo));
Expand Down
18 changes: 2 additions & 16 deletions src/frontend/src/views/Tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,15 @@ const TasksSubmission = () => {
//Fetch project for the first time
useEffect(() => {
if (state.projectTaskBoundries.findIndex((project) => project.id == environment.decode(encodedProjectId)) == -1) {
dispatch(
ProjectById(
`${import.meta.env.VITE_API_URL}/projects/${environment.decode(encodedProjectId)}`,
state.projectTaskBoundries,
environment.decode(encodedProjectId),
),
state.projectTaskBoundries,
);
dispatch(ProjectById(state.projectTaskBoundries, environment.decode(encodedProjectId)));
dispatch(
ProjectBuildingGeojsonService(
`${import.meta.env.VITE_API_URL}/projects/${environment.decode(encodedProjectId)}/features`,
),
);
} else {
dispatch(ProjectActions.SetProjectTaskBoundries([]));
dispatch(
ProjectById(
`${import.meta.env.VITE_API_URL}/projects/${environment.decode(encodedProjectId)}`,
state.projectTaskBoundries,
environment.decode(encodedProjectId),
),
state.projectTaskBoundries,
);
dispatch(ProjectById(state.projectTaskBoundries, environment.decode(encodedProjectId)));
}
if (Object.keys(state.projectInfo).length == 0) {
dispatch(ProjectActions.SetProjectInfo(projectInfo));
Expand Down

0 comments on commit 64d646b

Please sign in to comment.