import React, { useRef } from "react"; import useCameraStore from "../hooks/useCameraStore"; import { IconButton } from "@mui/material"; import { PendingActions } from "@mui/icons-material"; const SjCamera: React.FC = () => { const { setImageSj } = useCameraStore(); const fileRef = useRef(null); const readFilesAsDataURL = (files: FileList | null): Promise => new Promise((resolve) => { if (!files || files.length === 0) return resolve([]); const list = Array.from(files); const out: string[] = []; let done = 0; list.forEach((f) => { const fr = new FileReader(); fr.onload = (e) => { const dataUrl = (e.target?.result as string) || ""; if (dataUrl) out.push(dataUrl); done += 1; if (done === list.length) resolve(out); }; fr.onerror = () => { done += 1; if (done === list.length) resolve(out); }; fr.readAsDataURL(f); }); }); const handleSuratJalanCapture = async ( event: React.ChangeEvent ) => { const imgs = await readFilesAsDataURL(event.target.files); if (imgs.length > 0) { // APPEND: panggil setImageSj untuk tiap foto imgs.forEach((img) => setImageSj(img)); } // reset supaya bisa pilih file yang sama lagi if (fileRef.current) fileRef.current.value = ""; }; return (
); }; export default SjCamera;