Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Add an Episode Navigation block.
62 changes: 58 additions & 4 deletions projects/packages/videopress/src/class-channel-blocks.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* The VideoPress channel blocks.
* The channel blocks: channel details, video details, playlist details and episode navigation.
*
* @package automattic/jetpack-videopress
*/
Expand All @@ -23,9 +23,10 @@ class Channel_Blocks {
* @var array<string, string>
*/
const BLOCKS = array(
'videopress/channel-details' => 'render_channel_details',
'videopress/video-details' => 'render_video_details',
'videopress/playlist-details' => 'render_playlist_details',
'videopress/channel-details' => 'render_channel_details',
'videopress/video-details' => 'render_video_details',
'videopress/playlist-details' => 'render_playlist_details',
'videopress/episode-navigation' => 'render_episode_navigation',
);

/**
Expand Down Expand Up @@ -418,4 +419,57 @@ public static function render_playlist_details( $attributes ) {
$markup
);
}

/**
* Previous and next episode on a video page: within the playlist the page
* plays from, else in upload order.
*
* @return string
*/
public static function render_episode_navigation() {
$guid = Channel::queried_guid();
if ( '' === $guid ) {
return '';
}

$playlist = Channel::queried_playlist();
$sequence = $playlist ? array_column( $playlist['videos'], 'guid' ) : array();
if ( ! in_array( $guid, $sequence, true ) ) {
$playlist = null;
$sequence = array_reverse( array_column( Channel_Data::videos(), 'guid' ) );
}
$position = array_search( $guid, $sequence, true );
if ( false === $position ) {
return '';
}

$links = '';
foreach ( array(
'prev' => array( $position - 1, __( '← Previous episode', 'jetpack-videopress-pkg' ) ),
'next' => array( $position + 1, __( 'Next episode →', 'jetpack-videopress-pkg' ) ),
) as $direction => list( $index, $label ) ) {
$other = $sequence[ $index ] ?? '';
$id = '' !== $other ? Channel::attachment_id( $other ) : 0;
if ( ! $id ) {
continue;
}
$links .= sprintf(
'<a class="videopress-episode-navigation__link is-%1$s" href="%2$s" rel="%1$s"><span class="videopress-episode-navigation__label">%3$s</span><span class="videopress-episode-navigation__title">%4$s</span></a>',
esc_attr( $direction ),
esc_url( Channel::video_url( $id, $playlist ? $playlist['key'] : '' ) ),
esc_html( $label ),
esc_html( Channel_Data::video_details( $other, $id )['title'] )
);
}
if ( '' === $links ) {
return '';
}

return sprintf(
'<nav %1$s aria-label="%2$s">%3$s</nav>',
get_block_wrapper_attributes( array( 'class' => 'videopress-episode-navigation' ) ),
esc_attr__( 'Episodes', 'jetpack-videopress-pkg' ),
$links
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "videopress/episode-navigation",
"version": "0.1.0",
"title": "Episode Navigation",
"category": "media",
"icon": "<svg viewBox='0 0 24 24' width='24' height='24' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M4 5.5h9A1.5 1.5 0 0 1 14.5 7v6A1.5 1.5 0 0 1 13 14.5H4A1.5 1.5 0 0 1 2.5 13V7A1.5 1.5 0 0 1 4 5.5Zm3.5 2.6v3.8L10.7 10 7.5 8.1ZM16.5 7H21v1.5h-4.5V7Zm0 4H21v1.5h-4.5V11Zm-14 6H21v1.5H2.5V17Z'></path></svg>",
"description": "Links to the previous and next video, within the playlist being played or in upload order.",
"keywords": [ "episode", "next", "previous", "navigation", "videopress" ],
"textdomain": "jetpack-videopress-pkg",
"supports": {
"html": false,
"align": [ "wide", "full" ],
"anchor": true,
"spacing": {
"margin": true,
"padding": true
},
"color": {
"text": true,
"background": true,
"link": true
},
"typography": {
"fontSize": true,
"lineHeight": true,
"__experimentalDefaultControls": {
"fontSize": true
}
}
},
"attributes": {},
"editorScript": "file:./index.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* WordPress dependencies
*/
import { useBlockProps } from '@wordpress/block-editor';
import { Placeholder } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { VideoPressIcon } from '../video/components/icons';

/**
* Episode Navigation block edit component: the links only exist on a video page.
*
* @return Edit component.
*/
export default function EpisodeNavigationEdit() {
return (
<div { ...useBlockProps() }>
<Placeholder
icon={ VideoPressIcon }
label={ __( 'Episode Navigation', 'jetpack-videopress-pkg' ) }
instructions={ __(
'On a video page, links to the previous and next video, within the playlist being played or in upload order.',
'jetpack-videopress-pkg'
) }
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Internal dependencies
*/
// Overrides Webpack's publicPath before any lazy chunk loads on wpcom.
import '../../set-webpack-public-path';
import registerChannelBlock from '../../channel/register';
import metadata from './block.json';
import Edit from './edit';

registerChannelBlock( metadata, Edit );
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { render, screen } from '@testing-library/react';
import { registerBlockType } from '@wordpress/blocks';
import '../index';

jest.mock( '@wordpress/blocks', () => ( {
registerBlockType: jest.fn(),
} ) );

jest.mock( '@wordpress/block-editor', () => ( {
useBlockProps: ( props: Record< string, unknown > = {} ) => props,
} ) );

describe( 'episode navigation block registration', () => {
it( 'registers videopress/episode-navigation as a dynamic block with an editor placeholder', () => {
const [ name, settings ] = ( registerBlockType as jest.Mock ).mock.calls[ 0 ];
expect( name ).toBe( 'videopress/episode-navigation' );
expect( settings.title ).toBe( 'Episode Navigation' );
// The markup comes from the PHP render callback, so nothing is serialized.
expect( settings.save() ).toBeNull();

const Edit = settings.edit;
render( <Edit /> );
expect(
screen.getByText( /links to the previous and next video/, { ignore: '.a11y-speak-region' } )
).toBeInTheDocument();
} );
} );
18 changes: 18 additions & 0 deletions projects/packages/videopress/tests/php/Channel_Blocks_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,24 @@ public function test_playlist_details() {
$this->assertStringNotContainsString( '__cover', $picked );
}

/**
* Previous and next follow the playlist when the page plays from one, else upload order.
*/
public function test_episode_navigation() {
$this->assertSame( '', Channel_Blocks::render_episode_navigation() );

$this->view_video( 'ccccccc3', 'dungeons' );
$markup = Channel_Blocks::render_episode_navigation();
$this->assertStringContainsString( 'is-prev" href="' . esc_url( Channel::video_url( $this->videos['bbbbbbb2'], 'dungeons' ) ) . '"', $markup );
$this->assertStringContainsString( '<span class="videopress-episode-navigation__title">Goldshire episode</span>', $markup );
$this->assertStringNotContainsString( 'is-next', $markup );

$this->view_video( 'aaaaaaa1' );
$markup = Channel_Blocks::render_episode_navigation();
$this->assertStringContainsString( 'is-next" href="' . esc_url( Channel::video_url( $this->videos['bbbbbbb2'] ) ) . '"', $markup );
$this->assertStringNotContainsString( 'is-prev', $markup );
}

/**
* The editor gets the playlists ( key, title and videos ) for the pickers and the canvas
* previews, before the playlist block's script.
Expand Down
2 changes: 2 additions & 0 deletions projects/packages/videopress/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ module.exports = [
'./src/client/block-editor/blocks/video-details/index.tsx',
'block-editor/blocks/playlist-details/index':
'./src/client/block-editor/blocks/playlist-details/index.tsx',
'block-editor/blocks/episode-navigation/index':
'./src/client/block-editor/blocks/episode-navigation/index.tsx',

'lib/token-bridge': './src/client/lib/token-bridge/index.ts',
'lib/player-bridge': './src/client/lib/player-bridge/index.ts',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: enhancement

VideoPress: Add an Episode Navigation block.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Add an Episode Navigation block.
Loading