feat: added topic message update and search state management
This commit is contained in:
parent
8687985ccb
commit
13e3a8478c
@ -1,3 +1,4 @@
|
|||||||
|
import { db } from '@renderer/databases'
|
||||||
import { getDefaultTopic } from '@renderer/services/AssistantService'
|
import { getDefaultTopic } from '@renderer/services/AssistantService'
|
||||||
import { useAppDispatch, useAppSelector } from '@renderer/store'
|
import { useAppDispatch, useAppSelector } from '@renderer/store'
|
||||||
import {
|
import {
|
||||||
@ -50,8 +51,20 @@ export function useAssistant(id: string) {
|
|||||||
dispatch(removeTopic({ assistantId: assistant.id, topic }))
|
dispatch(removeTopic({ assistantId: assistant.id, topic }))
|
||||||
},
|
},
|
||||||
moveTopic: (topic: Topic, toAssistant: Assistant) => {
|
moveTopic: (topic: Topic, toAssistant: Assistant) => {
|
||||||
dispatch(addTopic({ assistantId: toAssistant.id, topic: { ...topic } }))
|
dispatch(addTopic({ assistantId: toAssistant.id, topic: { ...topic, assistantId: toAssistant.id } }))
|
||||||
dispatch(removeTopic({ assistantId: assistant.id, topic }))
|
dispatch(removeTopic({ assistantId: assistant.id, topic }))
|
||||||
|
// update topic messages in database
|
||||||
|
db.topics
|
||||||
|
.where('id')
|
||||||
|
.equals(topic.id)
|
||||||
|
.modify((dbTopic) => {
|
||||||
|
if (dbTopic.messages) {
|
||||||
|
dbTopic.messages = dbTopic.messages.map((message) => ({
|
||||||
|
...message,
|
||||||
|
assistantId: toAssistant.id
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
updateTopic: (topic: Topic) => dispatch(updateTopic({ assistantId: assistant.id, topic })),
|
updateTopic: (topic: Topic) => dispatch(updateTopic({ assistantId: assistant.id, topic })),
|
||||||
updateTopics: (topics: Topic[]) => dispatch(updateTopics({ assistantId: assistant.id, topics })),
|
updateTopics: (topics: Topic[]) => dispatch(updateTopics({ assistantId: assistant.id, topics })),
|
||||||
|
|||||||
@ -21,6 +21,7 @@ let _message: Message | undefined
|
|||||||
const TopicsPage: FC = () => {
|
const TopicsPage: FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [search, setSearch] = useState(_search)
|
const [search, setSearch] = useState(_search)
|
||||||
|
const [searchKeywords, setSearchKeywords] = useState(_search)
|
||||||
const [stack, setStack] = useState<Route[]>(_stack)
|
const [stack, setStack] = useState<Route[]>(_stack)
|
||||||
const [topic, setTopic] = useState<Topic | undefined>(_topic)
|
const [topic, setTopic] = useState<Topic | undefined>(_topic)
|
||||||
const [message, setMessage] = useState<Message | undefined>(_message)
|
const [message, setMessage] = useState<Message | undefined>(_message)
|
||||||
@ -40,6 +41,7 @@ const TopicsPage: FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onSearch = () => {
|
const onSearch = () => {
|
||||||
|
setSearchKeywords(search)
|
||||||
setStack(['topics', 'search'])
|
setStack(['topics', 'search'])
|
||||||
setTopic(undefined)
|
setTopic(undefined)
|
||||||
}
|
}
|
||||||
@ -84,7 +86,7 @@ const TopicsPage: FC = () => {
|
|||||||
/>
|
/>
|
||||||
<TopicMessages topic={topic} style={{ display: isShow('topic') }} />
|
<TopicMessages topic={topic} style={{ display: isShow('topic') }} />
|
||||||
<SearchResults
|
<SearchResults
|
||||||
keywords={isShow('search') ? search : ''}
|
keywords={isShow('search') ? searchKeywords : ''}
|
||||||
onMessageClick={onMessageClick}
|
onMessageClick={onMessageClick}
|
||||||
onTopicClick={onTopicClick}
|
onTopicClick={onTopicClick}
|
||||||
style={{ display: isShow('search') }}
|
style={{ display: isShow('search') }}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { ArrowRightOutlined } from '@ant-design/icons'
|
import { ArrowRightOutlined } from '@ant-design/icons'
|
||||||
import { HStack } from '@renderer/components/Layout'
|
import { HStack } from '@renderer/components/Layout'
|
||||||
|
import { useSettings } from '@renderer/hooks/useSettings'
|
||||||
import { default as MessageItem } from '@renderer/pages/home/Messages/Message'
|
import { default as MessageItem } from '@renderer/pages/home/Messages/Message'
|
||||||
import { locateToMessage } from '@renderer/services/MessagesService'
|
import { locateToMessage } from '@renderer/services/MessagesService'
|
||||||
import NavigationService from '@renderer/services/NavigationService'
|
import NavigationService from '@renderer/services/NavigationService'
|
||||||
@ -15,6 +16,7 @@ interface Props extends React.HTMLAttributes<HTMLDivElement> {
|
|||||||
|
|
||||||
const SearchMessage: FC<Props> = ({ message, ...props }) => {
|
const SearchMessage: FC<Props> = ({ message, ...props }) => {
|
||||||
const navigate = NavigationService.navigate!
|
const navigate = NavigationService.navigate!
|
||||||
|
const { messageStyle } = useSettings()
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
if (!message) {
|
if (!message) {
|
||||||
@ -22,7 +24,7 @@ const SearchMessage: FC<Props> = ({ message, ...props }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MessagesContainer {...props}>
|
<MessagesContainer {...props} className={messageStyle}>
|
||||||
<ContainerWrapper style={{ paddingTop: 20, paddingBottom: 20, position: 'relative' }}>
|
<ContainerWrapper style={{ paddingTop: 20, paddingBottom: 20, position: 'relative' }}>
|
||||||
<MessageItem message={message} />
|
<MessageItem message={message} />
|
||||||
<Button
|
<Button
|
||||||
@ -45,6 +47,7 @@ const SearchMessage: FC<Props> = ({ message, ...props }) => {
|
|||||||
const MessagesContainer = styled.div`
|
const MessagesContainer = styled.div`
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user