mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-02 18:39:06 +08:00
feat: add click assistant switch to topics settings
This commit is contained in:
parent
bfa6bfa196
commit
cf9d4c5370
@ -175,6 +175,8 @@ const resources = {
|
|||||||
'general.restore.button': 'Restore',
|
'general.restore.button': 'Restore',
|
||||||
'general.reset.title': 'Data Reset',
|
'general.reset.title': 'Data Reset',
|
||||||
'general.reset.button': 'Reset',
|
'general.reset.button': 'Reset',
|
||||||
|
'advanced.title': 'Advanced Settings',
|
||||||
|
'advanced.click_assistant_switch_to_topics': 'Auto switch to topic',
|
||||||
'provider.api_key': 'API Key',
|
'provider.api_key': 'API Key',
|
||||||
'provider.check': 'Check',
|
'provider.check': 'Check',
|
||||||
'provider.get_api_key': 'Get API Key',
|
'provider.get_api_key': 'Get API Key',
|
||||||
@ -445,6 +447,8 @@ const resources = {
|
|||||||
'general.restore.button': '恢复',
|
'general.restore.button': '恢复',
|
||||||
'general.reset.title': '重置数据',
|
'general.reset.title': '重置数据',
|
||||||
'general.reset.button': '重置',
|
'general.reset.button': '重置',
|
||||||
|
'advanced.title': '高级设置',
|
||||||
|
'advanced.click_assistant_switch_to_topics': '点击助手切换到话题',
|
||||||
'provider.api_key': 'API 密钥',
|
'provider.api_key': 'API 密钥',
|
||||||
'provider.check': '检查',
|
'provider.check': '检查',
|
||||||
'provider.get_api_key': '点击这里获取密钥',
|
'provider.get_api_key': '点击这里获取密钥',
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import DragableList from '@renderer/components/DragableList'
|
|||||||
import CopyIcon from '@renderer/components/Icons/CopyIcon'
|
import CopyIcon from '@renderer/components/Icons/CopyIcon'
|
||||||
import AssistantSettingPopup from '@renderer/components/Popups/AssistantSettingPopup'
|
import AssistantSettingPopup from '@renderer/components/Popups/AssistantSettingPopup'
|
||||||
import { useAssistant, useAssistants } from '@renderer/hooks/useAssistant'
|
import { useAssistant, useAssistants } from '@renderer/hooks/useAssistant'
|
||||||
|
import { useSettings } from '@renderer/hooks/useSettings'
|
||||||
import { getDefaultTopic, syncAsistantToAgent } from '@renderer/services/assistant'
|
import { getDefaultTopic, syncAsistantToAgent } from '@renderer/services/assistant'
|
||||||
import { EVENT_NAMES, EventEmitter } from '@renderer/services/event'
|
import { EVENT_NAMES, EventEmitter } from '@renderer/services/event'
|
||||||
import { useAppDispatch, useAppSelector } from '@renderer/store'
|
import { useAppDispatch, useAppSelector } from '@renderer/store'
|
||||||
@ -27,6 +28,7 @@ const Assistants: FC<Props> = ({ activeAssistant, setActiveAssistant, onCreateAs
|
|||||||
const generating = useAppSelector((state) => state.runtime.generating)
|
const generating = useAppSelector((state) => state.runtime.generating)
|
||||||
const [search, setSearch] = useState('')
|
const [search, setSearch] = useState('')
|
||||||
const { updateAssistant, removeAllTopics } = useAssistant(activeAssistant.id)
|
const { updateAssistant, removeAllTopics } = useAssistant(activeAssistant.id)
|
||||||
|
const { clickAssistantToShowTopic, topicPosition } = useSettings()
|
||||||
const searchRef = useRef<InputRef>(null)
|
const searchRef = useRef<InputRef>(null)
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
@ -103,9 +105,13 @@ const Assistants: FC<Props> = ({ activeAssistant, setActiveAssistant, onCreateAs
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (topicPosition === 'left' && clickAssistantToShowTopic) {
|
||||||
|
EventEmitter.emit(EVENT_NAMES.SWITCH_TOPIC_SIDEBAR)
|
||||||
|
}
|
||||||
|
|
||||||
setActiveAssistant(assistant)
|
setActiveAssistant(assistant)
|
||||||
},
|
},
|
||||||
[generating, setActiveAssistant, t]
|
[clickAssistantToShowTopic, generating, setActiveAssistant, t, topicPosition]
|
||||||
)
|
)
|
||||||
|
|
||||||
const list = assistants.filter((assistant) => assistant.name?.toLowerCase().includes(search.toLowerCase().trim()))
|
const list = assistants.filter((assistant) => assistant.name?.toLowerCase().includes(search.toLowerCase().trim()))
|
||||||
|
|||||||
@ -32,7 +32,13 @@ const Messages: FC<Props> = ({ assistant, topic, setActiveTopic }) => {
|
|||||||
const onSendMessage = useCallback(
|
const onSendMessage = useCallback(
|
||||||
async (message: Message) => {
|
async (message: Message) => {
|
||||||
if (message.role === 'user') {
|
if (message.role === 'user') {
|
||||||
message.usage = await estimateMessageUsage(message)
|
estimateMessageUsage(message).then((usage) => {
|
||||||
|
setMessages((prev) => {
|
||||||
|
const _messages = prev.map((m) => (m.id === message.id ? { ...m, usage } : m))
|
||||||
|
db.topics.update(topic.id, { messages: _messages })
|
||||||
|
return _messages
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
const _messages = [...messages, message]
|
const _messages = [...messages, message]
|
||||||
setMessages(_messages)
|
setMessages(_messages)
|
||||||
|
|||||||
@ -154,7 +154,7 @@ const Container = styled.div`
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
max-height: calc(100vh - var(--navbar-height) - 50px);
|
max-height: calc(100vh - var(--navbar-height) - 140px);
|
||||||
`
|
`
|
||||||
|
|
||||||
const TopicListItem = styled.div`
|
const TopicListItem = styled.div`
|
||||||
|
|||||||
@ -5,11 +5,11 @@ import { useSettings } from '@renderer/hooks/useSettings'
|
|||||||
import i18n from '@renderer/i18n'
|
import i18n from '@renderer/i18n'
|
||||||
import { backup, reset, restore } from '@renderer/services/backup'
|
import { backup, reset, restore } from '@renderer/services/backup'
|
||||||
import { useAppDispatch } from '@renderer/store'
|
import { useAppDispatch } from '@renderer/store'
|
||||||
import { setLanguage, setUserName } from '@renderer/store/settings'
|
import { setClickAssistantToShowTopic, setLanguage } from '@renderer/store/settings'
|
||||||
import { setProxyUrl as _setProxyUrl } from '@renderer/store/settings'
|
import { setProxyUrl as _setProxyUrl } from '@renderer/store/settings'
|
||||||
import { ThemeMode } from '@renderer/types'
|
import { ThemeMode } from '@renderer/types'
|
||||||
import { isValidProxyUrl } from '@renderer/utils'
|
import { isValidProxyUrl } from '@renderer/utils'
|
||||||
import { Button, Input, Select } from 'antd'
|
import { Button, Input, Select, Switch } from 'antd'
|
||||||
import { FC, useState } from 'react'
|
import { FC, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
@ -19,10 +19,10 @@ const GeneralSettings: FC = () => {
|
|||||||
const {
|
const {
|
||||||
language,
|
language,
|
||||||
proxyUrl: storeProxyUrl,
|
proxyUrl: storeProxyUrl,
|
||||||
userName,
|
|
||||||
theme,
|
theme,
|
||||||
windowStyle,
|
windowStyle,
|
||||||
topicPosition,
|
topicPosition,
|
||||||
|
clickAssistantToShowTopic,
|
||||||
setTheme,
|
setTheme,
|
||||||
setWindowStyle,
|
setWindowStyle,
|
||||||
setTopicPosition
|
setTopicPosition
|
||||||
@ -106,17 +106,18 @@ const GeneralSettings: FC = () => {
|
|||||||
/>
|
/>
|
||||||
</SettingRow>
|
</SettingRow>
|
||||||
<SettingDivider />
|
<SettingDivider />
|
||||||
<SettingRow>
|
{topicPosition === 'left' && (
|
||||||
<SettingRowTitle>{t('settings.general.user_name')}</SettingRowTitle>
|
<>
|
||||||
<Input
|
<SettingRow>
|
||||||
placeholder={t('settings.general.user_name.placeholder')}
|
<SettingRowTitle>{t('settings.advanced.click_assistant_switch_to_topics')}</SettingRowTitle>
|
||||||
value={userName}
|
<Switch
|
||||||
onChange={(e) => dispatch(setUserName(e.target.value))}
|
checked={clickAssistantToShowTopic}
|
||||||
style={{ width: 180 }}
|
onChange={(checked) => dispatch(setClickAssistantToShowTopic(checked))}
|
||||||
maxLength={30}
|
/>
|
||||||
/>
|
</SettingRow>
|
||||||
</SettingRow>
|
<SettingDivider />
|
||||||
<SettingDivider />
|
</>
|
||||||
|
)}
|
||||||
<SettingRow>
|
<SettingRow>
|
||||||
<SettingRowTitle>{t('settings.proxy.title')}</SettingRowTitle>
|
<SettingRowTitle>{t('settings.proxy.title')}</SettingRowTitle>
|
||||||
<Input
|
<Input
|
||||||
|
|||||||
@ -18,6 +18,7 @@ export interface SettingsState {
|
|||||||
fontSize: number
|
fontSize: number
|
||||||
topicPosition: 'left' | 'right'
|
topicPosition: 'left' | 'right'
|
||||||
pasteLongTextAsFile: boolean
|
pasteLongTextAsFile: boolean
|
||||||
|
clickAssistantToShowTopic: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: SettingsState = {
|
const initialState: SettingsState = {
|
||||||
@ -34,7 +35,8 @@ const initialState: SettingsState = {
|
|||||||
windowStyle: 'opaque',
|
windowStyle: 'opaque',
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
topicPosition: 'right',
|
topicPosition: 'right',
|
||||||
pasteLongTextAsFile: true
|
pasteLongTextAsFile: true,
|
||||||
|
clickAssistantToShowTopic: false
|
||||||
}
|
}
|
||||||
|
|
||||||
const settingsSlice = createSlice({
|
const settingsSlice = createSlice({
|
||||||
@ -89,6 +91,9 @@ const settingsSlice = createSlice({
|
|||||||
},
|
},
|
||||||
setPasteLongTextAsFile: (state, action: PayloadAction<boolean>) => {
|
setPasteLongTextAsFile: (state, action: PayloadAction<boolean>) => {
|
||||||
state.pasteLongTextAsFile = action.payload
|
state.pasteLongTextAsFile = action.payload
|
||||||
|
},
|
||||||
|
setClickAssistantToShowTopic: (state, action: PayloadAction<boolean>) => {
|
||||||
|
state.clickAssistantToShowTopic = action.payload
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -109,7 +114,8 @@ export const {
|
|||||||
setFontSize,
|
setFontSize,
|
||||||
setWindowStyle,
|
setWindowStyle,
|
||||||
setTopicPosition,
|
setTopicPosition,
|
||||||
setPasteLongTextAsFile
|
setPasteLongTextAsFile,
|
||||||
|
setClickAssistantToShowTopic
|
||||||
} = settingsSlice.actions
|
} = settingsSlice.actions
|
||||||
|
|
||||||
export default settingsSlice.reducer
|
export default settingsSlice.reducer
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user