Skip to content

Commit

Permalink
feat: #2308 improve chat actions ux
Browse files Browse the repository at this point in the history
  • Loading branch information
Yidadaa committed Jul 9, 2023
1 parent 90d8f31 commit b55b01c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
41 changes: 21 additions & 20 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -980,7 +981,7 @@ export function Chat() {
<ChatAction
text={Locale.Chat.Actions.Retry}
icon={<ResetIcon />}
onClick={() => onResend(message.id ?? i)}
onClick={() => onResend(message)}
/>

<ChatAction
Expand Down Expand Up @@ -1028,11 +1029,11 @@ export function Chat() {
/>
</div>

{showActions && (
<div className={styles["chat-message-action-date"]}>
{message.date.toLocaleString()}
</div>
)}
<div className={styles["chat-message-action-date"]}>
{isContext
? Locale.Chat.IsContext
: message.date.toLocaleString()}
</div>
</div>
</div>
{shouldShowClearContextDivider && <ClearContextDivider />}
Expand Down
1 change: 1 addition & 0 deletions app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const cn = {
Reset: "清除记忆",
SaveAs: "存为面具",
},
IsContext: "预设提示词",
},
Export: {
Title: "分享聊天记录",
Expand Down
1 change: 1 addition & 0 deletions app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const en: LocaleType = {
Reset: "Reset to Default",
SaveAs: "Save as Mask",
},
IsContext: "Contextual Prompt",
},
Export: {
Title: "Export Messages",
Expand Down

0 comments on commit b55b01c

Please sign in to comment.