Skip to content

Commit

Permalink
AI Assistant: change prompt placeholder (#34671)
Browse files Browse the repository at this point in the history
* remove typing effect from prompt placeholders

* use a fixed placeholder with suggestions on how to create a prompt

* use different placeholders depending on whether there is content or not

* move ternary out of jsx chunk

* take i18n out of ternary

* change placeholder text
  • Loading branch information
CGastrell committed Dec 15, 2023
1 parent 951ec4f commit 4c74f02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

AI Assistant: remove typing effect on prompt placeholder
30 changes: 4 additions & 26 deletions projects/plugins/jetpack/extensions/blocks/ai-assistant/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { USAGE_PANEL_PLACEMENT_BLOCK_SETTINGS_SIDEBAR } from '../../plugins/ai-a
import ConnectPrompt from './components/connect-prompt';
import FeedbackControl from './components/feedback-control';
import ImageWithSelect from './components/image-with-select';
import { promptTemplates } from './components/prompt-templates-control';
import ToolbarControls from './components/toolbar-controls';
import UpgradePrompt from './components/upgrade-prompt';
import { getStoreBlockId } from './extensions/ai-assistant/with-ai-assistant';
Expand Down Expand Up @@ -201,24 +200,6 @@ export default function AIAssistantEdit( { attributes, setAttributes, clientId,
replaceBlocks( clientId, storedInnerBlocks );
}, [ initialContent, clientId, replaceBlocks, getBlock, attributes?.useGutenbergSyntax ] );

const [ promptPlaceholder, setPromptPlaceholder ] = useState( '' );
const [ currentIndex, setCurrentIndex ] = useState( 0 );

// Loop through placeholder prompts for a nice UX effect.
useEffect( () => {
const interval = setInterval( () => {
if ( currentIndex < promptTemplates.length ) {
setPromptPlaceholder( promptTemplates[ currentIndex ].label );
setCurrentIndex( prevIndex => prevIndex + 1 );
} else {
clearInterval( interval );
setPromptPlaceholder( __( 'Ask Jetpack AI', 'jetpack' ) );
}
}, 1600 );

return () => clearInterval( interval );
}, [ promptPlaceholder, currentIndex ] );

useEffect( () => {
// we don't want to store "half way" states
if ( ! [ 'init', 'done' ].includes( requestingState ) ) {
Expand Down Expand Up @@ -426,6 +407,8 @@ export default function AIAssistantEdit( { attributes, setAttributes, clientId,

const innerBlocks = useInnerBlocksProps( blockProps );

const promptPlaceholder = __( 'Ask Jetpack AI…', 'jetpack' );
const promptPlaceholderWithSamples = __( 'Write about… Make a table for…', 'jetpack' );
return (
<KeyboardShortcuts
bindGlobal
Expand Down Expand Up @@ -559,12 +542,7 @@ export default function AIAssistantEdit( { attributes, setAttributes, clientId,
// Focus the text area
userPromptInput.focus();

// Add a typing effect in the text area
for ( let i = 0; i < prompt.length; i++ ) {
setTimeout( () => {
setAttributes( { userPrompt: prompt.slice( 0, i + 1 ) } );
}, 25 * i );
}
setAttributes( { userPrompt: prompt } );
} }
recordEvent={ tracks.recordEvent }
isGeneratingTitle={ isGeneratingTitle }
Expand All @@ -574,7 +552,7 @@ export default function AIAssistantEdit( { attributes, setAttributes, clientId,
ref={ aiControlRef }
disabled={ requireUpgrade || ! connected }
value={ attributes.userPrompt }
placeholder={ promptPlaceholder || __( 'Ask Jetpack AI', 'jetpack' ) }
placeholder={ attributes?.content ? promptPlaceholder : promptPlaceholderWithSamples }
onChange={ handleChange }
onSend={ handleSend }
onStop={ handleStopSuggestion }
Expand Down

0 comments on commit 4c74f02

Please sign in to comment.