import {__, _x, _n, _nx} from '@wordpress/i18n'; import Card from 'react-bootstrap/Card'; import {useState, useEffect} from '@wordpress/element'; import Row from 'react-bootstrap/Row'; import Col from 'react-bootstrap/Col'; import Container from 'react-bootstrap/Container'; import Modal from 'react-bootstrap/Modal'; import { VideoLength, VideoSize, VideoViews, VideoDate, } from './VideoAttributes'; import Form from 'react-bootstrap/Form'; import InputGroup from 'react-bootstrap/InputGroup'; import Button from 'react-bootstrap/Button'; import Tab from 'react-bootstrap/Tab'; import Tabs from 'react-bootstrap/Tabs'; import DeleteModal from './DeleteModal'; import Spinner from 'react-bootstrap/Spinner'; export default function VideoModal({ video, setVideos, selectVideo, children, }) { const [show, setShow] = useState(false); const [title, setTitle] = useState(video.title); const [autoPlay, setAutoPlay] = useState(false); const [loop, setLoop] = useState(false); const [muted, setMuted] = useState(false); const [preload, setPreload] = useState(true); const [embedParams, setEmbedParams] = useState(''); const [uploading, setUploading] = useState(false); const [loading, setLoading] = useState(false); const [iframe, setIframe] = useState(null); useEffect(() => { let params = []; if (autoPlay) { params.push('autoplay="true"'); } if (loop) { params.push('loop="true"'); } if (muted) { params.push('muted="true"'); } if (preload) { params.push('preload="true"'); } setEmbedParams(params.join(' ')); }, [autoPlay, loop, muted, preload]); useEffect(() => { const component = ( ); setIframe(component); }, [video]); const getThumbnail = (file) => { return IUP_VIDEO.cdnUrl + '/' + video.guid + '/' + file; }; const handleShow = () => { setShow(true); }; const handleClose = () => { setShow(false); }; function updateVideo() { setLoading(true); const formData = new FormData(); formData.append('title', title); formData.append('video_id', video.guid); formData.append('nonce', IUP_VIDEO.nonce); const options = { method: 'POST', headers: { Accept: 'application/json', }, body: formData, }; fetch(`${ajaxurl}?action=infinite-uploads-video-update`, options) .then((response) => response.json()) .then((data) => { if (data.success) { setVideos((videos) => videos.map((v) => v.guid === video.guid ? {...v, title} : v ) ); } else { console.error(data.data); } setLoading(false); }) .catch((error) => { console.log('Error:', error); setLoading(false); }); } function setThumbnail(thumbnailFileName) { setLoading(true); const formData = new FormData(); formData.append('thumbnail', thumbnailFileName); formData.append('video_id', video.guid); formData.append('nonce', IUP_VIDEO.nonce); const options = { method: 'POST', headers: { Accept: 'application/json', }, body: formData, }; fetch(`${ajaxurl}?action=infinite-uploads-video-update`, options) .then((response) => response.json()) .then((data) => { if (data.success) { setVideos((videos) => videos.map((v) => v.guid === video.guid ? {...v, thumbnailFileName} : v ) ); } else { console.error(data.data); } setLoading(false); }) .catch((error) => { console.log('Error:', error); setLoading(false); }); } function uploadThumbnail(file) { setUploading(true); const formData = new FormData(); formData.append('thumbnailFile', file); formData.append('video_id', video.guid); formData.append('nonce', IUP_VIDEO.nonce); const options = { method: 'POST', headers: { Accept: 'application/json', }, body: formData, }; fetch(`${ajaxurl}?action=infinite-uploads-video-update`, options) .then((response) => response.json()) .then((data) => { if (data.success) { getVideo(); // refresh video data setUploading(false); } else { console.error(data.data); setUploading(false); } }) .catch((error) => { console.log('Error:', error); setUploading(false); }); } function getVideo() { const options = { method: 'GET', headers: { Accept: 'application/json', AccessKey: IUP_VIDEO.apiKey, }, }; fetch( `https://video.bunnycdn.com/library/${IUP_VIDEO.libraryId}/videos/${video.guid}`, options ) .then((response) => response.json()) .then((data) => { //replace video in videos array setVideos((videos) => videos.map((v) => v.guid === video.guid ? {...v, ...data} : v ) ); }) .catch((error) => { console.error(error); }); } let thumbnails = []; for (let i = 1; i <= 5; i++) { thumbnails.push(
{__( 'Choose a new thumbnail to be displayed in the video player:', 'infinite-uploads' )}
{__( 'Copy and paste this code into your post, page, or widget to embed the video. If using Gutenberg editor use our block.', 'infinite-uploads' )}
{__( 'View the statistics for this video.', 'infinite-uploads' )}