Skip to content

Commit

Permalink
solved cover image upload type error (#10630)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanuj1718 authored Feb 20, 2025
1 parent ba6b0fc commit 213fb25
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions src/components/Common/AvatarEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ const AvatarEditModal = ({
const [selectedFile, setSelectedFile] = useState<File>();
const [preview, setPreview] = useState<string>();
const [isCameraOpen, setIsCameraOpen] = useState<boolean>(false);
const webRef = useRef<any>(null);
const [previewImage, setPreviewImage] = useState(null);
const webRef = useRef<Webcam>(null);
const [previewImage, setPreviewImage] = useState<string | null>(null);
const [isCaptureImgBeingUploaded, setIsCaptureImgBeingUploaded] =
useState(false);
const [constraint, setConstraint] = useState<IVideoConstraint>(
Expand All @@ -81,16 +81,35 @@ const AvatarEditModal = ({
}, []);

const captureImage = () => {
setPreviewImage(webRef.current.getScreenshot());
const canvas = webRef.current.getCanvas();
canvas?.toBlob((blob: Blob) => {
const myFile = new File([blob], "image.png", {
type: blob.type,
});
setSelectedFile(myFile);
if (webRef.current) {
setPreviewImage(webRef.current.getScreenshot());
}
const canvas = webRef.current?.getCanvas();
canvas?.toBlob((blob) => {
if (blob) {
const myFile = new File([blob], "image.png", {
type: blob.type,
});
setSelectedFile(myFile);
} else {
toast.error(t("failed_to_capture_image"));
}
});
};

const stopCamera = useCallback(() => {
try {
if (webRef.current) {
const openCamera = webRef.current?.video?.srcObject as MediaStream;
if (openCamera) {
openCamera.getTracks().forEach((track) => track.stop());
}
}
} catch {
toast.error("Failed to stop camera");
} finally {
setIsCameraOpen(false);
}
}, []);
const closeModal = () => {
setPreview(undefined);
setIsProcessing(false);
Expand Down Expand Up @@ -410,7 +429,7 @@ const AvatarEditModal = ({
onClick={() => {
setPreviewImage(null);
setIsCameraOpen(false);
webRef.current.stopCamera();
stopCamera();
}}
disabled={isProcessing}
>
Expand Down

0 comments on commit 213fb25

Please sign in to comment.