Skip to content

Commit

Permalink
Fix Camera Capture and Upload Workflow (#10326)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajku-dev authored Jan 31, 2025
1 parent 55d5790 commit 2298ed5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/components/Files/CameraCaptureDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ export interface CameraCaptureDialogProps {
onHide: () => void;
onCapture: (file: File, fileName: string) => void;
onResetCapture: () => void;
setPreview?: (isPreview: boolean) => void;
}

export default function CameraCaptureDialog(props: CameraCaptureDialogProps) {
const { show, onHide, onCapture, onResetCapture } = props;
const { show, onHide, onCapture, onResetCapture, setPreview } = props;
const isLaptopScreen = useBreakpoints({ lg: true, default: false });

const [cameraFacingMode, setCameraFacingMode] = useState(
Expand Down Expand Up @@ -149,6 +150,7 @@ export default function CameraCaptureDialog(props: CameraCaptureDialogProps) {
variant="primary"
onClick={() => {
captureImage();
setPreview?.(true);
}}
className="m-2"
>
Expand All @@ -164,6 +166,7 @@ export default function CameraCaptureDialog(props: CameraCaptureDialogProps) {
onClick={() => {
setPreviewImage(null);
onResetCapture();
setPreview?.(false);
}}
className="m-2"
>
Expand All @@ -174,6 +177,7 @@ export default function CameraCaptureDialog(props: CameraCaptureDialogProps) {
onClick={() => {
setPreviewImage(null);
onHide();
setPreview?.(false);
}}
className="m-2"
>
Expand Down Expand Up @@ -215,6 +219,7 @@ export default function CameraCaptureDialog(props: CameraCaptureDialogProps) {
variant="primary"
onClick={() => {
captureImage();
setPreview?.(true);
}}
>
<CareIcon icon="l-capture" className="text-lg" />
Expand All @@ -230,6 +235,7 @@ export default function CameraCaptureDialog(props: CameraCaptureDialogProps) {
onClick={() => {
setPreviewImage(null);
onResetCapture();
setPreview?.(false);
}}
>
{t("retake")}
Expand All @@ -239,6 +245,7 @@ export default function CameraCaptureDialog(props: CameraCaptureDialogProps) {
onClick={() => {
onHide();
setPreviewImage(null);
setPreview?.(false);
}}
>
{t("submit")}
Expand All @@ -254,6 +261,7 @@ export default function CameraCaptureDialog(props: CameraCaptureDialogProps) {
setPreviewImage(null);
onResetCapture();
onHide();
setPreview?.(false);
}}
>
{`${t("close")} ${t("camera")}`}
Expand Down
8 changes: 6 additions & 2 deletions src/components/Files/FilesTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,16 @@ export const FilesTab = (props: FilesTabProps) => {
});

useEffect(() => {
if (fileUpload.files.length > 0 && fileUpload.files[0] !== undefined) {
if (
fileUpload.files.length > 0 &&
fileUpload.files[0] !== undefined &&
!fileUpload.previewing
) {
setOpenUploadDialog(true);
} else {
setOpenUploadDialog(false);
}
}, [fileUpload.files]);
}, [fileUpload.files, fileUpload.previewing]);

useEffect(() => {
if (!openUploadDialog) {
Expand Down
5 changes: 5 additions & 0 deletions src/hooks/useFileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type FileUploadReturn = {
removeFile: (index: number) => void;
clearFiles: () => void;
uploading: boolean;
previewing?: boolean;
};

// Array of image extensions
Expand Down Expand Up @@ -92,6 +93,7 @@ export default function useFileUpload(
const [cameraModalOpen, setCameraModalOpen] = useState(false);
const [audioModalOpen, setAudioModalOpen] = useState(false);
const [uploading, setUploading] = useState(false);
const [previewing, setPreviewing] = useState(false);

const [files, setFiles] = useState<File[]>([]);
const queryClient = useQueryClient();
Expand Down Expand Up @@ -285,6 +287,7 @@ export default function useFileUpload(
setFiles(errors);
setUploadFileNames(errors?.map((f) => f.name) ?? []);
setError(t("file_error__network"));
setCameraModalOpen(false);
};

const clearFiles = () => {
Expand All @@ -302,6 +305,7 @@ export default function useFileUpload(
setFiles((prev) => [...prev, file]);
}}
onResetCapture={clearFiles}
setPreview={setPreviewing}
/>
<AudioCaptureDialog
show={audioModalOpen}
Expand Down Expand Up @@ -356,5 +360,6 @@ export default function useFileUpload(
},
clearFiles,
uploading,
previewing,
};
}

0 comments on commit 2298ed5

Please sign in to comment.