From 9fb761c32c0bcc5d64f6d1c5dd9043d2014a9661 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Tue, 7 Apr 2026 18:46:30 +0530 Subject: [PATCH 1/2] fix: refactor Preview component --- src/blocks/blocks/posts/edit.js | 114 ++++++++++++++++---------------- 1 file changed, 58 insertions(+), 56 deletions(-) diff --git a/src/blocks/blocks/posts/edit.js b/src/blocks/blocks/posts/edit.js index 12155b196..e5d15cea8 100644 --- a/src/blocks/blocks/posts/edit.js +++ b/src/blocks/blocks/posts/edit.js @@ -64,6 +64,63 @@ import { styles } from './constants.js'; const { attributes: defaultAttributes } = metadata; +const Preview = ({ + posts, + categoriesList, + authors, + blockProps, + inlineStyles, + attributes, + isLoading +}) => { + if ( ! posts || ! categoriesList || ! authors || isLoading ) { + return ( +
+ + + { __( 'Loading Posts', 'otter-blocks' ) } + +
+ ); + } + + if ( 0 === posts.length ) { + return ( +
+ + { __( 'No Posts', 'otter-blocks' ) } + +
+ ); + } + + return ( +
+ + { attributes.enableFeaturedPost && ( + + ) } + + + + + { + attributes.hasPagination && + } +
+ ); +}; + /** * Posts component * @param {import('./types').PostProps} param0 @@ -307,62 +364,6 @@ const Edit = ({ const blockProps = useBlockProps(); - const Preview = ({ - posts, - categoriesList, - authors, - blockProps, - inlineStyles, - attributes - }) => { - if ( ! posts || ! categoriesList || ! authors || isLoading ) { - return ( -
- - - { __( 'Loading Posts', 'otter-blocks' ) } - -
- ); - } - - if ( 0 === posts.length ) { - return ( -
- - { __( 'No Posts', 'otter-blocks' ) } - -
- ); - } - - return ( -
- - { attributes.enableFeaturedPost && ( - - ) } - - - - - { - attributes.hasPagination && - } -
- ); - }; - return ( { categoriesList && ( @@ -386,6 +387,7 @@ const Edit = ({ blockProps={ blockProps } inlineStyles={ inlineStyles } attributes={ attributes } + isLoading={ isLoading } /> ); From bc72dc2af44cc525bc9e6a2a4e4b872d71a7f30b Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Tue, 7 Apr 2026 18:56:35 +0530 Subject: [PATCH 2/2] fix: derived featured post and author --- src/blocks/blocks/posts/edit.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/blocks/blocks/posts/edit.js b/src/blocks/blocks/posts/edit.js index e5d15cea8..5d2f9a2bc 100644 --- a/src/blocks/blocks/posts/edit.js +++ b/src/blocks/blocks/posts/edit.js @@ -93,6 +93,10 @@ const Preview = ({ ); } + const featuredPost = posts?.[0]; + const featuredPostAuthor = authors?.find( + ( author ) => author?.id === featuredPost?.author + ); return (
@@ -100,9 +104,9 @@ const Preview = ({ { attributes.enableFeaturedPost && ( ) }