{"version":3,"file":"ImageUploader-Dm4-SEB-.js","sources":["../../../app/javascript/shared/ImageUploader.jsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport { ref, uploadBytes, getDownloadURL } from \"firebase/storage\";\nimport { updateDoc, doc } from \"firebase/firestore\";\nimport { db, storage } from \"./firebase\";\n\nconst ImageUploader = ({ user, onUploadSuccess, onUploadError, children }) => {\n const fileInputRef = useRef(null);\n\n const handleImageClick = () => {\n fileInputRef.current.click();\n };\n\n const handleImageUpload = async (event) => {\n const file = event.target.files[0];\n if (file && user) {\n try {\n if (file.size > 5 * 1024 * 1024) {\n throw new Error(\"File size exceeds 5MB limit.\");\n }\n\n const allowedTypes = [\"image/jpeg\", \"image/png\", \"image/gif\"];\n if (!allowedTypes.includes(file.type)) {\n throw new Error(\"Invalid file type. Please upload a JPEG, PNG, or GIF image.\");\n }\n\n const fileName = `${Date.now()}_${file.name}`;\n const storageRef = ref(storage, `profile_photos/${user.uid}/${fileName}`);\n\n await uploadBytes(storageRef, file);\n const downloadURL = await getDownloadURL(storageRef);\n await updateDoc(doc(db, \"users\", user.uid), {\n profilePhotoURL: downloadURL,\n });\n onUploadSuccess(downloadURL);\n } catch (error) {\n console.error(\"Error uploading profile photo:\", error);\n onUploadError(error.message);\n }\n }\n };\n\n return (\n <>\n \n