HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/wp-recipe-maker/assets/js/admin-modal/fields/FieldVideo.js
import React, { Fragment } from 'react';

import Media from '../general/Media';
import FieldTextarea from './FieldTextarea';

import { __wprm } from 'Shared/Translations';
 
const FieldVideo = (props) => {
    const hasUpload = props.id > 0;
    const hasEmbed = ! hasUpload && ( -1 == props.id || props.embed );
    const hasVideo = hasUpload || hasEmbed;

    const selectVideo = (e) => {
        e.preventDefault();

        Media.selectVideo((attachment) => {
            props.onChange( attachment.attributes.id, attachment.attributes.thumb.src );
        });
    }

    return (
        <div className="wprm-admin-modal-field-video">
            {
                hasVideo
                ?
                <Fragment>
                    {
                        hasUpload
                        ?
                        <div className="wprm-admin-modal-field-video-preview">
                            <img
                                onClick={ selectVideo }
                                src={ props.thumb || wprm_admin_modal.images.video }
                            />
                            <a
                                href="#"
                                onClick={ (e) => {
                                    e.preventDefault();
                                    props.onChange( 0, '' );
                                } }
                            >{ __wprm( 'Remove Video' ) }</a>
                        </div>
                        :
                        <Fragment>
                            <FieldTextarea
                                value={ props.embed }
                                onChange={(embed) => {
                                    props.onChange( -1, '', embed );
                                }}
                                placeholder={ __wprm( 'Use URL to the video (e.g. https://www.youtube.com/watch?v=dQw4w9WgXcQ) or the full embed code.' ) }
                            />
                            <a
                                href="#"
                                onClick={ (e) => {
                                    e.preventDefault();
                                    props.onChange( 0, '', '' );
                                } }
                            >{ __wprm( 'Remove Video' ) }</a>
                        </Fragment>
                    }
                </Fragment>
                :
                <Fragment>
                    <button
                        className="button button-secondary button-compact"
                        onClick={ selectVideo }
                    >{ __wprm( 'Upload Video' ) }</button>
                    <button
                        className="button button-secondary button-compact"
                        onClick={ (e) => {
                            e.preventDefault();
                            props.onChange( -1, '' );
                        } }
                    >{ __wprm( 'Embed Video' ) }</button>
                </Fragment>
            }
        </div>
    );
}
export default FieldVideo;