-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Block Library - Post Comment Content]: Fix block's edit function (#3…
…5190) * [Block Library - Post Comment Content]: Fix block's edit function * Update packages/block-library/src/post-comment-content/index.php Co-authored-by: George Mamadashvili <[email protected]> * address feedback Co-authored-by: George Mamadashvili <[email protected]>
- Loading branch information
1 parent
6fc7ce7
commit 68b99e8
Showing
3 changed files
with
37 additions
and
19 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { RawHTML } from '@wordpress/element'; | ||
import { useEntityProp } from '@wordpress/core-data'; | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
|
||
// TODO: JSDOC types | ||
export default function Edit( { attributes, context } ) { | ||
const { className } = attributes; | ||
const { commentId } = context; | ||
import { useBlockProps, Warning } from '@wordpress/block-editor'; | ||
import { Disabled } from '@wordpress/components'; | ||
|
||
export default function Edit( { context: { commentId } } ) { | ||
const blockProps = useBlockProps(); | ||
const [ content ] = useEntityProp( | ||
'root', | ||
'comment', | ||
'content', | ||
commentId | ||
); | ||
|
||
if ( ! content?.rendered ) { | ||
return ( | ||
<div { ...blockProps }> | ||
<Warning>{ __( 'Comment has no content.' ) }</Warning> | ||
</div> | ||
); | ||
} | ||
return ( | ||
<div { ...useBlockProps() }> | ||
<p className={ className }>{ content }</p> | ||
<div { ...blockProps }> | ||
<Disabled> | ||
<RawHTML key="html">{ content.rendered }</RawHTML> | ||
</Disabled> | ||
</div> | ||
); | ||
} |
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