Skip to content

Commit f709336

Browse files
alshakeromatticbot
authored andcommitted
Fix Verbum comments in Query Loop (#40933)
Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/12711349519 Upstream-Ref: Automattic/jetpack@59e2d93
1 parent 6d31502 commit f709336

30 files changed

+379
-297
lines changed

composer.lock

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

vendor/automattic/jetpack-mu-wpcom/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ This is an alpha version! The changes listed here are not final.
4545
- Load WPCOM sidebar notice async
4646
- Restore visited button color in themes.php to Core's default
4747
- Starter page templates: correctly insert the pattern to the Content block when rendering mode is template-locked
48+
- To support adding a comment form inside a query loop
4849
- wpcom-block-editor-nux: avoid using useLocation which now throws exception outside Site Editor in Gutenberg 19.9.0
4950

5051
## [6.0.0] - 2024-12-04
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('wp-polyfill'), 'version' => '4cf8f5b832fdeb1f83c1');
1+
<?php return array('dependencies' => array('wp-polyfill'), 'version' => '5dddcf62b1d02cdefa9b');

vendor/automattic/jetpack-mu-wpcom/src/build/verbum-comments/verbum-comments.css

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

vendor/automattic/jetpack-mu-wpcom/src/build/verbum-comments/verbum-comments.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.

vendor/automattic/jetpack-mu-wpcom/src/build/verbum-comments/verbum-comments.rtl.css

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

vendor/automattic/jetpack-mu-wpcom/src/features/verbum-comments/class-verbum-comments.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function verbum_render_element() {
9696
$color_scheme = 'transparent';
9797
}
9898

99-
$verbum = '<div id="comment-form__verbum" class="' . $color_scheme . '"></div>' . $this->hidden_fields();
99+
$verbum = '<div class="comment-form__verbum ' . $color_scheme . '"></div>' . $this->hidden_fields();
100100

101101
// If the blog requires login, Verbum need to be wrapped in a <form> to work.
102102
// Verbum is given `mustLogIn` to handle the login flow.
@@ -535,8 +535,12 @@ public function add_verbum_meta_data( $comment_id ) {
535535
* Get the hidden fields for the comment form.
536536
*/
537537
public function hidden_fields() {
538+
// Ironically, get_queried_post_id doesn't work inside query loop.
539+
// See: https://github.com/Automattic/wp-calypso/issues/98136
540+
$queried_post = get_post();
541+
$queried_post_id = $queried_post ? $queried_post->ID : 0;
538542
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
539-
$post_id = isset( $_GET['postid'] ) ? intval( $_GET['postid'] ) : get_queried_object_id();
543+
$post_id = isset( $_GET['postid'] ) ? intval( $_GET['postid'] ) : $queried_post_id;
540544
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
541545
$is_current_user_subscribed = isset( $_GET['is_current_user_subscribed'] ) ? intval( $_GET['is_current_user_subscribed'] ) : 0;
542546
$nonce = wp_create_nonce( 'highlander_comment' );

vendor/automattic/jetpack-mu-wpcom/src/features/verbum-comments/src/components/EmailForm/email-form-cookie-consent.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
import { useContext, useCallback } from 'preact/hooks';
12
import { translate } from '../../i18n';
2-
import { shouldStoreEmailData } from '../../state';
3+
import { VerbumSignals } from '../../state';
34
import { ToggleControl } from '../ToggleControl';
45

5-
const handleChange = ( e: boolean ) => {
6-
shouldStoreEmailData.value = e;
7-
};
8-
96
export const EmailFormCookieConsent = () => {
7+
const { shouldStoreEmailData } = useContext( VerbumSignals );
8+
9+
const handleChange = useCallback(
10+
( e: boolean ) => {
11+
shouldStoreEmailData.value = e;
12+
},
13+
[ shouldStoreEmailData ]
14+
);
15+
1016
const label = (
1117
<div className="verbum-toggle-control__label">
1218
<p className="primary">

vendor/automattic/jetpack-mu-wpcom/src/features/verbum-comments/src/components/EmailForm/index.tsx

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { signal, effect, batch, computed } from '@preact/signals';
1+
import { effect, batch, useSignal, useComputed } from '@preact/signals';
22
import clsx from 'clsx';
3-
import { useState, useEffect } from 'preact/hooks';
3+
import { useState, useEffect, useContext } from 'preact/hooks';
44
import { translate } from '../../i18n';
55
import { Name, Website, Email } from '../../images';
6-
import { mailLoginData, isMailFormInvalid, shouldStoreEmailData } from '../../state';
6+
import { VerbumSignals } from '../../state';
77
import { getUserInfoCookie, isAuthRequired } from '../../utils';
88
import { NewCommentEmail } from '../new-comment-email';
99
import { NewPostsEmail } from '../new-posts-email';
@@ -15,32 +15,34 @@ interface EmailFormProps {
1515
shouldShowEmailForm: boolean;
1616
}
1717

18-
const isValidEmail = signal( true );
19-
const isEmailTouched = signal( false );
20-
const isNameTouched = signal( false );
21-
const isValidAuthor = signal( true );
22-
const userEmail = computed( () => mailLoginData.value.email || '' );
23-
const userName = computed( () => mailLoginData.value.author || '' );
24-
const userUrl = computed( () => mailLoginData.value.url || '' );
18+
export const EmailForm = ( { shouldShowEmailForm }: EmailFormProps ) => {
19+
const { mailLoginData, isMailFormInvalid, shouldStoreEmailData } = useContext( VerbumSignals );
2520

26-
const validateFormData = () => {
27-
const emailRegex = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
28-
batch( () => {
29-
isValidEmail.value =
30-
Boolean( userEmail.value ) && Boolean( emailRegex.test( userEmail.value ) );
31-
isValidAuthor.value = Boolean( userName.value.length > 0 );
32-
} );
33-
};
21+
const isValidEmail = useSignal( true );
22+
const isEmailTouched = useSignal( false );
23+
const isNameTouched = useSignal( false );
24+
const isValidAuthor = useSignal( true );
25+
const userEmail = useComputed( () => mailLoginData.value.email || '' );
26+
const userName = useComputed( () => mailLoginData.value.author || '' );
27+
const userUrl = useComputed( () => mailLoginData.value.url || '' );
3428

35-
const setFormData = ( event: ChangeEvent< HTMLInputElement > ) => {
36-
mailLoginData.value = {
37-
...mailLoginData.peek(),
38-
[ event.currentTarget.name ]: event.currentTarget.value,
29+
const validateFormData = () => {
30+
const emailRegex = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
31+
batch( () => {
32+
isValidEmail.value =
33+
Boolean( userEmail.value ) && Boolean( emailRegex.test( userEmail.value ) );
34+
isValidAuthor.value = Boolean( userName.value.length > 0 );
35+
} );
36+
};
37+
38+
const setFormData = ( event: ChangeEvent< HTMLInputElement > ) => {
39+
mailLoginData.value = {
40+
...mailLoginData.peek(),
41+
[ event.currentTarget.name ]: event.currentTarget.value,
42+
};
43+
validateFormData();
3944
};
40-
validateFormData();
41-
};
4245

43-
export const EmailForm = ( { shouldShowEmailForm }: EmailFormProps ) => {
4446
const { subscribeToComment, subscribeToBlog } = VerbumComments;
4547
const [ emailNewComment, setEmailNewComment ] = useState( false );
4648
const [ emailNewPosts, setEmailNewPosts ] = useState( false );

0 commit comments

Comments
 (0)