From 83e9f32488dc23c9d2ee9109f5f1d495216d77de Mon Sep 17 00:00:00 2001 From: vgcman16 <155417613+vgcman16@users.noreply.github.com> Date: Thu, 5 Jun 2025 19:01:45 -0500 Subject: [PATCH] feat: improve prompt enhancer ux --- app/components/chat/BaseChat.module.scss | 30 ++++++++++++++++++++ app/components/chat/BaseChat.tsx | 4 +-- app/components/chat/Chat.client.tsx | 4 +-- app/components/chat/ChatBox.tsx | 35 ++++++++++++++---------- app/lib/hooks/usePromptEnhancer.ts | 8 ++++-- 5 files changed, 60 insertions(+), 21 deletions(-) diff --git a/app/components/chat/BaseChat.module.scss b/app/components/chat/BaseChat.module.scss index 4908e34e..2b17684a 100644 --- a/app/components/chat/BaseChat.module.scss +++ b/app/components/chat/BaseChat.module.scss @@ -45,3 +45,33 @@ fill: url(#shine-gradient); mix-blend-mode: overlay; } + +[data-prompt-enhanced='true'] .PromptEffectLine { + animation: prompt-line 1s ease-out; +} + +[data-prompt-enhanced='true'] .PromptShine { + animation: prompt-shine 1s ease-out; +} + +@keyframes prompt-line { + from { + stroke-dashoffset: 100; + opacity: 1; + } + to { + stroke-dashoffset: 0; + opacity: 0; + } +} + +@keyframes prompt-shine { + from { + opacity: 0; + transform: translateX(-20%); + } + to { + opacity: 0; + transform: translateX(100%); + } +} diff --git a/app/components/chat/BaseChat.tsx b/app/components/chat/BaseChat.tsx index 65228eb5..05f7bd8d 100644 --- a/app/components/chat/BaseChat.tsx +++ b/app/components/chat/BaseChat.tsx @@ -99,9 +99,8 @@ export const BaseChat = React.forwardRef( providerList, input = '', enhancingPrompt, + promptEnhanced, handleInputChange, - - // promptEnhanced, enhancePrompt, sendMessage, handleStop, @@ -462,6 +461,7 @@ export const BaseChat = React.forwardRef( handleStop={handleStop} handleSendMessage={handleSendMessage} enhancingPrompt={enhancingPrompt} + promptEnhanced={promptEnhanced} enhancePrompt={enhancePrompt} isListening={isListening} startListening={startListening} diff --git a/app/components/chat/Chat.client.tsx b/app/components/chat/Chat.client.tsx index 9fe76319..43c58dc0 100644 --- a/app/components/chat/Chat.client.tsx +++ b/app/components/chat/Chat.client.tsx @@ -567,8 +567,8 @@ export const ChatImpl = memo( content: parsedMessages[i] || '', }; })} - enhancePrompt={() => { - enhancePrompt( + enhancePrompt={async () => { + await enhancePrompt( input, (input) => { setInput(input); diff --git a/app/components/chat/ChatBox.tsx b/app/components/chat/ChatBox.tsx index 6bb246d9..c1ce6679 100644 --- a/app/components/chat/ChatBox.tsx +++ b/app/components/chat/ChatBox.tsx @@ -9,6 +9,7 @@ import FilePreview from './FilePreview'; import { ScreenshotStateManager } from './ScreenshotStateManager'; import { SendButton } from './SendButton.client'; import { IconButton } from '~/components/ui/IconButton'; +import { Tooltip } from '~/components/ui/Tooltip'; import { toast } from 'react-toastify'; import { extractTextFromFile } from '~/utils/fileExtract'; import { SpeechRecognitionButton } from '~/components/chat/SpeechRecognition'; @@ -56,6 +57,7 @@ interface ChatBoxProps { handleInputChange?: ((event: React.ChangeEvent) => void) | undefined; handleStop?: (() => void) | undefined; enhancingPrompt?: boolean | undefined; + promptEnhanced?: boolean | undefined; enhancePrompt?: (() => void) | undefined; chatMode?: 'discuss' | 'build'; setChatMode?: (mode: 'discuss' | 'build') => void; @@ -68,6 +70,7 @@ interface ChatBoxProps { export const ChatBox: React.FC = (props) => { return (
= (props) => { props.handleFileUpload()}>
- { - props.enhancePrompt?.(); - toast.success('Prompt enhanced!'); - }} - > - {props.enhancingPrompt ? ( -
- ) : ( -
- )} -
+ + { + props.enhancePrompt?.(); + toast.success('Prompt enhanced!'); + }} + > + {props.enhancingPrompt ? ( +
+ ) : ( +
+ )} +
+
, - ) => { + ): Promise => { setEnhancingPrompt(true); setPromptEnhanced(false); @@ -41,11 +41,12 @@ export function usePromptEnhancer() { const reader = response.body?.getReader(); const originalInput = input; + let _input = input; if (reader) { const decoder = new TextDecoder(); - let _input = ''; + _input = ''; let _error; try { @@ -67,6 +68,7 @@ export function usePromptEnhancer() { } catch (error) { _error = error; setInput(originalInput); + _input = originalInput; } finally { if (_error) { logger.error(_error); @@ -80,6 +82,8 @@ export function usePromptEnhancer() { }); } } + + return _input; }; return { enhancingPrompt, promptEnhanced, enhancePrompt, resetEnhancer };