diff --git a/client/src/pages/Create/Create.js b/client/src/pages/Create/Create.js index e5b9242..0a87a7b 100644 --- a/client/src/pages/Create/Create.js +++ b/client/src/pages/Create/Create.js @@ -1,8 +1,8 @@ -import React, { useState, useCallback } from 'react' +import React, { useState, useCallback, useEffect } from 'react' import download from 'downloadjs' import { Link } from 'react-router-dom' import './Create.css' -import AsyncSelect from 'react-select/lib/Async' +import Select from 'react-select' import Webcam from '../../components/WebcamCapture' import Countdown from '../../components/Countdown' import Page from '../../components/Page' @@ -27,33 +27,59 @@ function Create({ history }) { const [isWebcamReady, setIsWebcamReady] = useState(false) const [gifId, setGifId] = useState() const [text, setText] = useState('') + const [textLimitError, setTextLimitError] = useState('') const [isProcessingGif, setIsProcessingGif] = useState('') const [isUploading, setUploading] = useState(false) const [warning, setWarning] = useState( window.MediaRecorder ? false : WARNING_BROWSER, ) + const [webCamDenied, setWebCamDenied] = useState(true) + const [webCamSelectPlaceHolder, setWebCamSelectPlaceHolder] = useState( + 'Please accept browser webcam permissions', + ) + const [webCamOptions, setWebCamOptions] = useState([]) - const cameraOptions = () => + useEffect(() => { navigator.mediaDevices - .enumerateDevices() - .then((inputs) => { - const options = [] - inputs - .filter((input) => { - return input.kind === 'videoinput' + .getUserMedia({ + audio: false, + video: true, + }) + .then(() => { + navigator.mediaDevices + .enumerateDevices() + .then((inputs) => { + const options = [] + inputs + .filter((input) => { + return input.kind === 'videoinput' + }) + .forEach((videoInput) => { + options.push({ + value: videoInput, + label: videoInput.label, + }) + }) + + if (options.length < 1) { + setWebCamSelectPlaceHolder('No camera detected...') + setWebCamDenied(true) + } else { + setWebCamDenied(false) + setWebCamSelectPlaceHolder('Select your camera...') + setWebCamOptions(options) + } }) - .forEach((videoInput) => { - options.push({ - value: videoInput, - label: videoInput.label, - }) + .catch((err) => { + console.error('ERROR: No camera input found', err) }) - return options }) .catch((err) => { - console.error('ERROR: No camera input found', err) - return [] + console.error(err) + setWebCamSelectPlaceHolder('You have denied webcam permissions') + setWebCamDenied(true) }) + }, []) const retry = () => { setGifId(null) @@ -135,6 +161,15 @@ function Create({ history }) { download(fileBlob, `${gifId}.gif`) } + const handleText = (input) => { + if (input.length === 30) { + setTextLimitError('Caption must have a maximum limit of 30 characters.') + } else { + setText(input) + setTextLimitError('') + } + } + const header = ( <>

Create Your Own GIF

@@ -188,15 +223,11 @@ function Create({ history }) { )}
- { - return 'No camera detected...' - }} - loadOptions={cameraOptions} />
{isPrerecordingPhase && ( @@ -224,9 +255,12 @@ function Create({ history }) { )} {phase === PHASE_TEXT && ( <> + {textLimitError && ( +

{textLimitError}

+ )}