From a40f23938827ed34a2fff975ff571c5b7ac6404a Mon Sep 17 00:00:00 2001 From: Justin Foell <630830+jrfoell@users.noreply.github.com> Date: Fri, 28 Feb 2020 16:54:51 -0600 Subject: [PATCH] Refine Edit --- src/blocks/activity/edit.js | 57 ++++++++++++++++++++ src/blocks/activity/embed-placeholder.js | 68 ++++++++++++++++++++++++ src/blocks/activity/index.js | 12 +++-- 3 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 src/blocks/activity/edit.js create mode 100644 src/blocks/activity/embed-placeholder.js diff --git a/src/blocks/activity/edit.js b/src/blocks/activity/edit.js new file mode 100644 index 0000000..99e7f9b --- /dev/null +++ b/src/blocks/activity/edit.js @@ -0,0 +1,57 @@ +/* global wp, wpStrava */ +import EmbedPlaceholder from './embed-placeholder'; +import { isEmpty } from 'lodash'; + +/** + * Localized Data. + */ +const { + placeholderActivityImg, +} = wpStrava; + +const Edit = (props) => { + const { + setAttributes, + cannotEmbed, + tryAgain, + attributes: { + url + } + } = props; + + + const submitUrl = (event) => { + if ( event ) { + event.preventDefault(); + } + console.log( 'onsubmit', event ); + setAttributes( { url: event.target.value } ) + }; + + const changeUrl = ( event ) => { + console.log( 'onchange', event ); + console.log( 'Props', props ); + setAttributes( { url: event.target.value } ); + }; + + if ( isEmpty( url ) ) { + return ( + fallback( url, props.onReplace ) } + tryAgain={ tryAgain } + onSubmit={ submitUrl } + /> + ); + } + + return ( + + ); +}; + +export default Edit; diff --git a/src/blocks/activity/embed-placeholder.js b/src/blocks/activity/embed-placeholder.js new file mode 100644 index 0000000..bc2546e --- /dev/null +++ b/src/blocks/activity/embed-placeholder.js @@ -0,0 +1,68 @@ +/** + * WordPress dependencies + */ +const { __, _x } = wp.i18n; +const { Button, Placeholder, ExternalLink } = wp.components; +const { BlockIcon } = wp.blockEditor; + +const EmbedPlaceholder = ( props ) => { + const { + icon, + label, + value, + onSubmit, + onChange, + cannotEmbed, + fallback, + tryAgain, + } = props; + + return ( + } + label={ label } + className="wp-block-embed" + instructions={ __( + 'Paste a link to the content you want to display on your site.' + ) } + > +
+ + +
+
+ + { __( 'Learn more about embeds' ) } + +
+ { cannotEmbed && ( +
+
+ { __( 'Sorry, this content could not be embedded.' ) } +
+ { ' ' } + +
+ ) } +
+ ); +}; + +export default EmbedPlaceholder; diff --git a/src/blocks/activity/index.js b/src/blocks/activity/index.js index 55978f5..b9e235c 100644 --- a/src/blocks/activity/index.js +++ b/src/blocks/activity/index.js @@ -1,5 +1,6 @@ /* global wp, wpStrava */ -import { registerBlockType } from '@wordpress/blocks'; +const { registerBlockType } = wp.blocks; +import edit from './edit'; /** * Localized Data. @@ -8,11 +9,16 @@ const { placeholderActivityImg, } = wpStrava; - registerBlockType( 'wp-strava/activity', { title: 'Strava Activity', icon: 'chart-line', category: 'embed', - edit: () => , + attributes: { + url: { + type: 'string', + default: '', + }, + }, + edit, save: () => , } );