/** * @author Tanya Vykliuk */ import React, { useState } from 'react'; import { bindActionCreators, Dispatch } from 'redux'; import { connect } from 'react-redux'; import VideoRecorder from 'react-video-recorder'; import Button from '@material-ui/core/Button'; import Card from '@material-ui/core/Card'; import CardMedia from '@material-ui/core/CardMedia'; import TextField from '@material-ui/core/TextField'; import Typography from '@material-ui/core/Typography'; import BackupIcon from '@material-ui/icons/Backup'; import ArrowBackIosIcon from '@material-ui/icons/ArrowBackIos'; import { useTranslation } from 'react-i18next'; // @ts-ignore import styles from './FeedForm.module.scss'; import { createFeed, updateFeedAsAdmin } from '../../reducers/feed/service'; import { updateNewFeedPageState, updateShareFormState, updateArMediaState } from '../../reducers/popupsState/service'; const mapDispatchToProps = (dispatch: Dispatch): any => ({ createFeed: bindActionCreators(createFeed, dispatch), updateFeedAsAdmin: bindActionCreators(updateFeedAsAdmin, dispatch), updateNewFeedPageState: bindActionCreators(updateNewFeedPageState, dispatch), updateShareFormState: bindActionCreators(updateShareFormState, dispatch), updateArMediaState: bindActionCreators(updateArMediaState, dispatch), }); interface Props{ feed?:any; createFeed?: typeof createFeed; updateFeedAsAdmin?: typeof updateFeedAsAdmin; updateNewFeedPageState?: typeof updateNewFeedPageState; updateShareFormState?: typeof updateShareFormState; updateArMediaState?: typeof updateArMediaState; } const FeedForm = ({feed, createFeed, updateFeedAsAdmin, updateNewFeedPageState, updateShareFormState, updateArMediaState} : Props) => { const [isSended, setIsSended] = useState(false); const [isRecordVideo, setRecordVideo] = useState(false); const [isVideo, setIsVideo] = useState(false); const [composingTitle, setComposingTitle] = useState(feed ? feed.title : ''); const [composingText, setComposingText] = useState(feed ? feed.description : ''); const [video, setVideo] = useState(null); const [preview, setPreview] = useState(null); const titleRef = React.useRef(); const textRef = React.useRef(); const videoRef = React.useRef(); const { t } = useTranslation(); const handleComposingTitleChange = (event: any): void => setComposingTitle(event.target.value); const handleComposingTextChange = (event: any): void => setComposingText(event.target.value); const handleCreateFeed = () => { const newFeed = { title: composingTitle.trim(), description: composingText.trim(), video, preview } as any; if(feed){ updateFeedAsAdmin(feed.id, newFeed); }else{ createFeed(newFeed); } setComposingTitle(''); setComposingText(''); setVideo(null); setPreview(null); setIsSended(true); const thanksTimeOut = setTimeout(()=>{ setIsSended(false); clearTimeout(thanksTimeOut); }, 2000); updateShareFormState(true); }; const handlePickVideo = async (file) => setVideo(file.target.files[0]); const handlePickPreview = async (file) => setPreview(file.target.files[0]); return
{isSended ? {t('social:feedForm.thanks')} :
{t('social:feedForm.share')} {feed && }

{t('social:feedForm.upload')}

{(videoRef.current as HTMLInputElement).click();}} />

{/*

Record from camera

setRecordVideo(true)} />

*/} {feed && } {t('social:feedForm.preview')} {t('social:feedForm.createFeed')} {/* */} {isRecordVideo === true &&
{ setVideo(videoBlob); setIsVideo(true); }} /> {isVideo && }
}
}
; }; export default connect(null, mapDispatchToProps)(FeedForm);