From 893a04aba3b94c2cd000a672ef0d3ed045a3a7aa Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Sat, 15 Mar 2025 16:07:20 +0800 Subject: [PATCH] feat: add new topic button and update translations - Introduced a NewTopicButton component to facilitate adding new topics. - Updated translations for new topic functionality in English, Japanese, Russian, Simplified Chinese, and Traditional Chinese. - Adjusted font size in TranslateButton for better UI consistency. - Removed unused new topic shortcut from Inputbar component. --- .../src/components/TranslateButton.tsx | 2 +- src/renderer/src/i18n/locales/en-us.json | 1 + src/renderer/src/i18n/locales/ja-jp.json | 1 + src/renderer/src/i18n/locales/ru-ru.json | 1 + src/renderer/src/i18n/locales/zh-cn.json | 1 + src/renderer/src/i18n/locales/zh-tw.json | 1 + .../src/pages/home/Inputbar/Inputbar.tsx | 16 ++----- .../src/pages/home/Messages/Messages.tsx | 19 ++++++-- .../pages/home/Messages/NewTopicButton.tsx | 48 +++++++++++++++++++ 9 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 src/renderer/src/pages/home/Messages/NewTopicButton.tsx diff --git a/src/renderer/src/components/TranslateButton.tsx b/src/renderer/src/components/TranslateButton.tsx index 8f53ac15..afd153bb 100644 --- a/src/renderer/src/components/TranslateButton.tsx +++ b/src/renderer/src/components/TranslateButton.tsx @@ -91,7 +91,7 @@ const TranslateButton: FC = ({ text, onTranslated, disabled, style, isLoa const ToolbarButton = styled(Button)` min-width: 30px; height: 30px; - font-size: 17px; + font-size: 16px; border-radius: 50%; transition: all 0.3s ease; color: var(--color-icon); diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index 2a2bd7e8..4a06b56c 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -170,6 +170,7 @@ "topics.prompt.tips": "Topic Prompts: Additional supplementary prompts provided for the current topic", "topics.title": "Topics", "topics.unpinned": "Unpinned Topics", + "topics.new": "New Topic", "translate": "Translate", "navigation": { "prev": "Previous Message", diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json index ebd3d8fe..d075a7ce 100644 --- a/src/renderer/src/i18n/locales/ja-jp.json +++ b/src/renderer/src/i18n/locales/ja-jp.json @@ -170,6 +170,7 @@ "topics.prompt.tips": "トピック提示語:現在のトピックに対して追加の補足提示語を提供", "topics.title": "トピック", "topics.unpinned": "固定解除", + "topics.new": "新しいトピック", "translate": "翻訳", "navigation": { "prev": "前のメッセージ", diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index 259bf36b..53e300b4 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -170,6 +170,7 @@ "topics.prompt.tips": "Тематические подсказки: Дополнительные подсказки, предоставленные для текущей темы", "topics.title": "Топики", "topics.unpinned": "Открепленные темы", + "topics.new": "Новый топик", "translate": "Перевести", "navigation": { "prev": "Предыдущее сообщение", diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index 1c7bf0bf..6bcf2ff6 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -170,6 +170,7 @@ "topics.prompt.tips": "话题提示词: 针对当前话题提供额外的补充提示词", "topics.title": "话题", "topics.unpinned": "取消固定", + "topics.new": "开始新对话", "translate": "翻译", "navigation": { "prev": "上一条消息", diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index 19f6f3b4..00785547 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -170,6 +170,7 @@ "topics.prompt.tips": "話題提示詞:針對目前話題提供額外的補充提示詞", "topics.title": "話題", "topics.unpinned": "取消固定", + "topics.new": "開始新對話", "translate": "翻譯", "navigation": { "prev": "上一條訊息", diff --git a/src/renderer/src/pages/home/Inputbar/Inputbar.tsx b/src/renderer/src/pages/home/Inputbar/Inputbar.tsx index 8b048a7a..e746729e 100644 --- a/src/renderer/src/pages/home/Inputbar/Inputbar.tsx +++ b/src/renderer/src/pages/home/Inputbar/Inputbar.tsx @@ -1,7 +1,6 @@ import { ClearOutlined, ColumnHeightOutlined, - FormOutlined, FullscreenExitOutlined, FullscreenOutlined, GlobalOutlined, @@ -71,7 +70,6 @@ const Inputbar: FC = ({ assistant: _assistant, setActiveTopic, topic }) = pasteLongTextAsFile, pasteLongTextThreshold, showInputEstimatedTokens, - clickAssistantToShowTopic, autoTranslateWithSpace } = useSettings() const [expended, setExpend] = useState(false) @@ -127,7 +125,6 @@ const Inputbar: FC = ({ assistant: _assistant, setActiveTopic, topic }) = const inputTokenCount = showInputEstimatedTokens ? tokenCount : 0 - const newTopicShortcut = useShortcutDisplay('new_topic') const cleanTopicShortcut = useShortcutDisplay('clear_topic') const inputEmpty = isEmpty(text.trim()) && files.length === 0 @@ -325,8 +322,8 @@ const Inputbar: FC = ({ assistant: _assistant, setActiveTopic, topic }) = addTopic(topic) setActiveTopic(topic) - clickAssistantToShowTopic && setTimeout(() => EventEmitter.emit(EVENT_NAMES.SHOW_TOPIC_SIDEBAR), 0) - }, [addTopic, assistant, clickAssistantToShowTopic, setActiveTopic, setModel]) + setTimeout(() => EventEmitter.emit(EVENT_NAMES.SHOW_TOPIC_SIDEBAR), 0) + }, [addTopic, assistant, setActiveTopic, setModel]) const onPause = async () => { await pauseMessages() @@ -710,11 +707,6 @@ const Inputbar: FC = ({ assistant: _assistant, setActiveTopic, topic }) = - - - - - onMentionModel(model, mentionFromKeyboard)} @@ -742,7 +734,7 @@ const Inputbar: FC = ({ assistant: _assistant, setActiveTopic, topic }) = ToolbarButton={ToolbarButton} /> )} - + = ({ assistant: _assistant, setActiveTopic, topic }) = /> - + {loading && ( diff --git a/src/renderer/src/pages/home/Messages/Messages.tsx b/src/renderer/src/pages/home/Messages/Messages.tsx index ac31d145..926809d2 100644 --- a/src/renderer/src/pages/home/Messages/Messages.tsx +++ b/src/renderer/src/pages/home/Messages/Messages.tsx @@ -28,6 +28,7 @@ import styled from 'styled-components' import ChatNavigation from './ChatNavigation' import MessageGroup from './MessageGroup' import NarrowLayout from './NarrowLayout' +import NewTopicButton from './NewTopicButton' import Prompt from './Prompt' interface MessagesProps { @@ -45,7 +46,14 @@ const Messages: React.FC = ({ assistant, topic, setActiveTopic }) const [displayMessages, setDisplayMessages] = useState([]) const [hasMore, setHasMore] = useState(false) const [isLoadingMore, setIsLoadingMore] = useState(false) - const { messages, displayCount, updateMessages, clearTopicMessages, deleteMessage } = useMessageOperations(topic) + const { messages, displayCount, loading, updateMessages, clearTopicMessages, deleteMessage } = + useMessageOperations(topic) + + const messagesRef = useRef(messages) + + useEffect(() => { + messagesRef.current = messages + }, [messages]) useEffect(() => { const reversedMessages = [...messages].reverse() @@ -99,6 +107,12 @@ const Messages: React.FC = ({ assistant, topic, setActiveTopic }) } }), EventEmitter.on(EVENT_NAMES.NEW_CONTEXT, async () => { + const messages = messagesRef.current + + if (messages.length === 0) { + return + } + const lastMessage = last(messages) if (lastMessage?.type === 'clear') { @@ -107,8 +121,6 @@ const Messages: React.FC = ({ assistant, topic, setActiveTopic }) return } - if (messages.length === 0) return - const clearMessage = getUserMessage({ assistant, topic, type: 'clear' }) const newMessages = [...messages, clearMessage] await updateMessages(newMessages) @@ -181,6 +193,7 @@ const Messages: React.FC = ({ assistant, topic, setActiveTopic }) ref={containerRef} $right={topicPosition === 'left'}> + {messages.length >= 2 && !loading && } { + const { t } = useTranslation() + + const addNewTopic = () => { + EventEmitter.emit(EVENT_NAMES.ADD_NEW_TOPIC) + } + + return ( + + + + ) +} + +const Container = styled.div` + display: flex; + justify-content: center; + align-items: center; +` + +const Button = styled(AntdButton)` + border-radius: 20px; + padding: 0 12px; + height: 34px !important; + font-size: 12px; + opacity: 0.8; + transition: all 0.3s ease; + background-color: var(--color-background-soft); + color: var(--color-text-2); + &:hover { + opacity: 0.9; + background-color: var(--color-background-mute) !important; + color: var(--color-text-1) !important; + border-color: var(--color-border-mute) !important; + } +` + +export default NewTopicButton