Skip to content

Commit 5951db7

Browse files
committed
Update webcam modal to include a directional button for user-facing and environment facing cams; Include cancel button to escape from modal; Upate size of modal for devices
1 parent 007d6e6 commit 5951db7

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/components/Modals/WebcamModal.jsx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
// React Imports
2-
import React, { useRef } from 'react';
2+
import React, { useRef, useState } from 'react';
33
import Webcam from 'react-webcam';
44
// Material UI Imports
55
import Button from '@mui/material/Button';
66
import 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
1011
const 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

Comments
 (0)