Skip to content

Commit 2a98002

Browse files
authored
Reactions: Apply learnings from other blocks (#1761)
1 parent 1d58b15 commit 2a98002

File tree

10 files changed

+78
-37
lines changed

10 files changed

+78
-37
lines changed

build/reactions/block.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
"wide",
1414
"full"
1515
],
16+
"layout": {
17+
"default": {
18+
"type": "constrained",
19+
"orientation": "vertical",
20+
"justifyContent": "center"
21+
}
22+
},
1623
"interactivity": true
1724
},
1825
"blockHooks": {

build/reactions/index.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '3b68725ce4f6e2d7ba9a');
1+
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '924ffd281ef19da276e3');

build/reactions/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/reactions/render.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@
1111
/* @var array $attributes Block attributes. */
1212
$attributes = wp_parse_args( $attributes, array( 'align' => null ) );
1313

14-
/* @var string $content Inner blocks content. */
14+
/* @var \WP_Block $block Current block. */
15+
$block = $block ?? '';
16+
17+
/* @var string $content Block content. */
18+
$content = $content ?? '';
19+
1520
if ( empty( $content ) ) {
1621
// Fallback for v1.0.0 blocks.
1722
$_title = $attributes['title'] ?? __( 'Fediverse Reactions', 'activitypub' );
1823
$content = '<h6 class="wp-block-heading">' . esc_html( $_title ) . '</h6>';
1924
unset( $attributes['title'], $attributes['className'] );
25+
} else {
26+
$content = implode( PHP_EOL, wp_list_pluck( $block->parsed_block['innerBlocks'], 'innerHTML' ) );
2027
}
2128

2229
// Get the Post ID from attributes or use the current post.
@@ -71,6 +78,11 @@ function ( $comment ) {
7178
);
7279
}
7380

81+
if ( empty( $reactions ) ) {
82+
echo '<!-- Reactions block: No reactions found. -->';
83+
return;
84+
}
85+
7486
// Set up the Interactivity API state.
7587
wp_interactivity_state(
7688
'activitypub/reactions',
@@ -102,11 +114,10 @@ function ( $reaction ) use ( $attributes ) {
102114

103115
// Initialize the context for the block.
104116
$context = array(
105-
'blockId' => $block_id,
106-
'hasReactions' => ! empty( $reactions ),
107-
'reactions' => $reactions,
108-
'postId' => $_post_id,
109-
'modal' => array(
117+
'blockId' => $block_id,
118+
'reactions' => $reactions,
119+
'postId' => $_post_id,
120+
'modal' => array(
110121
'isCompact' => true,
111122
'isOpen' => false,
112123
'items' => array(),
@@ -116,11 +127,10 @@ function ( $reaction ) use ( $attributes ) {
116127
// Add the block wrapper attributes.
117128
$wrapper_attributes = get_block_wrapper_attributes(
118129
array(
119-
'id' => $block_id,
120-
'data-wp-interactive' => 'activitypub/reactions',
121-
'data-wp-context' => wp_json_encode( $context, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ),
122-
'data-wp-init' => 'callbacks.initReactions',
123-
'data-wp-bind--hidden' => '!context.hasReactions',
130+
'id' => $block_id,
131+
'data-wp-interactive' => 'activitypub/reactions',
132+
'data-wp-context' => wp_json_encode( $context, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ),
133+
'data-wp-init' => 'callbacks.initReactions',
124134
)
125135
);
126136
?>

0 commit comments

Comments
 (0)