PluginProbe
BeyondWords – AI audio for publishers / 7.0.0
BeyondWords – AI audio for publishers v7.0.0
7.1.0 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.7.0 All 43 releases
speechkit / src / editor / components / preview-panel / index.js

index.js in BeyondWords – AI audio for publishers 7.0.0, at src/editor/components/preview-panel/index.js

71 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress dependencies
3 */
4 import { __ } from '@wordpress/i18n';
5 import { PanelBody, PanelRow } from '@wordpress/components';
6 import { useSelect } from '@wordpress/data';
7
8 /**
9 * Internal dependencies
10 */
11 import ErrorNotice from '../error-notice';
12 import PlayAudio from '../play-audio';
13
14 /**
15 * Whether the post has audio/video ready to preview.
16 *
17 * Matches PlayAudioCheck so the panel hides when PlayAudio would render nothing;
18 * legacy `podcast_id` keys are recognised for upgraded posts.
19 *
20 * @param {Function} select Redux-style select() from `@wordpress/data`.
21 *
22 * @return {boolean} True when a content/podcast id is set on the post.
23 */
24 function hasGeneratedContent( select ) {
25 const meta = select( 'core/editor' ).getEditedPostAttribute( 'meta' );
26 return Boolean(
27 meta?.beyondwords_content_id ||
28 meta?.beyondwords_podcast_id ||
29 meta?.speechkit_podcast_id
30 );
31 }
32
33 /**
34 * Whether the post has a BeyondWords error message to surface.
35 *
36 * @param {Function} select Redux-style select() from `@wordpress/data`.
37 *
38 * @return {boolean} True when an error message is set on the post.
39 */
40 function hasError( select ) {
41 const meta = select( 'core/editor' ).getEditedPostAttribute( 'meta' );
42 return Boolean(
43 meta?.beyondwords_error_message || meta?.speechkit_error_message
44 );
45 }
46
47 export function PreviewPanel() {
48 // An error alone also shows the panel, mirroring the document-settings display.
49 const showPanel = useSelect(
50 ( select ) => hasGeneratedContent( select ) || hasError( select ),
51 []
52 );
53
54 if ( ! showPanel ) {
55 return null;
56 }
57
58 return (
59 <PanelBody
60 title={ __( 'Preview', 'speechkit' ) }
61 initialOpen={ true }
62 className="beyondwords beyondwords-sidebar__preview"
63 >
64 <ErrorNotice wrapper={ PanelRow } />
65 <PlayAudio wrapper={ PanelRow } />
66 </PanelBody>
67 );
68 }
69
70 export default PreviewPanel;
71