Skip to content

Commit

Permalink
AI Featured Image: fix panel transition after setting featured image (#…
Browse files Browse the repository at this point in the history
…36863)

* Unselect blocks to ensure the post complementary area will show up

* Change order of events when opening the panel

* Handle recent versions of Gutenberg where the featured image is on the post status panel

* changelog
  • Loading branch information
lhkowalski authored Apr 11, 2024
1 parent 2afc412 commit 3519ec5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

AI Featured Image: fix bug on automatic transition to featured image panel
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default function FeaturedImage( { busy, disabled }: { busy: boolean; disa
useDispatch( 'core/edit-post' );
const { editPost, toggleEditorPanelOpened: toggleEditorPanelOpenedFromEditor } =
useDispatch( 'core/editor' );
const { clearSelectedBlock } = useDispatch( 'core/block-editor' );

const [ isFeaturedImageModalVisible, setIsFeaturedImageModalVisible ] = useState( false );
const [ images, setImages ] = useState< CarrouselImages >( [ { generating: true } ] );
Expand Down Expand Up @@ -176,8 +177,10 @@ export default function FeaturedImage( { busy, disabled }: { busy: boolean; disa
}, [ processImageGeneration, recordEvent ] );

const triggerComplementaryArea = useCallback( () => {
enableComplementaryArea( 'core/edit-post', 'edit-post/document' );
}, [ enableComplementaryArea ] );
// clear any block selection, because selected blocks have precedence on settings sidebar
clearSelectedBlock();
return enableComplementaryArea( 'core/edit-post', 'edit-post/document' );
}, [ clearSelectedBlock, enableComplementaryArea ] );

const handleAccept = useCallback( () => {
// track the accept/use image event
Expand All @@ -191,14 +194,19 @@ export default function FeaturedImage( { busy, disabled }: { busy: boolean; disa

// Open the featured image panel for users to see the new image.
setTimeout( () => {
// If the panel is not opened, open it and then trigger the complementary area.
if ( ! isEditorPanelOpened( 'featured-image' ) ) {
toggleEditorPanelOpened?.( 'featured-image' ).then( () => {
triggerComplementaryArea();
} );
} else {
triggerComplementaryArea();
}
const isFeaturedImagePanelOpened = isEditorPanelOpened( 'featured-image' );
const isPostStatusPanelOpened = isEditorPanelOpened( 'post-status' );

// open the complementary area and then trigger the featured image panel.
triggerComplementaryArea().then( () => {
if ( ! isFeaturedImagePanelOpened ) {
toggleEditorPanelOpened( 'featured-image' );
}
// handle the case where the featured image panel is not present
if ( ! isPostStatusPanelOpened ) {
toggleEditorPanelOpened( 'post-status' );
}
} );
}, 500 );
};

Expand Down

0 comments on commit 3519ec5

Please sign in to comment.