/** * External dependencies */ import { Text, Button, ThemeProvider } from '@automattic/jetpack-components'; import { Popover, Dropdown, Modal } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { image, trash, globe as siteDefaultPrivacyIcon } from '@wordpress/icons'; import classNames from 'classnames'; import { useState, useEffect } from 'react'; /** */ import privatePrivacyIcon from '../../../components/icons/crossed-eye-icon'; import publicPrivacyIcon from '../../../components/icons/uncrossed-eye-icon'; import { VIDEO_PRIVACY_LEVELS, VIDEO_PRIVACY_LEVEL_PRIVATE, VIDEO_PRIVACY_LEVEL_PUBLIC, VIDEO_PRIVACY_LEVEL_SITE_DEFAULT, } from '../../../state/constants'; import usePlaybackToken from '../../hooks/use-playback-token'; import usePosterEdit from '../../hooks/use-poster-edit'; import useVideo from '../../hooks/use-video'; import { VideoThumbnailDropdownButtons } from '../video-thumbnail'; import VideoThumbnailSelectorModal from '../video-thumbnail-selector-modal'; import styles from './style.module.scss'; import { ActionItemProps, PopoverWithAnchorProps, ThumbnailActionsDropdownProps, VideoQuickActionsProps, PrivacyActionsDropdownProps, ConnectVideoQuickActionsProps, } from './types'; const PopoverWithAnchor = ( { anchorRef, children = null }: PopoverWithAnchorProps ) => { if ( ! anchorRef ) { return null; } const popoverProps = { anchorRef, offset: 15, }; return ( { children } ); }; const ActionItem = ( { icon, children, className, ...props }: ActionItemProps ) => { const [ anchorRef, setAnchorRef ] = useState( null ); const [ showPopover, setShowPopover ] = useState( false ); return (
); }; const ThumbnailActionsDropdown = ( { description, onUpdate, isUpdatingPoster, }: ThumbnailActionsDropdownProps ) => { const [ anchorRef, setAnchorRef ] = useState( null ); const [ showPopover, setShowPopover ] = useState( false ); return ( ( <> ) } /> ); }; const VideoQuickActions = ( { className, privacySetting, isUpdatingPrivacy, isUpdatingPoster, onUpdateVideoThumbnail, onUpdateVideoPrivacy, onDeleteVideo, }: VideoQuickActionsProps ) => { return (
{ __( 'Delete video', 'jetpack-videopress-pkg' ) }
); }; export const ConnectVideoQuickActions = ( props: ConnectVideoQuickActionsProps ) => { const { videoId } = props; if ( ! Number.isFinite( videoId ) ) { return null; } const { data, updateVideoPrivacy, deleteVideo, isUpdatingPrivacy, isUpdatingPoster } = useVideo( videoId ); const { isFetchingPlaybackToken } = usePlaybackToken( data ); const [ showDeleteModal, setShowDeleteModal ] = useState( false ); const { frameSelectorIsOpen, handleCloseSelectFrame, handleOpenSelectFrame, handleVideoFrameSelected, selectedTime, handleConfirmFrame, updatePosterImageFromFrame, selectAndUpdatePosterImageFromLibrary, } = usePosterEdit( { video: data } ); const onUpdateVideoThumbnail: VideoQuickActionsProps[ 'onUpdateVideoThumbnail' ] = async action => { switch ( action ) { case 'select-from-video': return handleOpenSelectFrame(); case 'upload-image': return selectAndUpdatePosterImageFromLibrary(); } }; useEffect( () => { if ( selectedTime == null ) { return; } updatePosterImageFromFrame(); }, [ selectedTime ] ); if ( showDeleteModal ) { return ( setShowDeleteModal( false ) } className={ styles[ 'delete-video-modal' ] } >
{ __( 'This action cannot be undone.', 'jetpack-videopress-pkg' ) }
); } if ( frameSelectorIsOpen ) { return ( <> ); } const { privacySetting } = data; return ( setShowDeleteModal( true ) } privacySetting={ privacySetting } isUpdatingPrivacy={ isUpdatingPrivacy || isFetchingPlaybackToken } isUpdatingPoster={ isUpdatingPoster } /> ); }; export default VideoQuickActions;