/** * WordPress dependencies. */ const { element: { createElement, Fragment, useState, }, i18n: { __, }, components: { Placeholder, Disabled, SandBox, Button, ExternalLink, Spinner, ToolbarGroup, ToolbarButton, }, compose: { compose, }, data: { withSelect, }, blockEditor: { RichText, BlockControls, } } = wp; /** * BuddyPress dependencies. */ const { blockData: { embedScriptURL, } } = bp; const EditEmbedActivity = ( { attributes, setAttributes, isSelected, preview, fetching } ) => { const { url, caption } = attributes; const label = __( 'BuddyPress Activity URL', 'buddypress' ); const [ value, setURL ] = useState( url ); const [ isEditingURL, setIsEditingURL ] = useState( ! url ); const onSubmit = ( event ) => { if ( event ) { event.preventDefault(); } setIsEditingURL( false ); setAttributes( { url: value } ); }; const switchBackToURLInput = ( event ) => { if ( event ) { event.preventDefault(); } setIsEditingURL( true ); }; const editToolbar = ( ); if ( isEditingURL ) { return (
setURL( event.target.value ) } />
{ __( 'Learn more about activity embeds', 'buddypress' ) }
); } if ( fetching ) { return (

{ __( 'Embedding…', 'buddypress' ) }

); } if ( ! preview || ! preview['x_buddypress'] || 'activity' !== preview['x_buddypress'] ) { return ( { editToolbar }

{ __( 'The URL you provided is not a permalink to a public BuddyPress Activity. Please use another URL.', 'buddypress' ) }

); } return ( { ! isEditingURL && editToolbar }
{ ( ! RichText.isEmpty( caption ) || isSelected ) && ( setAttributes( { caption: value } ) } inlineToolbar /> ) }
); } const editEmbedActivityBlock = compose( [ withSelect( ( select, ownProps ) => { const { url } = ownProps.attributes; const { getEmbedPreview, isRequestingEmbedPreview, } = select( 'core' ); const preview = !! url && getEmbedPreview( url ); const fetching = !! url && isRequestingEmbedPreview( url ); return { preview: preview, fetching: fetching, }; } ), ] )( EditEmbedActivity ); export default editEmbedActivityBlock;