From b55b01cb13ac3ab96d0c621c94b2968424825d2f Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 9 Jul 2023 16:39:46 +0800 Subject: [PATCH] feat: #2308 improve chat actions ux --- app/components/chat.tsx | 41 +++++++++++++++++++++-------------------- app/locales/cn.ts | 1 + app/locales/en.ts | 1 + 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index c479a08ad..02c0dd920 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -730,16 +730,18 @@ export function Chat() { deleteMessage(msgId); }; - const onResend = (botMessageId: number) => { - // find last user input message and resend - const userIndex = findLastUserIndex(botMessageId); - if (userIndex === null) return; + const onResend = (message: ChatMessage) => { + let content = message.content; + + if (message.role === "assistant" && message.id) { + const userIndex = findLastUserIndex(message.id); + if (userIndex) { + content = session.messages.at(userIndex)?.content ?? content; + } + } setIsLoading(true); - const userMsg = session.messages[userIndex]; - deleteMessage(userMsg.id); - deleteMessage(botMessageId); - chatStore.onUserInput(userMsg.content).then(() => setIsLoading(false)); + chatStore.onUserInput(content).then(() => setIsLoading(false)); inputRef.current?.focus(); }; @@ -918,12 +920,11 @@ export function Chat() { > {messages.map((message, i) => { const isUser = message.role === "user"; - // const showActions = - // !isUser && - // i > 0 && - // !(message.preview || message.content.length === 0) && - // i >= context.length; // do not show actions for context prompts - const showActions = true; + const isContext = i < context.length; + const showActions = + i > 0 && + !(message.preview || message.content.length === 0) && + !isContext; const showTyping = message.preview || message.streaming; const shouldShowClearContextDivider = i === clearContextIndex - 1; @@ -980,7 +981,7 @@ export function Chat() { } - onClick={() => onResend(message.id ?? i)} + onClick={() => onResend(message)} /> - {showActions && ( -
- {message.date.toLocaleString()} -
- )} +
+ {isContext + ? Locale.Chat.IsContext + : message.date.toLocaleString()} +
{shouldShowClearContextDivider && } diff --git a/app/locales/cn.ts b/app/locales/cn.ts index c6ba4ed74..c32014bee 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -66,6 +66,7 @@ const cn = { Reset: "清除记忆", SaveAs: "存为面具", }, + IsContext: "预设提示词", }, Export: { Title: "分享聊天记录", diff --git a/app/locales/en.ts b/app/locales/en.ts index 23b6e7ca9..d96b978f5 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -68,6 +68,7 @@ const en: LocaleType = { Reset: "Reset to Default", SaveAs: "Save as Mask", }, + IsContext: "Contextual Prompt", }, Export: { Title: "Export Messages",