-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enhance/748: Updates to expand/condense text functionality #774
Changes from 7 commits
073ff0c
73b7e75
007a9ba
de3bc8c
8a7036e
54ba286
c41afe4
6e9884d
40740f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/* eslint-disable @wordpress/no-unsafe-wp-apis */ | ||
/* eslint-disable no-shadow */ | ||
import { registerPlugin } from '@wordpress/plugins'; | ||
import { | ||
store as blockEditorStore, | ||
|
@@ -20,7 +21,7 @@ | |
count as getWordCount, | ||
count as getCharacterCount, | ||
} from '@wordpress/wordcount'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
|
||
import { DisableFeatureButton } from '../components'; | ||
import '../../scss/content-resizing-plugin.scss'; | ||
|
@@ -124,6 +125,9 @@ | |
// Indicates if the modal window with the result is open/closed. | ||
const [ isModalOpen, setIsModalOpen ] = useState( false ); | ||
|
||
// Modal title depending on resizing type. | ||
const [ modalTitle, setModalTitle ] = useState( '' ); | ||
|
||
const { isMultiBlocksSelected, resizingType, isResizing } = useSelect( | ||
( __select ) => { | ||
return { | ||
|
@@ -142,6 +146,12 @@ | |
await resizeContent(); | ||
} )(); | ||
} | ||
|
||
if ( 'grow' === resizingType ) { | ||
setModalTitle( __( 'Expanded text suggestions', 'classifai' ) ); | ||
} else { | ||
setModalTitle( __( 'Condensed text suggestions', 'classifai' ) ); | ||
} | ||
}, [ resizingType ] ); | ||
|
||
// Triggers AJAX request to resize the content. | ||
|
@@ -153,7 +163,7 @@ | |
setIsModalOpen( true ); | ||
} )(); | ||
} | ||
}, [ isResizing, selectedBlock ] ); | ||
|
||
// Resets to default states. | ||
function resetStates() { | ||
|
@@ -161,6 +171,23 @@ | |
setTextArray( [] ); | ||
setIsModalOpen( false ); | ||
dispatch( resizeContentStore ).setResizingType( null ); | ||
setModalTitle( '' ); | ||
} | ||
|
||
/** | ||
* Refreshes results. | ||
* | ||
* @param {string} resizingType Type of resizing. grow|shrink|null | ||
* @param {Block} selectedBlock The selected block. | ||
*/ | ||
async function refreshResults( resizingType, selectedBlock ) { | ||
dispatch( resizeContentStore ).setResizingType( null ); | ||
|
||
await new Promise( ( resolve ) => setTimeout( resolve, 0 ) ); | ||
|
||
setSelectedBlock( selectedBlock ); | ||
|
||
dispatch( resizeContentStore ).setResizingType( resizingType ); | ||
} | ||
|
||
/** | ||
|
@@ -261,7 +288,7 @@ | |
// Result Modal JSX. | ||
const suggestionModal = ! isResizing && textArray.length && isModalOpen && ( | ||
<Modal | ||
title={ __( 'Select a suggestion', 'classifai' ) } | ||
title={ modalTitle } | ||
isFullScreen={ false } | ||
className="classifai-content-resize__suggestion-modal" | ||
onRequestClose={ () => { | ||
|
@@ -316,7 +343,10 @@ | |
</td> | ||
<td> | ||
<Button | ||
text={ __( 'Select', 'classifai' ) } | ||
text={ __( | ||
'Replace', | ||
'classifai' | ||
) } | ||
variant="secondary" | ||
onClick={ () => | ||
updateContent( textItem ) | ||
|
@@ -330,6 +360,26 @@ | |
</tbody> | ||
</table> | ||
</div> | ||
<p> | ||
{ __( | ||
'None of these suggestions are ideal, please', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with your thought here: #748 (comment). To me this reads as if something went wrong and we're giving an error message. It also doesn't make sense if someone has it set to only show a single result ( I also wonder if a button makes more sense here, as that would stand out more, especially when the disable functionality is turned on, we already show a link here: Something like this: I also think |
||
'classifai' | ||
) }{ ' ' } | ||
<Button | ||
onClick={ () => | ||
refreshResults( resizingType, selectedBlock ) | ||
} | ||
variant="link" | ||
> | ||
{ sprintf( | ||
/* translators: %s type of resizing */ | ||
__( 'retry %s', 'classifai' ), | ||
'grow' === resizingType | ||
? __( 'expanding the text', 'classifai' ) | ||
: __( 'condensing the text', 'classifai' ) | ||
) } | ||
</Button> | ||
</p> | ||
<DisableFeatureButton feature="feature_content_resizing" /> | ||
</Modal> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be more complicated than what we care about but in the case where someone has it set to only display a single suggestion,
suggestions
doesn't make sense at that point. Very minor thing so may be fine to just leaveThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added here 6e9884d