Skip to content

Commit

Permalink
fix:In package.json sytled-component version is changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Suraj-kumar00 committed Aug 4, 2024
1 parent ce42542 commit bb1f7af
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 48 deletions.
88 changes: 44 additions & 44 deletions app/camera/CameraUpload.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
// app/components/CameraUpload.js
// // app/components/CameraUpload.js

import React, { useState } from 'react';
import { ref, uploadBytes, getDownloadURL } from 'firebase/storage';
import { storage } from '@/firebase'; // Adjust the path if necessary
import Camera from 'react-camera-pro';
// import React, { useState } from 'react';
// import { ref, uploadBytes, getDownloadURL } from 'firebase/storage';
// import { storage } from '@/firebase'; // Adjust the path if necessary
// import Camera from 'react-camera-pro';

const CameraUpload = ({ onUpload }) => {
const [camera, setCamera] = useState(null);
const [imageURL, setImageURL] = useState('');
// const CameraUpload = ({ onUpload }) => {
// const [camera, setCamera] = useState(null);
// const [imageURL, setImageURL] = useState('');

const captureImage = async () => {
if (camera) {
const imageSrc = camera.takePhoto();
if (imageSrc) {
const imageBlob = await fetch(imageSrc).then(res => res.blob());
const file = new File([imageBlob], 'photo.jpg', { type: 'image/jpeg' });
const fileURL = await uploadImage(file);
setImageURL(fileURL);
if (onUpload) onUpload(fileURL); // Pass the URL to parent if needed
}
}
};
// const captureImage = async () => {
// if (camera) {
// const imageSrc = camera.takePhoto();
// if (imageSrc) {
// const imageBlob = await fetch(imageSrc).then(res => res.blob());
// const file = new File([imageBlob], 'photo.jpg', { type: 'image/jpeg' });
// const fileURL = await uploadImage(file);
// setImageURL(fileURL);
// if (onUpload) onUpload(fileURL); // Pass the URL to parent if needed
// }
// }
// };

const uploadImage = async (file) => {
try {
const storageRef = ref(storage, `images/${file.name}`);
await uploadBytes(storageRef, file);
const fileURL = await getDownloadURL(storageRef);
return fileURL;
} catch (error) {
console.error('Error uploading image: ', error);
}
};
// const uploadImage = async (file) => {
// try {
// const storageRef = ref(storage, `images/${file.name}`);
// await uploadBytes(storageRef, file);
// const fileURL = await getDownloadURL(storageRef);
// return fileURL;
// } catch (error) {
// console.error('Error uploading image: ', error);
// }
// };

return (
<div>
<Camera
ref={(cam) => setCamera(cam)}
idealFacingMode="environment"
imageType="jpeg"
imageCompression={0.8}
/>
<button onClick={captureImage}>Capture and Upload</button>
{imageURL && <img src={imageURL} alt="Captured" style={{ width: '100px', height: '100px' }} />}
</div>
);
};
// return (
// <div>
// <Camera
// ref={(cam) => setCamera(cam)}
// idealFacingMode="environment"
// imageType="jpeg"
// imageCompression={0.8}
// />
// <button onClick={captureImage}>Capture and Upload</button>
// {imageURL && <img src={imageURL} alt="Captured" style={{ width: '100px', height: '100px' }} />}
// </div>
// );
// };

export default CameraUpload;
// export default CameraUpload;
2 changes: 1 addition & 1 deletion app/inventory/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useState, useEffect, useRef } from 'react';
import { firestore, storage } from '@/firebase';
import { Box, Button, Modal, Stack, TextField, Typography, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, ThemeProvider, createTheme } from '@mui/material';
import { collection, getDocs, query, setDoc, doc, getDoc, deleteDoc, updateDoc } from 'firebase/firestore';
import FileUpload from '../images/fileupload'; // Import the FileUpload component
import FileUpload from '../images/fileupload';

const darkTheme = createTheme({
palette: {
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
"firebase": "^10.12.5",
"next": "14.2.5",
"react": "^18",
"react-camera-pro": "^1.4.0",
"react-dom": "^18",
"styled-components": "^5.1.34"
"react-dom": "^18"
},
"devDependencies": {
"eslint": "^8",
Expand Down

0 comments on commit bb1f7af

Please sign in to comment.