Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x | /**
* External dependencies
*/
import { Text, Button, Title, LoadingPlaceholder } from '@automattic/jetpack-components';
import { formatNumber } from '@automattic/number-formatters';
import { useViewportMatch } from '@wordpress/compose';
import { __, sprintf } from '@wordpress/i18n';
import { Icon, chartBar, chevronDown, chevronUp } from '@wordpress/icons';
import clsx from 'clsx';
import { useState } from 'react';
import { usePermission } from '../../hooks/use-permission';
import useVideo from '../../hooks/use-video';
/**
* Internal dependencies
*/
import PublishFirstVideoPopover from '../publish-first-video-popover';
import { ConnectVideoQuickActions } from '../video-quick-actions';
import VideoThumbnail from '../video-thumbnail';
import styles from './style.module.scss';
import { VideoCardProps } from './types';
/**
* Types
*/
import type { ReactNode } from 'react';
const QuickActions = ( {
id,
onVideoDetailsClick,
className,
isOwned = true,
}: {
id: VideoCardProps[ 'id' ];
onVideoDetailsClick: VideoCardProps[ 'onVideoDetailsClick' ];
className?: VideoCardProps[ 'className' ];
isOwned?: VideoCardProps[ 'isOwned' ];
} ) => {
const { canPerformAction } = usePermission();
// A video that was moved to another blog stays in this local library but can no
// longer be edited here, so disable the edit action for it.
const editDisabled = ! canPerformAction || isOwned === false;
return (
<div className={ clsx( styles[ 'video-card__quick-actions-section' ], className ) }>
<Button
variant="primary"
size="small"
onClick={ onVideoDetailsClick }
className={ styles[ 'video-card__quick-actions__edit-button' ] }
disabled={ editDisabled }
>
{ __( 'Edit video details', 'jetpack-videopress-pkg' ) }
</Button>
{ id && isOwned !== false && <ConnectVideoQuickActions videoId={ id } /> }
</div>
);
};
/**
* Video Card component
*
* @param {VideoCardProps} props - Component props.
* @return {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,
isOwned = true,
}: VideoCardProps ) => {
const isBlank = ! title && ! duration && ! plays && ! thumbnail && ! loading;
const hasPlays = typeof plays !== 'undefined';
const playsCount = hasPlays
? sprintf(
/* translators: %s: the number of plays */
__( '%s plays', 'jetpack-videopress-pkg' ),
formatNumber( plays )
)
: '';
const [ anchor, setAnchor ] = useState( null );
const isSm = useViewportMatch( 'small', '<' );
const [ isOpen, setIsOpen ] = useState( false );
const disabled = loading || uploading;
return (
<>
<div
className={ clsx( styles[ 'video-card__wrapper' ], {
[ styles[ 'is-blank' ] ]: isBlank,
[ styles.disabled ]: isSm || disabled,
} ) }
{ ...( isSm && ! disabled && { onClick: () => setIsOpen( wasOpen => ! wasOpen ) } ) }
>
{ ! isSm && <div className={ styles[ 'video-card__background' ] } /> }
<VideoThumbnail
className={ styles[ 'video-card__thumbnail' ] }
thumbnail={ thumbnail }
loading={ loading || isUpdatingPoster }
uploading={ uploading }
processing={ processing }
duration={ loading ? null : duration }
editable={ loading ? false : editable }
uploadProgress={ uploadProgress }
ref={ setAnchor }
/>
<div className={ styles[ 'video-card__title-section' ] }>
{ isSm && ! disabled && (
<div className={ styles.chevron }>
{ isOpen && <Icon icon={ chevronUp } /> }
{ ! isOpen && <Icon icon={ chevronDown } /> }
</div>
) }
{ loading ? (
<LoadingPlaceholder width="60%" height={ 30 } />
) : (
<Title className={ styles[ 'video-card__title' ] } mb={ 0 } size="small">
{ title }
</Title>
) }
{ loading ? (
<LoadingPlaceholder width={ 96 } height={ 24 } />
) : (
<>
{ hasPlays && (
<Text component="div" className={ styles[ 'video-card__video-plays-counter' ] }>
<Icon icon={ chartBar } />
{ playsCount }
</Text>
) }
{ isOwned === false && (
<Text component="div">
{ __( 'Moved to another site', 'jetpack-videopress-pkg' ) }
</Text>
) }
</>
) }
</div>
<PublishFirstVideoPopover id={ id } anchor={ anchor } />
{ showQuickActions && ! isSm && (
<QuickActions
id={ id }
onVideoDetailsClick={ onVideoDetailsClick }
isOwned={ isOwned }
className={ clsx( {
[ styles[ 'is-blank' ] ]: loading,
} ) }
/>
) }
</div>
{ showQuickActions && isSm && isOpen && (
<QuickActions
id={ id }
onVideoDetailsClick={ onVideoDetailsClick }
isOwned={ isOwned }
className={ styles.small }
/>
) }
</>
);
};
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 (
<VideoCard
id={ id }
{ ...restProps }
loading={ loading }
uploading={ uploading }
isUpdatingPoster={ isUpdatingPoster }
processing={ processing }
editable={ editable }
privacySetting={ data.privacySetting }
uploadProgress={ uploadProgress }
/>
);
};
export default ConnectVideoCard;
|