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.reset.title': 'Data 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.check': 'Check',
|
||||
'provider.get_api_key': 'Get API Key',
|
||||
@ -445,6 +447,8 @@ const resources = {
|
||||
'general.restore.button': '恢复',
|
||||
'general.reset.title': '重置数据',
|
||||
'general.reset.button': '重置',
|
||||
'advanced.title': '高级设置',
|
||||
'advanced.click_assistant_switch_to_topics': '点击助手切换到话题',
|
||||
'provider.api_key': 'API 密钥',
|
||||
'provider.check': '检查',
|
||||
'provider.get_api_key': '点击这里获取密钥',
|
||||
|
||||
@ -3,6 +3,7 @@ import DragableList from '@renderer/components/DragableList'
|
||||
import CopyIcon from '@renderer/components/Icons/CopyIcon'
|
||||
import AssistantSettingPopup from '@renderer/components/Popups/AssistantSettingPopup'
|
||||
import { useAssistant, useAssistants } from '@renderer/hooks/useAssistant'
|
||||
import { useSettings } from '@renderer/hooks/useSettings'
|
||||
import { getDefaultTopic, syncAsistantToAgent } from '@renderer/services/assistant'
|
||||
import { EVENT_NAMES, EventEmitter } from '@renderer/services/event'
|
||||
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 [search, setSearch] = useState('')
|
||||
const { updateAssistant, removeAllTopics } = useAssistant(activeAssistant.id)
|
||||
const { clickAssistantToShowTopic, topicPosition } = useSettings()
|
||||
const searchRef = useRef<InputRef>(null)
|
||||
const { t } = useTranslation()
|
||||
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)
|
||||
},
|
||||
[generating, setActiveAssistant, t]
|
||||
[clickAssistantToShowTopic, generating, setActiveAssistant, t, topicPosition]
|
||||
)
|
||||
|
||||
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(
|
||||
async (message: Message) => {
|
||||
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]
|
||||
setMessages(_messages)
|
||||
|
||||
@ -154,7 +154,7 @@ const Container = styled.div`
|
||||
flex-direction: column;
|
||||
padding-top: 10px;
|
||||
overflow-y: scroll;
|
||||
max-height: calc(100vh - var(--navbar-height) - 50px);
|
||||
max-height: calc(100vh - var(--navbar-height) - 140px);
|
||||
`
|
||||
|
||||
const TopicListItem = styled.div`
|
||||
|
||||
@ -5,11 +5,11 @@ import { useSettings } from '@renderer/hooks/useSettings'
|
||||
import i18n from '@renderer/i18n'
|
||||
import { backup, reset, restore } from '@renderer/services/backup'
|
||||
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 { ThemeMode } from '@renderer/types'
|
||||
import { isValidProxyUrl } from '@renderer/utils'
|
||||
import { Button, Input, Select } from 'antd'
|
||||
import { Button, Input, Select, Switch } from 'antd'
|
||||
import { FC, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
@ -19,10 +19,10 @@ const GeneralSettings: FC = () => {
|
||||
const {
|
||||
language,
|
||||
proxyUrl: storeProxyUrl,
|
||||
userName,
|
||||
theme,
|
||||
windowStyle,
|
||||
topicPosition,
|
||||
clickAssistantToShowTopic,
|
||||
setTheme,
|
||||
setWindowStyle,
|
||||
setTopicPosition
|
||||
@ -106,17 +106,18 @@ const GeneralSettings: FC = () => {
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingDivider />
|
||||
<SettingRow>
|
||||
<SettingRowTitle>{t('settings.general.user_name')}</SettingRowTitle>
|
||||
<Input
|
||||
placeholder={t('settings.general.user_name.placeholder')}
|
||||
value={userName}
|
||||
onChange={(e) => dispatch(setUserName(e.target.value))}
|
||||
style={{ width: 180 }}
|
||||
maxLength={30}
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingDivider />
|
||||
{topicPosition === 'left' && (
|
||||
<>
|
||||
<SettingRow>
|
||||
<SettingRowTitle>{t('settings.advanced.click_assistant_switch_to_topics')}</SettingRowTitle>
|
||||
<Switch
|
||||
checked={clickAssistantToShowTopic}
|
||||
onChange={(checked) => dispatch(setClickAssistantToShowTopic(checked))}
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingDivider />
|
||||
</>
|
||||
)}
|
||||
<SettingRow>
|
||||
<SettingRowTitle>{t('settings.proxy.title')}</SettingRowTitle>
|
||||
<Input
|
||||
|
||||
@ -18,6 +18,7 @@ export interface SettingsState {
|
||||
fontSize: number
|
||||
topicPosition: 'left' | 'right'
|
||||
pasteLongTextAsFile: boolean
|
||||
clickAssistantToShowTopic: boolean
|
||||
}
|
||||
|
||||
const initialState: SettingsState = {
|
||||
@ -34,7 +35,8 @@ const initialState: SettingsState = {
|
||||
windowStyle: 'opaque',
|
||||
fontSize: 14,
|
||||
topicPosition: 'right',
|
||||
pasteLongTextAsFile: true
|
||||
pasteLongTextAsFile: true,
|
||||
clickAssistantToShowTopic: false
|
||||
}
|
||||
|
||||
const settingsSlice = createSlice({
|
||||
@ -89,6 +91,9 @@ const settingsSlice = createSlice({
|
||||
},
|
||||
setPasteLongTextAsFile: (state, action: PayloadAction<boolean>) => {
|
||||
state.pasteLongTextAsFile = action.payload
|
||||
},
|
||||
setClickAssistantToShowTopic: (state, action: PayloadAction<boolean>) => {
|
||||
state.clickAssistantToShowTopic = action.payload
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -109,7 +114,8 @@ export const {
|
||||
setFontSize,
|
||||
setWindowStyle,
|
||||
setTopicPosition,
|
||||
setPasteLongTextAsFile
|
||||
setPasteLongTextAsFile,
|
||||
setClickAssistantToShowTopic
|
||||
} = settingsSlice.actions
|
||||
|
||||
export default settingsSlice.reducer
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user