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 Person block #6

Closed bobbingwide closed 2 years ago

bobbingwide commented 6 years ago

Create a block displaying details of a person / user with contact information

The Person block will work with the oik-user plugin to display information about a particular user. It will combine a set of shortcodes into a single block.

Initial version

Block to be the equivalent of

<h3>Person</h3>
[bw_user user=abc name,bio]
[bw_follow_me user=abc]

where abc is the user name or ID entered in the Advanced Settings User field.

Subsequent versions

bobbingwide commented 6 years ago

The current state of the Person block is as these screenshots. image

image

Changes in this version

  1. Add key= property
  2. Add default: '' to user attribute
  3. Import and use to encapsulate shortcodes. May be unnecessary in this instance.

For edit and save I've set the key= property to avoid getting the particularly unhelpful message

Warning: Each child in an array or iterator should have a unique "key" prop. 
See https://fb.me/react-warning-keys for more information. 

I've read the help multiple times but it really doesn't give any indication how to perform problem determination using Developer tools. There must be a rite of passage that I've not been prepared for.

How do I identify which controls need key= fields and which don't?

Note: Setting multiple key= fields with the same value does at least produce a slightly more useful message.

Warning: Encountered two children with the same key, `perinspector`. 
Keys should be unique so that components maintain their identity across updates. 
Non-unique keys may cause children to be duplicated and/or omitted 
— the behavior is unsupported and could change in a future version.

Perhaps there could be some provision in core for the commonly used tags.

Additional requirements

  1. Display user's name rather than Person in the heading
  2. Provide select list for users.
  3. Use a generalised function for building shortcodes from attributes
bobbingwide commented 5 years ago

It’s time to change this block to a server side rendered function that under the covers will use the shortcode functions. There is already an example of using the bw_user shortcode to display an author box with gravatar,about,bio and a class of author-box.
The block should optionally include the Follow me block as a child element.

bobbingwide commented 5 years ago

The trouble with having the follow me block as a child element is that nested blocks do not automatically inherit attributes of the parent block. So the user= attribute would need to be set for both the Person block and the child follow me block.

Possible solutions

bobbingwide commented 5 years ago

Latest example in the block editor, showing the equivalent shortcode and the rendered output.

image

bobbingwide commented 2 years ago