11// React Imports
2- import React , { useRef } from 'react' ;
2+ import React , { useRef , useState } from 'react' ;
33import Webcam from 'react-webcam' ;
44// Material UI Imports
55import Button from '@mui/material/Button' ;
66import Modal from '@mui/material/Modal' ;
7+ import CameraswitchIcon from '@mui/icons-material/Cameraswitch' ;
78
89// TODO: Determine future of this modal
910// web camera modal
1011const WebcamModal = ( { open, onClose, onCapture } ) => {
1112 const webcamRef = useRef ( null ) ;
13+ const [ facingDirection , setFacingDirection ] = useState ( 'environment' ) ;
14+
15+ const handleCameraDirection = ( ) => {
16+ if ( facingDirection === 'environment' ) {
17+ setFacingDirection ( 'user' ) ;
18+ } else {
19+ setFacingDirection ( 'environment' ) ;
20+ }
21+ } ;
1222
1323 const handleCapture = ( ) => {
1424 const imageSrc = webcamRef . current . getScreenshot ( ) ;
@@ -29,19 +39,27 @@ const WebcamModal = ({ open, onClose, onCapture }) => {
2939 flexDirection : 'column' ,
3040 alignItems : 'center' ,
3141 justifyContent : 'center' ,
32- height : '100vh'
42+ gap : '10px' ,
43+ height : '100dvh'
3344 } }
3445 >
35- < h2 id = "webcam-modal-title" > Webcam</ h2 >
3646 < Webcam
3747 audio = { false }
3848 ref = { webcamRef }
3949 screenshotFormat = "image/jpeg"
40- videoConstraints = { { facingMode : 'user' } }
50+ videoConstraints = { { facingMode : facingDirection } }
4151 />
42- < Button variant = "contained" color = "primary" onClick = { handleCapture } >
43- Take Photo
44- </ Button >
52+ < div style = { { display : 'flex' , gap : '10px' } } >
53+ < Button variant = "contained" color = "primary" onClick = { ( ) => onClose ( ) } >
54+ Cancel
55+ </ Button >
56+ < Button variant = "contained" color = "primary" onClick = { handleCapture } >
57+ Take Photo
58+ </ Button >
59+ < Button variant = "contained" color = "primary" onClick = { handleCameraDirection } >
60+ < CameraswitchIcon />
61+ </ Button >
62+ </ div >
4563 </ div >
4664 </ Modal >
4765 ) ;
0 commit comments