feat: Add button to remove messages and responses
This commit is contained in:
parent
61eb356fd9
commit
2ffe2a98b8
|
@ -324,8 +324,21 @@
|
|||
}
|
||||
}
|
||||
|
||||
.chat-message-user > .chat-message-container > .chat-message-item {
|
||||
background-color: var(--second);
|
||||
.chat-message-user > .chat-message-container {
|
||||
.chat-message-top-actions {
|
||||
flex-direction: row;
|
||||
right: unset;
|
||||
left: 20px;
|
||||
}
|
||||
&:hover {
|
||||
.chat-message-top-actions {
|
||||
left: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
& > .chat-message-item {
|
||||
background-color: var(--second);
|
||||
}
|
||||
}
|
||||
|
||||
.chat-message-actions {
|
||||
|
|
|
@ -274,6 +274,10 @@ export function Chat(props: {
|
|||
}
|
||||
};
|
||||
|
||||
const onMessageDelete = (messageIndex: number) => {
|
||||
chatStore.removeMessage(sessionIndex, messageIndex);
|
||||
};
|
||||
|
||||
const onResend = (botIndex: number) => {
|
||||
// find last user input message and resend
|
||||
for (let i = botIndex; i >= 0; i -= 1) {
|
||||
|
@ -418,33 +422,45 @@ export function Chat(props: {
|
|||
</div>
|
||||
)}
|
||||
<div className={styles["chat-message-item"]}>
|
||||
{!isUser &&
|
||||
!(message.preview || message.content.length === 0) && (
|
||||
<div className={styles["chat-message-top-actions"]}>
|
||||
{message.streaming ? (
|
||||
<div
|
||||
className={styles["chat-message-top-action"]}
|
||||
onClick={() => onUserStop(i)}
|
||||
>
|
||||
{Locale.Chat.Actions.Stop}
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
className={styles["chat-message-top-action"]}
|
||||
onClick={() => onResend(i)}
|
||||
>
|
||||
{Locale.Chat.Actions.Retry}
|
||||
</div>
|
||||
)}
|
||||
{!isUser
|
||||
? !(message.preview || message.content.length === 0) && (
|
||||
<div className={styles["chat-message-top-actions"]}>
|
||||
{message.streaming ? (
|
||||
<div
|
||||
className={styles["chat-message-top-action"]}
|
||||
onClick={() => onUserStop(i)}
|
||||
>
|
||||
{Locale.Chat.Actions.Stop}
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
className={styles["chat-message-top-action"]}
|
||||
onClick={() => onResend(i)}
|
||||
>
|
||||
{Locale.Chat.Actions.Retry}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div
|
||||
className={styles["chat-message-top-action"]}
|
||||
onClick={() => copyToClipboard(message.content)}
|
||||
>
|
||||
{Locale.Chat.Actions.Copy}
|
||||
<div
|
||||
className={styles["chat-message-top-action"]}
|
||||
onClick={() => copyToClipboard(message.content)}
|
||||
>
|
||||
{Locale.Chat.Actions.Copy}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
)
|
||||
: !(message.preview || message.content.length === 0) && (
|
||||
<div className={styles["chat-message-top-actions"]}>
|
||||
{!message.streaming && (
|
||||
<div
|
||||
className={styles["chat-message-top-action"]}
|
||||
onClick={(e) => onMessageDelete(i)}
|
||||
>
|
||||
{Locale.Chat.Actions.Delete}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{(message.preview || message.content.length === 0) &&
|
||||
!isUser ? (
|
||||
<LoadingIcon />
|
||||
|
|
|
@ -17,6 +17,7 @@ const cn = {
|
|||
Copy: "复制",
|
||||
Stop: "停止",
|
||||
Retry: "重试",
|
||||
Delete: "删除",
|
||||
},
|
||||
Rename: "重命名对话",
|
||||
Typing: "正在输入…",
|
||||
|
|
|
@ -19,6 +19,7 @@ const en: LocaleType = {
|
|||
Copy: "Copy",
|
||||
Stop: "Stop",
|
||||
Retry: "Retry",
|
||||
Delete: "Delete",
|
||||
},
|
||||
Rename: "Rename Chat",
|
||||
Typing: "Typing…",
|
||||
|
|
|
@ -18,6 +18,7 @@ const tw: LocaleType = {
|
|||
Copy: "複製",
|
||||
Stop: "停止",
|
||||
Retry: "重試",
|
||||
Delete: "刪除",
|
||||
},
|
||||
Rename: "重命名對話",
|
||||
Typing: "正在輸入…",
|
||||
|
|
|
@ -194,6 +194,7 @@ interface ChatStore {
|
|||
summarizeSession: () => void;
|
||||
updateStat: (message: Message) => void;
|
||||
updateCurrentSession: (updater: (session: ChatSession) => void) => void;
|
||||
removeMessage: (sessionIndex: number, messageIndex: number) => void;
|
||||
updateMessage: (
|
||||
sessionIndex: number,
|
||||
messageIndex: number,
|
||||
|
@ -384,6 +385,15 @@ export const useChatStore = create<ChatStore>()(
|
|||
return recentMessages;
|
||||
},
|
||||
|
||||
removeMessage(sessionIndex: number, messageIndex: number) {
|
||||
const sessions = get().sessions;
|
||||
const session = sessions.at(sessionIndex);
|
||||
const messages = session?.messages;
|
||||
// remove user's message and bot's response
|
||||
messages?.splice(messageIndex, 2);
|
||||
set(() => ({ sessions }));
|
||||
},
|
||||
|
||||
updateMessage(
|
||||
sessionIndex: number,
|
||||
messageIndex: number,
|
||||
|
|
Loading…
Reference in New Issue