bobbingwide / oik-blocks

WordPress 5.0 blocks for oik shortcodes
https://oik-plugins.com/oik-plugins/oik-blocks
GNU General Public License v3.0
1 stars 0 forks source link

Create a Countdown timer block for the [bw_countdown] shortcode #9

Closed bobbingwide closed 2 years ago

bobbingwide commented 6 years ago

Implement a countdown timer block for the [bw_countdown] shortcode.

Requirement

Implement a Countdown block that will demonstrate...

  1. Using different control types for different parameters
  2. A block with JavaScript, albeit still being supported as a shortcode.
Parameter Control type
until Date picker
since Date picker
description text or textarea
expiryUrl URL field
expiryText text
Format text

Proposed solution

Minimum logic for the first version.

bobbingwide commented 6 years ago

Examples

[bw_countdown since="2017-06-17" description="Days since Gutenberg first appeared on WordPress.org" format="D"]

bobbingwide commented 6 years ago

The block currently looks like this. image

When displayed we get. image

bobbingwide commented 6 years ago

I don't really understand why I needed to do the following to avoid getting Warnings from react.

Add key="something" to every tag. This eventually resolved

Warning: Each child in an array or iterator should have a unique "key" prop.

Set a default value for each attribute. This resolved Warning: A component is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa)

And once those have been explained then perhaps we could consider the other stumbling blocks.

How do I code this so that it's only coded once

var atts = props.attributes;
var chatts = '[bw_countdown';   
for (var key of Object.keys( atts )) {
  var value = atts[key];
  if ( value ) {
    chatts = chatts + " " + key + "=\"" + value + '"';
  }
}
chatts = chatts + ']';

How do I generalise this routine so that all I need is the shortcode parameter structure and the block builds itself.

For examples see: https://www.oik-plugins.com/oik_shortcodes/bw_countdown/ https://www.oik-plugins.com/oik_shortcodes/bw_pages/

bobbingwide commented 6 years ago

Note. The attribute names are case sensitive. When I entered a value for Expiry Text re-editing the post caused the block to break. Changing the attribute name from expiryText to expirytext resolves the issue.

I haven't yet implemented expiryUrl.

bobbingwide commented 5 years ago

This block doesn't work with Gutenberg 4.0.0.

bobbingwide commented 5 years ago

Got a message when using the Countdown block

Warning: A non-numeric value encountered in C:\apache\htdocs\wordpress\wp-content\plugins\oik\includes\bw_jquery.inc on line 13
bobbingwide commented 2 years ago

The Countdown block is now delivered in oik. See https://github.com/bobbingwide/oik/issues/138