Skip to content

Commit 35b5390

Browse files
authored
Sync remote reply account info across all blocks on page (#2211)
1 parent 2520b82 commit 35b5390

File tree

6 files changed

+38
-28
lines changed

6 files changed

+38
-28
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: changed
3+
4+
Remote reply blocks now sync account info across all blocks on the same page

build/remote-reply/render.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,20 @@
5555
'commentURL' => $selected_comment,
5656
'copyButtonText' => __( 'Copy', 'activitypub' ),
5757
'errorMessage' => '',
58-
'hasRemoteUser' => false,
5958
'isError' => false,
6059
'isLoading' => false,
6160
'modal' => array( 'isOpen' => false ),
62-
'profileURL' => '',
6361
'remoteProfile' => '',
6462
'shouldSaveProfile' => true,
65-
'template' => '',
63+
)
64+
);
65+
66+
wp_interactivity_state(
67+
'activitypub/remote-reply',
68+
array(
69+
'hasRemoteUser' => false,
70+
'profileURL' => '',
71+
'template' => '',
6672
)
6773
);
6874

@@ -149,7 +155,7 @@ class="activitypub-dialog__error"
149155
<?php echo $wrapper_attributes; // phpcs:ignore WordPress.Security.EscapeOutput ?>
150156
<?php echo $wrapper_context; // phpcs:ignore WordPress.Security.EscapeOutput ?>
151157
>
152-
<div class="activitypub-remote-profile" hidden data-wp-bind--hidden="!context.hasRemoteUser">
158+
<div class="activitypub-remote-profile" hidden data-wp-bind--hidden="!state.hasRemoteUser">
153159
<a
154160
href=""
155161
class="comment-reply-link activitypub-remote-profile__link"
@@ -160,7 +166,7 @@ class="comment-reply-link activitypub-remote-profile__link"
160166
printf(
161167
/* translators: %s: profile name */
162168
esc_html__( 'Reply as %s', 'activitypub' ),
163-
'<span data-wp-text="context.profileURL"></span>'
169+
'<span data-wp-text="state.profileURL"></span>'
164170
);
165171
?>
166172
</a>
@@ -181,7 +187,7 @@ class="activitypub-remote-profile__close wp-element-button wp-block-button__link
181187
class="comment-reply-link activitypub-remote-reply__link"
182188
data-wp-on-async--click="actions.toggleModal"
183189
data-wp-on-async--keydown="actions.onReplyLinkKeydown"
184-
data-wp-bind--hidden="context.hasRemoteUser"
190+
data-wp-bind--hidden="state.hasRemoteUser"
185191
data-wp-bind--aria-expanded="context.modal.isOpen"
186192
aria-label="<?php esc_attr_e( 'Reply on the Fediverse', 'activitypub' ); ?>"
187193
aria-haspopup="dialog"

build/remote-reply/view.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => '79275d307cc08187928c', 'type' => 'module');
1+
<?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => 'f55d39f584162dc95ab4', 'type' => 'module');

build/remote-reply/view.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/remote-reply/render.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,20 @@
5555
'commentURL' => $selected_comment,
5656
'copyButtonText' => __( 'Copy', 'activitypub' ),
5757
'errorMessage' => '',
58-
'hasRemoteUser' => false,
5958
'isError' => false,
6059
'isLoading' => false,
6160
'modal' => array( 'isOpen' => false ),
62-
'profileURL' => '',
6361
'remoteProfile' => '',
6462
'shouldSaveProfile' => true,
65-
'template' => '',
63+
)
64+
);
65+
66+
wp_interactivity_state(
67+
'activitypub/remote-reply',
68+
array(
69+
'hasRemoteUser' => false,
70+
'profileURL' => '',
71+
'template' => '',
6672
)
6773
);
6874

@@ -149,7 +155,7 @@ class="activitypub-dialog__error"
149155
<?php echo $wrapper_attributes; // phpcs:ignore WordPress.Security.EscapeOutput ?>
150156
<?php echo $wrapper_context; // phpcs:ignore WordPress.Security.EscapeOutput ?>
151157
>
152-
<div class="activitypub-remote-profile" hidden data-wp-bind--hidden="!context.hasRemoteUser">
158+
<div class="activitypub-remote-profile" hidden data-wp-bind--hidden="!state.hasRemoteUser">
153159
<a
154160
href=""
155161
class="comment-reply-link activitypub-remote-profile__link"
@@ -160,7 +166,7 @@ class="comment-reply-link activitypub-remote-profile__link"
160166
printf(
161167
/* translators: %s: profile name */
162168
esc_html__( 'Reply as %s', 'activitypub' ),
163-
'<span data-wp-text="context.profileURL"></span>'
169+
'<span data-wp-text="state.profileURL"></span>'
164170
);
165171
?>
166172
</a>
@@ -181,7 +187,7 @@ class="activitypub-remote-profile__close wp-element-button wp-block-button__link
181187
class="comment-reply-link activitypub-remote-reply__link"
182188
data-wp-on-async--click="actions.toggleModal"
183189
data-wp-on-async--keydown="actions.onReplyLinkKeydown"
184-
data-wp-bind--hidden="context.hasRemoteUser"
190+
data-wp-bind--hidden="state.hasRemoteUser"
185191
data-wp-bind--aria-expanded="context.modal.isOpen"
186192
aria-label="<?php esc_attr_e( 'Reply on the Fediverse', 'activitypub' ); ?>"
187193
aria-haspopup="dialog"

src/remote-reply/view.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,25 @@ createModalStore( 'activitypub/remote-reply' );
2525
* @property {String} commentURL The comment URL.
2626
* @property {String} copyButtonText The copy button text.
2727
* @property {String} errorMessage The error message.
28-
* @property {boolean} hasRemoteUser Whether a remote user is set.
2928
* @property {boolean} isError Whether there is an error.
3029
* @property {boolean} isLoading Whether the remote profile is being submitted.
3130
* @property {Object} modal The modal state.
3231
* @property {boolean} modal.isOpen Whether the modal is open.
33-
* @property {String} profileURL The remote profile URL.
3432
* @property {String} remoteProfile The remote profile.
3533
* @property {boolean} shouldSaveProfile Whether to save the profile.
36-
* @property {String} template The template for the remote reply URL.
3734
*/
3835

39-
const { actions, callbacks } = store( 'activitypub/remote-reply', {
36+
const { actions, callbacks, state } = store( 'activitypub/remote-reply', {
4037
state: {
4138
/**
4239
* Get the remote profile URL.
4340
*
4441
* @returns {String} The remote profile URL.
4542
*/
4643
get remoteProfileUrl() {
47-
const { commentURL, template } = getContext();
44+
const { commentURL } = getContext();
4845

49-
return template.replace( '{uri}', encodeURIComponent( commentURL ) );
46+
return state.template.replace( '{uri}', encodeURIComponent( commentURL ) );
5047
},
5148
},
5249
actions: {
@@ -165,7 +162,7 @@ const { actions, callbacks } = store( 'activitypub/remote-reply', {
165162
// Save the remote user if the remember option is checked.
166163
if ( context.shouldSaveProfile ) {
167164
callbacks.setStore( { profileURL, template } );
168-
Object.assign( context, { hasRemoteUser: true, profileURL, template } );
165+
Object.assign( state, { hasRemoteUser: true, profileURL, template } );
169166
}
170167
} catch ( error ) {
171168
// Handle error.
@@ -188,12 +185,10 @@ const { actions, callbacks } = store( 'activitypub/remote-reply', {
188185
* Delete the saved remote user profile.
189186
*/
190187
deleteRemoteUser() {
191-
const context = getContext();
192-
193188
callbacks.deleteStore();
194-
context.hasRemoteUser = false;
195-
context.profileURL = '';
196-
context.template = '';
189+
state.hasRemoteUser = false;
190+
state.profileURL = '';
191+
state.template = '';
197192
},
198193
},
199194
callbacks: {
@@ -206,12 +201,11 @@ const { actions, callbacks } = store( 'activitypub/remote-reply', {
206201
* Initialize the component.
207202
*/
208203
init() {
209-
const context = getContext();
210204
const { profileURL, template } = callbacks.getStore();
211205

212206
// Set the remote user data from localStorage if available.
213207
if ( profileURL && template ) {
214-
Object.assign( context, { hasRemoteUser: true, profileURL, template } );
208+
Object.assign( state, { hasRemoteUser: true, profileURL, template } );
215209
}
216210
},
217211

0 commit comments

Comments
 (0)