Skip to content

Commit

Permalink
Title Optimization: improve button behavior on error screen (#39554)
Browse files Browse the repository at this point in the history
* Properly close the modal when Cancel is clicked, cleaning up the state

* Skip new generation on try again button when there are options already

* Changelog
  • Loading branch information
lhkowalski authored Sep 27, 2024
1 parent 337fdd7 commit b1f867e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Title Optimization: improve button behaviors when handling errors.
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,16 @@ export default function TitleOptimization( {

const handleTryAgain = useCallback( () => {
setError( null );
handleRequest( true ); // retry the generation
}, [ handleRequest ] );

/**
* Only try to generate again if there are no options available.
* If there are options, show them so the user can choose one
* or ask for new suggestions.
*/
if ( options.length === 0 ) {
handleRequest( true ); // retry the generation
}
}, [ handleRequest, options ] );

const handleTitleOptimizationWithKeywords = useCallback( () => {
handleRequest();
Expand All @@ -204,6 +212,7 @@ export default function TitleOptimization( {
);

const handleClose = useCallback( () => {
setError( null );
toggleTitleOptimizationModal();
setOptimizationKeywords( '' );
stopSuggestion();
Expand Down Expand Up @@ -275,7 +284,7 @@ export default function TitleOptimization( {
</>
) }
<div className="jetpack-ai-title-optimization__cta">
<Button variant="secondary" onClick={ toggleTitleOptimizationModal }>
<Button variant="secondary" onClick={ handleClose }>
{ __( 'Cancel', 'jetpack' ) }
</Button>
{ showTryAgainButton && (
Expand Down

0 comments on commit b1f867e

Please sign in to comment.