Skip to content

Commit

Permalink
Merge pull request #359 from hotosm/feat/drone-operator-image-upload-ui
Browse files Browse the repository at this point in the history
Feat/drone operator image upload UI
  • Loading branch information
subashtiwari1010 authored Nov 27, 2024
2 parents 7dbbc74 + d31bc79 commit 7c7e576
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import { useDispatch } from 'react-redux';
import { toast } from 'react-toastify';
Expand All @@ -14,6 +14,7 @@ import { Button } from '@Components/RadixComponents/Button';
import { Label } from '@Components/common/FormUI';
import SwitchTab from '@Components/common/SwitchTab';
import {
resetFilesExifData,
setSelectedTaskDetailToViewOrthophoto,
setUploadedImagesType,
} from '@Store/actions/droneOperatorTask';
Expand Down Expand Up @@ -67,6 +68,10 @@ const DescriptionBox = () => {
},
});

useEffect(() => {
dispatch(resetFilesExifData());
}, [dispatch]);

const { mutate: reStartImageryProcess, isLoading: imageProcessingStarting } =
useMutation({
mutationFn: () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Button } from '@Components/RadixComponents/Button';
import { setSecondPage } from '@Store/actions/droneOperatorTask';
import { useTypedDispatch } from '@Store/hooks';
import { postUnflyableComment } from '@Services/droneOperator';
import { toast } from 'react-toastify';
import { useMutation } from '@tanstack/react-query';
import { useParams } from 'react-router-dom';
import UploadsBox from '../UploadsBox';
Expand Down Expand Up @@ -32,26 +33,26 @@ const QuestionBox = ({
setFlyable(e.target.value);
}

const mutation = useMutation(
const { mutate: mutateComment, isLoading: commentIsUpdating } = useMutation(
(data: any) => postUnflyableComment({ projectId, taskId, data }),
{
onSuccess: () => {
// Optionally, refetch queries or show a success message
console.log('User created successfully');
toast.success('Comment Added successfully');
},
onError: error => {
onError: (error: Record<string, any>) => {
// Handle error
console.error('Error creating user:', error);
toast.error(error?.message);
},
},
);
function handleSubmit() {
if (flyable === 'no') {
const data = {
event: 'comment',
newComment: comment,
comment,
};
mutation.mutate(data);
mutateComment(data);
} else {
dispatch(setSecondPage(true));
}
Expand Down Expand Up @@ -118,7 +119,7 @@ const QuestionBox = ({
className="naxatw-w-fit naxatw-bg-[#D73F3F] naxatw-text-[#FFFFFF]"
onClick={() => handleSubmit()}
disabled={flyable === 'no' && comment.length < 6}
isLoading={mutation.isLoading}
isLoading={commentIsUpdating}
>
Save
</Button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-await-in-loop */
import { Button } from '@Components/RadixComponents/Button';
import { toggleModal } from '@Store/actions/common';
import { setFiles, setFilesExifData } from '@Store/actions/droneOperatorTask';
import { setFilesExifData } from '@Store/actions/droneOperatorTask';
import { useTypedDispatch, useTypedSelector } from '@Store/hooks';
import getExifData from '@Utils/getExifData';
import { toast } from 'react-toastify';
Expand All @@ -12,15 +12,16 @@ const UploadsBox = ({
label?: string;
}) => {
const dispatch = useTypedDispatch();
const files = useTypedSelector(state => state.droneOperatorTask.files);
const files = useTypedSelector(
state => state.droneOperatorTask.filesExifData,
);
const handleFileChange = async (
event: React.ChangeEvent<HTMLInputElement>,
) => {
event.preventDefault();
const selectedFiles = event.target.files;
if (!selectedFiles || selectedFiles?.length === 0) return;
const selectedFilesArray: File[] = Array.from(selectedFiles);
dispatch(setFiles(selectedFilesArray));
try {
const exifData = await Promise.all(
selectedFilesArray.map(async (file: File) => {
Expand Down

0 comments on commit 7c7e576

Please sign in to comment.