-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
343 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
projects/packages/videopress/src/client/admin/components/video-card/error.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { Button, Title, useBreakpointMatch } from '@automattic/jetpack-components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { Icon, 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 React from 'react'; | ||
|
||
const QuickActions = ( { | ||
id, | ||
onVideoDetailsClick, | ||
className, | ||
}: { | ||
id: VideoCardProps[ 'id' ]; | ||
onVideoDetailsClick: VideoCardProps[ 'onVideoDetailsClick' ]; | ||
className?: VideoCardProps[ 'className' ]; | ||
} ) => { | ||
const { canPerformAction } = usePermission(); | ||
|
||
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={ ! canPerformAction } | ||
> | ||
{ __( 'View error', 'jetpack-videopress-pkg' ) } | ||
</Button> | ||
|
||
{ id && <ConnectVideoQuickActions videoId={ id } /> } | ||
</div> | ||
); | ||
}; | ||
|
||
/** | ||
* Video Card component | ||
* | ||
* @param {VideoCardProps} props - Component props. | ||
* @returns {React.ReactNode} - VideoCardError react component. | ||
*/ | ||
export const VideoCardError = ( { | ||
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 [ anchor, setAnchor ] = useState( null ); | ||
const [ isSm ] = useBreakpointMatch( 'sm' ); | ||
const [ isOpen, setIsOpen ] = useState( false ); | ||
const disabled = false; | ||
|
||
return ( | ||
<> | ||
<div | ||
className={ clsx( styles[ 'video-card__wrapper' ], { | ||
[ styles[ 'is-blank' ] ]: isBlank, | ||
[ styles.disabled ]: isSm, | ||
} ) } | ||
{ ...( 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 } | ||
hasError={ true } | ||
/> | ||
|
||
<div className={ styles[ 'video-card__title-section' ] }> | ||
{ isSm && ( | ||
<div className={ styles.chevron }> | ||
{ isOpen && <Icon icon={ chevronUp } /> } | ||
{ ! isOpen && <Icon icon={ chevronDown } /> } | ||
</div> | ||
) } | ||
|
||
<Title className={ styles[ 'video-card__title' ] } mb={ 0 } size="small"> | ||
{ title } | ||
</Title> | ||
</div> | ||
|
||
<PublishFirstVideoPopover id={ id } anchor={ anchor } /> | ||
|
||
{ showQuickActions && ! isSm && ( | ||
<QuickActions | ||
id={ id } | ||
onVideoDetailsClick={ onVideoDetailsClick } | ||
className={ clsx( [ styles[ 'is-blank' ] ] ) } | ||
/> | ||
) } | ||
</div> | ||
|
||
{ showQuickActions && isSm && isOpen && ( | ||
<QuickActions | ||
id={ id } | ||
onVideoDetailsClick={ onVideoDetailsClick } | ||
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 ( | ||
<VideoCardError | ||
id={ id } | ||
{ ...restProps } | ||
loading={ loading } | ||
uploading={ uploading } | ||
isUpdatingPoster={ isUpdatingPoster } | ||
processing={ processing } | ||
editable={ editable } | ||
privacySetting={ data.privacySetting } | ||
uploadProgress={ uploadProgress } | ||
/> | ||
); | ||
}; | ||
|
||
export default ConnectVideoCard; |
Oops, something went wrong.