From 76199a0febe4158630564e67e5b0daee3f11cba0 Mon Sep 17 00:00:00 2001 From: "Soare Robert Daniel (Mac 2023)" Date: Tue, 30 Jul 2024 14:52:00 +0300 Subject: [PATCH] fix: use last conversation as default prompt value --- src/blocks/components/prompt/index.tsx | 18 ++++++++++++++++++ src/blocks/components/prompt/prompt-input.tsx | 2 +- src/blocks/plugins/ai-content/index.tsx | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/blocks/components/prompt/index.tsx b/src/blocks/components/prompt/index.tsx index cb2c0c1e9..b79305328 100644 --- a/src/blocks/components/prompt/index.tsx +++ b/src/blocks/components/prompt/index.tsx @@ -156,6 +156,24 @@ const PromptPlaceholder = ( props: PromptPlaceholderProps ) => { getEmbeddedPrompt(); }, []); + /** + * Use the last conversation as the default prompt value for the text transformation actions. + */ + useEffect( () => { + if ( + ! props.promptID || + 'textTransformation' !== props.promptID || + ! props.resultHistory + ) { + return; + } + + const lastConversation = resultHistory?.[ resultHistory.length - 1 ]?.meta?.prompt; + if ( lastConversation ) { + onValueChange( lastConversation ); + } + }, []); + useEffect( () => { if ( 'loading' === status || 'present' === apiKeyStatus ) { return; diff --git a/src/blocks/components/prompt/prompt-input.tsx b/src/blocks/components/prompt/prompt-input.tsx index be8ff257e..55b31cfd3 100644 --- a/src/blocks/components/prompt/prompt-input.tsx +++ b/src/blocks/components/prompt/prompt-input.tsx @@ -52,8 +52,8 @@ const PromptInput = ( props: PromptInputProps ) => { placeholder={ props.placeholder } rows={1} onKeyDown={ handleKeyDown } + value={ props.value } > - { props.value }