Skip to content

Commit

Permalink
Merge pull request #26 from rishishah-multidots/try/inline-block-comm…
Browse files Browse the repository at this point in the history
…enting

Add WordPress 6.7 for restapi
  • Loading branch information
poojabhimani12 authored Aug 30, 2024
2 parents b0ad9d5 + 6cfdb29 commit 465b438
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 149 deletions.
19 changes: 5 additions & 14 deletions lib/compat/wordpress-6.6/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ function gutenberg_block_editor_preload_paths_6_6( $paths, $context ) {
* @param WP_REST_Request $request The request object.
* @return WP_REST_Response The updated response object.
*/
if ( ! function_exists( 'update_comment_meta_from_rest_request' ) ) {
function update_comment_meta_from_rest_request( $response, $comment, $request ) {
if ( ! function_exists( 'update_comment_meta_from_rest_request_6_6' ) ) {
function update_comment_meta_from_rest_request_6_6( $response, $comment, $request ) {

if ( isset( $request['comment_type'] ) && ! empty( $request['comment_type'] ) ) {
$comment_data = array(
Expand All @@ -204,25 +204,16 @@ function update_comment_meta_from_rest_request( $response, $comment, $request )
wp_update_comment( $comment_data );
}

$author = get_user_by( 'login', $response->data['author_name'] );
if ( $author ) {
$avatar_url = get_avatar_url( $author->ID );
if ( $response->data['author'] ) {
$avatar_url = get_avatar_url( $response->data['author'] );
$response->data['author_avatar_urls'] = array(
'default' => $avatar_url,
'48' => add_query_arg( 's', 48, $avatar_url ),
'96' => add_query_arg( 's', 96, $avatar_url ),
);
}

$comment_id = $comment->comment_ID;
$meta_key = 'block_comment';
$meta_value = get_comment_meta( $comment_id, $meta_key, true );

if ( ! empty( $meta_value ) ) {
$response->data['meta'] = $meta_value;
}

return $response;
}
}
add_filter( 'rest_prepare_comment', 'update_comment_meta_from_rest_request', 10, 3 );
add_filter( 'rest_prepare_comment', 'update_comment_meta_from_rest_request_6_6', 10, 3 );
43 changes: 43 additions & 0 deletions lib/compat/wordpress-6.7/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,46 @@ function gutenberg_override_default_rest_server() {
return 'Gutenberg_REST_Server';
}
add_filter( 'wp_rest_server_class', 'gutenberg_override_default_rest_server', 1 );

/**
* Updates comment metadata from a REST API request.
*
* This function is hooked to the `rest_prepare_comment` filter and is responsible for updating the comment metadata based on the data provided in the REST API request.
*
* It performs the following tasks:
* - Updates the `block_comment` metadata for the comment based on the `meta` field in the request.
* - Updates the `comment_type` and `comment_approved` fields for the comment based on the corresponding fields in the request.
* - Retrieves the author's avatar URLs and adds them to the response data.
* - Retrieves the `block_comment` metadata for the comment and adds it to the response data.
*
* @param WP_REST_Response $response The response object.
* @param WP_Comment $comment The comment object.
* @param WP_REST_Request $request The request object.
* @return WP_REST_Response The updated response object.
*/
if ( ! function_exists( 'update_comment_meta_from_rest_request_6_7' ) ) {
function update_comment_meta_from_rest_request_6_7( $response, $comment, $request ) {

if ( isset( $request['comment_type'] ) && ! empty( $request['comment_type'] ) ) {
$comment_data = array(
'comment_ID' => $comment->comment_ID,
'comment_type' => $request['comment_type'],
'comment_approved' => isset( $request['comment_approved'] ) ? $request['comment_approved'] : 0,
);

wp_update_comment( $comment_data );
}

if ( $response->data['author'] ) {
$avatar_url = get_avatar_url( $response->data['author'] );
$response->data['author_avatar_urls'] = array(
'default' => $avatar_url,
'48' => add_query_arg( 's', 48, $avatar_url ),
'96' => add_query_arg( 's', 96, $avatar_url ),
);
}

return $response;
}
}
add_filter( 'rest_prepare_comment', 'update_comment_meta_from_rest_request_6_7', 10, 3 );
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/editor/src/components/collab-sidebar/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ function CommentHeader( { thread, onResolve, onEdit, onDelete, onReply } ) {
<DropdownMenu
icon={ moreVertical }
label="Select an action"
className="editor-collab-sidebar__commentDropdown"
controls={ moreActions }
/>
</HStack>
Expand Down
144 changes: 15 additions & 129 deletions packages/editor/src/components/collab-sidebar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
width: 100%;
}

.components-textarea-control__input {
textarea {
border: 1px solid $gray-300;
border-radius: 8px;
padding: 10px 15px;
Expand Down Expand Up @@ -89,18 +89,6 @@
flex-shrink: 0;
}

&__userstatus {
button {
font-size: 12px;
font-weight: 400;
line-height: 16px;
padding: 0;
height: auto;
box-shadow: none;
outline: none;
}
}

&__useroverlay {
background-color: rgba(0, 0, 0, 0.7);
width: 100%;
Expand All @@ -125,33 +113,26 @@
}
}

&__resolvedIcon {
fill: #008000;
border-radius: 50%;
width: 18px;
height: 18px;
border: 1px solid #008000;
margin-right: 2px;
margin-top: 5px;
}

&__commentUpdate {
margin-left: auto;

.components-button {
&.has-icon:not(.has-text) {
min-width: 24px;
padding: 0;
width: 24px;
height: 24px;
flex-shrink: 0;
button {
&.is-compact {
&.has-icon:not(.has-text) {
min-width: 24px;
padding: 0;
width: 24px;
height: 24px;
flex-shrink: 0;
}
}
}
}
&__commentDropdown {
flex-shrink: 0;

.components-dropdown {
flex-shrink: 0;

.components-button {
button {
&.has-icon {
min-width: 24px;
padding: 0;
width: 24px;
Expand All @@ -160,103 +141,8 @@
}
}

&__resolvedText {
font-style: italic;
font-weight: 500 !important;
color: #808080 !important;
margin-top: 5px !important;
}
}

.is-collab-block-selected {
background-color: color-mix(in srgb, currentColor 5%, #182f97 20%);
}

.block-editor-format-toolbar__comment-board {
z-index: 1000001;

.components-modal__frame {
max-width: 380px;
min-width: auto;
width: 90vw;
}

.components-modal__content {
margin-top: 0;
padding: 32px 32px;

.components-modal__header {
display: none;
}
}

.comment-board__userIcon {
width: 35px;
height: 35px;
max-width: 100%;
border-radius: 50%;
}

.comment-board__comment {
border-bottom: 1px solid $gray-300;
}

&__resolved {
align-self: end;
}

.comment-board__actions {
width: auto;
}

.comment-board__userName {
font-size: 16px;
text-transform: capitalize;
}

.comment-board__commentText {
font-size: 14px;
margin-top: 5px;
}

.comment-board__dateTime {
font-size: 12px;
}

.block-editor-format-toolbar__comment-input {
.components-text-control__input {
border: 1px solid #ccc;
height: 40px;

&::placeholder {
font-style: italic;
}

&:focus {
border-color: #2271b1;
}
}
}

.block-editor-format-toolbar__comment-board__resolved {
min-width: auto;

* {
min-width: auto;
}

span.components-checkbox-control__input-container {
display: none;

& + label {
text-decoration: underline;
cursor: pointer;
color: rgb(0, 124, 186);
}
}
}

.block-editor-format-toolbar__comment-board__edit {
margin-right: -8px;
}
}

0 comments on commit 465b438

Please sign in to comment.