-
Notifications
You must be signed in to change notification settings - Fork 809
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VideoPress: Add "publish first video" popover (#27714)
* rename actions to verbs * add firstUploadedVideoId to state * add getFirstUploadedVideoId selector * add dismissedFirstVideoPopover state * add forwardRef on VideoThumbnail component * add useFirstVideoPopover custom hook * add href and external link flag to action popover button * add PublishFirstVideoPopover component and remove useFirstVideoPopover hook * add first video popover to video card and video row * changelog * changelog * bump versions * remove comment * refactor translation to avoid build error * fix action popover storybook controls * add video guid to new post link query args * create and initialize block editor content class * bump versions * add firstVideoProcessed state and show video post popover only after processed * add nonce to new post link
- Loading branch information
Showing
33 changed files
with
382 additions
and
106 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/js-packages/components/changelog/add-videopress-publish-first-video-popover
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,4 @@ | ||
Significance: patch | ||
Type: added | ||
|
||
RNA: Add props to ActionPopover related to link on action button |
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
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
4 changes: 4 additions & 0 deletions
4
projects/packages/videopress/changelog/add-videopress-publish-first-video-popover
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,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
VideoPress: Add first video popover |
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
56 changes: 56 additions & 0 deletions
56
projects/packages/videopress/src/class-block-editor-content.php
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,56 @@ | ||
<?php | ||
/** | ||
* VideoPress Block Editor Content | ||
* | ||
* @package automattic/jetpack-videopress | ||
*/ | ||
|
||
namespace Automattic\Jetpack\VideoPress; | ||
|
||
/** | ||
* VideoPress block editor class for content generation | ||
*/ | ||
class Block_Editor_Content { | ||
/** | ||
* Initializer | ||
* | ||
* This method should be called only once by the Initializer class. Do not call this method again. | ||
*/ | ||
public static function init() { | ||
if ( ! Status::is_active() ) { | ||
return; | ||
} | ||
|
||
add_filter( 'default_content', array( static::class, 'video_block_by_guid' ), 10, 2 ); | ||
} | ||
|
||
/** | ||
* Generates a video block content with the given guid | ||
* | ||
* @param string $content Post content. | ||
* @param WP_Post $post Post. | ||
* @return string | ||
*/ | ||
public static function video_block_by_guid( $content, $post ) { | ||
if ( isset( $_GET['videopress_guid'], $_GET['_wpnonce'] ) | ||
&& wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'videopress-content-nonce' ) | ||
&& current_user_can( 'edit_post', $post->ID ) | ||
&& '' === $content | ||
) { | ||
$guid = sanitize_text_field( wp_unslash( $_GET['videopress_guid'] ) ); | ||
|
||
if ( ! empty( $guid ) ) { | ||
// ref /client/lib/url/index.ts | ||
$content = '<!-- wp:videopress/video {"guid":"' . $guid . '"} --> | ||
<figure class="wp-block-videopress-video wp-block-jetpack-videopress jetpack-videopress-player"> | ||
<div class="jetpack-videopress-player__wrapper"> | ||
https://videopress.com/v/' . $guid . '?resizeToParent=true&cover=true&preloadContent=metadata&useAverageColor=true | ||
</div> | ||
</figure> | ||
<!-- /wp:videopress/video -->'; | ||
} | ||
} | ||
|
||
return $content; | ||
} | ||
} |
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
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
73 changes: 73 additions & 0 deletions
73
...cts/packages/videopress/src/client/admin/components/publish-first-video-popover/index.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,73 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { ActionPopover, Text } from '@automattic/jetpack-components'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { addQueryArgs } from '@wordpress/url'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { STORE_ID } from '../../../state'; | ||
import useVideo from '../../hooks/use-video'; | ||
import useVideos from '../../hooks/use-videos'; | ||
import styles from './styles.module.scss'; | ||
/** | ||
* Types | ||
*/ | ||
import { PublishFirstVideoPopoverProps } from './types'; | ||
import type React from 'react'; | ||
|
||
/** | ||
* Publish First Video Popover component | ||
* | ||
* @param {PublishFirstVideoPopoverProps} props - Component props. | ||
* @returns {React.ReactNode} - PublishFirstVideoPopover react component. | ||
*/ | ||
const PublishFirstVideoPopover = ( { | ||
id, | ||
position = null, | ||
anchor = null, | ||
}: PublishFirstVideoPopoverProps ) => { | ||
const dispatch = useDispatch( STORE_ID ); | ||
const { data } = useVideo( Number( id ) ); | ||
const { firstUploadedVideoId, firstVideoProcessed, dismissedFirstVideoPopover } = useVideos(); | ||
const showAddToPostPopover = | ||
Number( firstUploadedVideoId ) === Number( id ) && | ||
firstVideoProcessed && | ||
! dismissedFirstVideoPopover; | ||
|
||
const closePopover = () => dispatch.dismissFirstVideoPopover(); | ||
|
||
const nonce = window.jetpackVideoPressInitialState?.contentNonce ?? ''; | ||
const newPostURL = addQueryArgs( 'post-new.php', { | ||
videopress_guid: data.guid, | ||
_wpnonce: nonce, | ||
} ); | ||
|
||
return ( | ||
showAddToPostPopover && ( | ||
<ActionPopover | ||
title={ __( 'Publish your new video', 'jetpack-videopress-pkg' ) } | ||
buttonContent={ __( 'Add video to post', 'jetpack-videopress-pkg' ) } | ||
buttonHref={ newPostURL } | ||
buttonExternalLink | ||
anchor={ anchor } | ||
onClose={ closePopover } | ||
onClick={ closePopover } | ||
noArrow={ false } | ||
className={ styles[ 'action-popover' ] } | ||
position={ position } | ||
> | ||
<Text> | ||
{ __( | ||
"Now that your video has been uploaded to VideoPress, it's time to show it to the world.", | ||
'jetpack-videopress-pkg' | ||
) } | ||
</Text> | ||
</ActionPopover> | ||
) | ||
); | ||
}; | ||
|
||
export default PublishFirstVideoPopover; |
3 changes: 3 additions & 0 deletions
3
...ges/videopress/src/client/admin/components/publish-first-video-popover/styles.module.scss
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,3 @@ | ||
.action-popover { | ||
cursor: auto; | ||
} |
10 changes: 10 additions & 0 deletions
10
...ects/packages/videopress/src/client/admin/components/publish-first-video-popover/types.ts
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,10 @@ | ||
/** | ||
* Types | ||
*/ | ||
import type { Popover } from '@wordpress/components'; | ||
|
||
export type PublishFirstVideoPopoverProps = { | ||
id: number | string; | ||
position?: Popover.Position; | ||
anchor?: Element; | ||
}; |
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
Oops, something went wrong.