-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Experiment: Comments block: client-side form submission #53737
Draft
luisherranz
wants to merge
15
commits into
trunk
Choose a base branch
from
try/client-side-form-submission-of-comments-form-block
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b542f35
Comments block: Try client-side form submission
ockham ffc93df
Try updating to new store API
ockham f3eeb01
Update action in Comment Reply Link block
ockham 26d13fb
Move module registration to correct filter
ockham a5f1a58
Fix more state
ockham e43b0d2
Move namespace inside JSON
DAreRodz 03cdf09
Register and enqueue comments form module
DAreRodz 3e20de5
Update state definition
DAreRodz 202771c
Use generator syntax for submit action
DAreRodz d5012cb
Update module registration logic
DAreRodz 3968364
Specify post-comments-form/view as module
DAreRodz feadb8c
Update PHP files
DAreRodz 7b92a5e
Remove unused viewScript
DAreRodz 204fa39
Dynamically import iAPI router
DAreRodz e57bc5f
Revert "Interactivity API: Remove `data-wp-slot` and `data-wp-fill` …
DAreRodz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { SelectControl } from '@wordpress/components'; | ||
import { | ||
SelectControl, | ||
PanelBody, | ||
ToggleControl, | ||
Notice, | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { InspectorControls } from '@wordpress/block-editor'; | ||
import { useEffect, useRef } from '@wordpress/element'; | ||
import { speak } from '@wordpress/a11y'; | ||
|
||
export default function CommentsInspectorControls( { | ||
attributes: { tagName }, | ||
attributes: { tagName, enhancedSubmission }, | ||
setAttributes, | ||
} ) { | ||
const htmlElementMessages = { | ||
|
@@ -17,8 +24,21 @@ export default function CommentsInspectorControls( { | |
"The <aside> element should represent a portion of a document whose content is only indirectly related to the document's main content." | ||
), | ||
}; | ||
|
||
const enhancedSubmissionNotice = __( | ||
'Enhanced submission might cause interactive blocks within the Comment Template to stop working. Disable it if you experience any issues.' | ||
); | ||
|
||
const isFirstRender = useRef( true ); // Don't speak on first render. | ||
useEffect( () => { | ||
if ( ! isFirstRender.current && enhancedSubmission ) { | ||
speak( enhancedSubmissionNotice ); | ||
} | ||
isFirstRender.current = false; | ||
}, [ enhancedSubmission, enhancedSubmissionNotice ] ); | ||
|
||
return ( | ||
<InspectorControls> | ||
<> | ||
<InspectorControls group="advanced"> | ||
<SelectControl | ||
__nextHasNoMarginBottom | ||
|
@@ -36,6 +56,36 @@ export default function CommentsInspectorControls( { | |
help={ htmlElementMessages[ tagName ] } | ||
/> | ||
</InspectorControls> | ||
</InspectorControls> | ||
<InspectorControls> | ||
<PanelBody | ||
title={ __( 'User Experience' ) } | ||
initialOpen={ false } | ||
> | ||
<ToggleControl | ||
label={ __( 'Enhanced form submission' ) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will there be other enhancements as well? Otherwise, I'm wondering if there's a more specific name for this feature that tells you what it does. However, I'm trying to think of an improvement and not coming up with anything short and accurate 😅 |
||
help={ __( | ||
'Submitted comments are added without refreshing the page.' | ||
) } | ||
checked={ !! enhancedSubmission } | ||
onChange={ ( value ) => | ||
setAttributes( { | ||
enhancedSubmission: !! value, | ||
} ) | ||
} | ||
/> | ||
{ enhancedSubmission && ( | ||
<div> | ||
<Notice | ||
spokenMessage={ null } | ||
status="warning" | ||
isDismissible={ false } | ||
> | ||
{ enhancedSubmissionNotice } | ||
</Notice> | ||
</div> | ||
) } | ||
</PanelBody> | ||
</InspectorControls> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where and how do they disable it? Having more specific actionable error messages will be helpful. Also, what kinds of interactive blocks might stop working? I'm not sure what kinds of things to look out for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is tricky because the correct answer is "interactive blocks that are not using the Interactivity API", which is too technical and doesn't make sense to put in the UI. We're still trying to come up with ways to auto-detect those blocks, but we haven't come up with a 100% reliable technique yet. Once we do, we can remove that message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had an idea to make this 100% reliable and remove the warning. I'll open a discussion to talk about it. It also applies to the Query block pagination.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There you go:
Any input would be highly appreciated 🙂