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 | 1x 1x | /**
* External dependencies
*/
import { Text } from '@automattic/jetpack-components';
import { Tooltip } from '@wordpress/components';
import { useViewportMatch } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { Icon, info, cautionFilled as warning } from '@wordpress/icons';
import clsx from 'clsx';
/**
* Internal dependencies
*/
import {
LOCAL_VIDEO_ERROR_MIME_TYPE_NOT_SUPPORTED,
VIDEO_PRIVACY_LEVELS,
VIDEO_PRIVACY_LEVEL_PRIVATE,
} from '../../../state/constants';
import { usePlan } from '../../hooks/use-plan';
import useVideos from '../../hooks/use-videos';
import ConnectVideoRow, { LocalVideoRow, Stats } from '../video-row';
import VideoRowError from '../video-row/error';
import styles from './style.module.scss';
/**
* Types
*/
import { LocalVideoListProps, VideoListProps } from './types';
const VideoList = ( {
videos,
hidePrivacy = false,
hideDuration = false,
hidePlays = false,
showActionButton = true,
showQuickActions = true,
loading = false,
onVideoDetailsClick,
}: VideoListProps ) => {
const isSmall = useViewportMatch( 'small', '<' );
const handleClickWithIndex = ( index, callback ) => () => {
callback?.( videos[ index ] );
};
return (
<div className={ styles.list }>
<div className={ styles.header }>
<div className={ styles[ 'title-wrapper' ] }>
<Text>{ __( 'Title', 'jetpack-videopress-pkg' ) }</Text>
</div>
{ ! isSmall && (
<div className={ styles[ 'data-wrapper' ] }>
<Stats
privacy={ hidePrivacy ? null : __( 'Privacy', 'jetpack-videopress-pkg' ) }
duration={ hideDuration ? null : __( 'Duration', 'jetpack-videopress-pkg' ) }
plays={ hidePlays ? null : __( 'Plays', 'jetpack-videopress-pkg' ) }
upload={ __( 'Upload date', 'jetpack-videopress-pkg' ) }
/>
</div>
) }
</div>
{ videos.map( ( video, index ) => {
const isPrivate =
VIDEO_PRIVACY_LEVELS[ video.privacySetting ] === VIDEO_PRIVACY_LEVEL_PRIVATE;
// A video moved to another blog stays in this local library but can no
// longer be edited here: flag it and disable its edit action.
const isMoved = video?.isOwned === false;
return video.error ? (
<VideoRowError key={ video?.guid ?? video?.id } id={ video?.id } title={ video?.title } />
) : (
<ConnectVideoRow
key={ video?.guid ?? video?.id }
id={ video?.id }
title={ video.title }
thumbnail={ video?.posterImage } // TODO: we should use thumbnail when the API is ready https://github.com/Automattic/jetpack/issues/26319
duration={ hideDuration ? null : video.duration }
plays={ hidePlays ? null : video.plays }
isPrivate={ hidePrivacy ? null : isPrivate }
uploadDate={ video.uploadDate }
showQuickActions={ ! video?.uploading && showQuickActions && ! isMoved }
showActionButton={ ! video?.uploading && showActionButton }
disableActionButton={ isMoved }
titleAdornment={
isMoved ? (
<Text variant="body-small" component="span">
{ __( 'Moved to another site', 'jetpack-videopress-pkg' ) }
</Text>
) : null
}
className={ styles.row }
onActionClick={ handleClickWithIndex( index, onVideoDetailsClick ) }
loading={ loading }
/>
);
} ) }
</div>
);
};
export const LocalVideoList = ( {
videos,
showActionButton = true,
showQuickActions = false,
uploading = false,
onActionClick,
}: LocalVideoListProps ) => {
const isSmall = useViewportMatch( 'small', '<' );
const { hasVideoPressPurchase } = usePlan();
const { uploadedVideoCount, isFetching } = useVideos();
const hasVideos = uploadedVideoCount > 0 || isFetching || uploading;
const handleClickWithIndex = index => () => {
onActionClick?.( videos[ index ] );
};
const getTitleAdornment = video => {
if ( video?.isUploadedToVideoPress ) {
return (
<Tooltip
position="top center"
text={ __( 'Video already uploaded to VideoPress', 'jetpack-videopress-pkg' ) }
>
<div className={ styles[ 'title-adornment' ] }>
<Icon icon={ info } />
</div>
</Tooltip>
);
}
if ( video?.readError != null ) {
const errorMessageReadError = __( 'Video cannot be read', 'jetpack-videopress-pkg' );
const errorMessageMimeType = __(
'Video has an unsupported file type',
'jetpack-videopress-pkg'
);
return (
<Tooltip
position="top center"
text={
video?.readError === LOCAL_VIDEO_ERROR_MIME_TYPE_NOT_SUPPORTED
? errorMessageMimeType
: errorMessageReadError
}
>
<div className={ clsx( styles[ 'title-adornment' ], styles.error ) }>
<Icon icon={ warning } />
</div>
</Tooltip>
);
}
return null;
};
return (
<div className={ styles.list }>
<div className={ styles.header }>
<div className={ styles[ 'title-wrapper' ] }>
<Text>{ __( 'Title', 'jetpack-videopress-pkg' ) }</Text>
</div>
{ ! isSmall && (
<div className={ styles[ 'data-wrapper' ] }>
<Stats
privacy=""
duration=""
plays=""
upload={ __( 'Upload date', 'jetpack-videopress-pkg' ) }
/>
</div>
) }
</div>
{ videos.map( ( video, index ) => {
if ( ! video?.id ) {
return null;
}
return (
<LocalVideoRow
key={ `local-video-${ video.id }` }
id={ video.id }
title={ video.title }
showActionButton={ showActionButton }
showQuickActions={ showQuickActions }
uploadDate={ video.uploadDate }
onActionClick={ handleClickWithIndex( index ) }
actionButtonLabel={ __( 'Upload to VideoPress', 'jetpack-videopress-pkg' ) }
disabled={ video?.isUploadedToVideoPress || video?.readError != null }
disableActionButton={ ( hasVideos && ! hasVideoPressPurchase ) || uploading }
titleAdornment={ getTitleAdornment( video ) }
/>
);
} ) }
</div>
);
};
export default VideoList;
|