/**
* External dependencies
*/
import {
Text,
Button,
Title,
numberFormat,
useBreakpointMatch,
} from '@automattic/jetpack-components';
import { __, sprintf } from '@wordpress/i18n';
import { Icon, chartBar, chevronDown, chevronUp } from '@wordpress/icons';
import classnames from 'classnames';
import { useState } from 'react';
import { usePermission } from '../../hooks/use-permission';
import useVideo from '../../hooks/use-video';
import Placeholder from '../placeholder';
/**
* Internal dependencies
*/
import { ConnectVideoQuickActions } from '../video-quick-actions';
import VideoThumbnail from '../video-thumbnail';
import styles from './style.module.scss';
import { VideoCardProps } from './types';
/**
* Types
*/
import type React from 'react';
const QuickActions = ( {
id,
onVideoDetailsClick,
className,
}: {
id: VideoCardProps[ 'id' ];
onVideoDetailsClick: VideoCardProps[ 'onVideoDetailsClick' ];
className?: VideoCardProps[ 'className' ];
} ) => {
const { canPerformAction } = usePermission();
return (
{ id && }
);
};
/**
* Video Card component
*
* @param {VideoCardProps} props - Component props.
* @returns {React.ReactNode} - VideoCard react component.
*/
export const VideoCard = ( {
title,
id,
duration,
plays,
thumbnail,
editable,
showQuickActions = true,
loading = false,
isUpdatingPoster = false,
uploading = false,
processing = false,
uploadProgress,
onVideoDetailsClick,
}: VideoCardProps ) => {
const isBlank = ! title && ! duration && ! plays && ! thumbnail && ! loading;
const hasPlays = typeof plays !== 'undefined';
const playsCount = hasPlays
? sprintf(
/* translators: placeholder is a number of plays */
__( '%s plays', 'jetpack-videopress-pkg' ),
numberFormat( plays )
)
: '';
const [ isSm ] = useBreakpointMatch( 'sm' );
const [ isOpen, setIsOpen ] = useState( false );
const disabled = loading || uploading;
return (
<>
setIsOpen( wasOpen => ! wasOpen ) } ) }
>
{ ! isSm &&
}
{ isSm && ! disabled && (
{ isOpen && }
{ ! isOpen && }
) }
{ loading ? (
) : (
{ title }
) }
{ loading ? (
) : (
<>
{ hasPlays && (
{ playsCount }
) }
>
) }
{ showQuickActions && ! isSm && (
) }
{ showQuickActions && isSm && isOpen && (
) }
>
);
};
export const ConnectVideoCard = ( { id, ...restProps }: VideoCardProps ) => {
const { isDeleting, uploading, processing, isUpdatingPoster, data, uploadProgress } = useVideo(
id
);
const loading = ( isDeleting || restProps?.loading ) && ! uploading && ! processing;
const editable = restProps?.editable && ! isDeleting && ! uploading && ! processing;
return (
);
};
export default ConnectVideoCard;