Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sdream-ai-fe
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
侯明涛
sdream-ai-fe
Commits
cbf58826
Commit
cbf58826
authored
Aug 13, 2024
by
HoMeTown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 新建会话首次发送消息刷新会话列表
parent
c4b8c5a6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
9 deletions
+17
-9
src/components/ConversationModal/index.tsx
+2
-3
src/pages/Chat/Chat.tsx
+15
-6
No files found.
src/components/ConversationModal/index.tsx
View file @
cbf58826
import
{
Button
,
Modal
,
ModalBody
,
ModalContent
,
ModalFooter
,
ModalHeader
,
Table
,
TableBody
,
TableCell
,
TableColumn
,
TableHeader
,
TableRow
,
getKeyValue
}
from
'@nextui-org/react'
import
{
Button
,
Modal
,
ModalBody
,
ModalContent
,
ModalFooter
,
ModalHeader
,
Table
,
TableBody
,
TableCell
,
TableColumn
,
TableHeader
,
TableRow
,
getKeyValue
}
from
'@nextui-org/react'
import
React
from
'react'
import
React
from
'react'
import
{
useDispatch
}
from
'react-redux'
import
{
useAppDispatch
,
useAppSelector
}
from
'@/store/hook'
import
{
useAppSelector
}
from
'@/store/hook'
import
{
deleteConversations
}
from
'@/store/conversationSlice'
import
{
deleteConversations
}
from
'@/store/conversationSlice'
import
useToast
from
'@/hooks/useToast'
import
useToast
from
'@/hooks/useToast'
...
@@ -11,7 +10,7 @@ interface ConversationModalProps {
...
@@ -11,7 +10,7 @@ interface ConversationModalProps {
}
}
export
const
ConversationModal
:
React
.
FC
<
ConversationModalProps
>
=
({
isOpen
,
onClose
})
=>
{
export
const
ConversationModal
:
React
.
FC
<
ConversationModalProps
>
=
({
isOpen
,
onClose
})
=>
{
const
dispatch
=
useDispatch
()
const
dispatch
=
use
App
Dispatch
()
const
showToast
=
useToast
()
const
showToast
=
useToast
()
const
tableColumns
=
[
const
tableColumns
=
[
...
...
src/pages/Chat/Chat.tsx
View file @
cbf58826
...
@@ -3,7 +3,6 @@ import { useParams } from 'react-router-dom'
...
@@ -3,7 +3,6 @@ import { useParams } from 'react-router-dom'
import
{
Spinner
}
from
'@nextui-org/react'
import
{
Spinner
}
from
'@nextui-org/react'
import
{
Virtuoso
}
from
'react-virtuoso'
import
{
Virtuoso
}
from
'react-virtuoso'
import
{
motion
}
from
'framer-motion'
import
{
motion
}
from
'framer-motion'
import
{
useDispatch
,
useSelector
}
from
'react-redux'
import
styles
from
'./Chat.module.less'
import
styles
from
'./Chat.module.less'
import
{
ChatSlogan
}
from
'./components/ChatSlogan'
import
{
ChatSlogan
}
from
'./components/ChatSlogan'
import
{
ChatMaskBar
}
from
'./components/ChatMaskBar'
import
{
ChatMaskBar
}
from
'./components/ChatMaskBar'
...
@@ -16,18 +15,20 @@ import { ChatEditor } from '@/components/ChatEditor'
...
@@ -16,18 +15,20 @@ import { ChatEditor } from '@/components/ChatEditor'
import
type
{
ChatRecord
}
from
'@/types/chat'
import
type
{
ChatRecord
}
from
'@/types/chat'
import
{
fetchUserQaRecordPage
}
from
'@/api/conversation'
import
{
fetchUserQaRecordPage
}
from
'@/api/conversation'
import
{
fetchCheckTokenApi
,
fetchStreamResponse
}
from
'@/api/chat'
import
{
fetchCheckTokenApi
,
fetchStreamResponse
}
from
'@/api/chat'
import
{
clearShouldSendQuestion
}
from
'@/store/conversationSlice'
import
{
clearShouldSendQuestion
,
fetchConversations
}
from
'@/store/conversationSlice'
import
type
{
RootState
}
from
'@/store'
// 假设你的 store 文件导出了 RootState 类型
import
type
{
RootState
}
from
'@/store'
// 假设你的 store 文件导出了 RootState 类型
import
{
useAppDispatch
,
useAppSelector
}
from
'@/store/hook'
export
const
Chat
:
React
.
FC
=
()
=>
{
export
const
Chat
:
React
.
FC
=
()
=>
{
let
ignore
=
false
let
ignore
=
false
const
{
id
}
=
useParams
<
{
id
:
string
}
>
()
const
{
id
}
=
useParams
<
{
id
:
string
}
>
()
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
)
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
)
const
[
isNewConversation
,
setIsNewConversation
]
=
useState
(
false
)
const
[
allItems
,
setAllItems
]
=
useState
<
ChatRecord
[]
>
([])
const
[
allItems
,
setAllItems
]
=
useState
<
ChatRecord
[]
>
([])
const
dispatch
=
useDispatch
()
const
dispatch
=
use
App
Dispatch
()
const
shouldSendQuestion
=
useSelector
((
state
:
RootState
)
=>
state
.
conversation
.
shouldSendQuestion
)
const
shouldSendQuestion
=
use
App
Selector
((
state
:
RootState
)
=>
state
.
conversation
.
shouldSendQuestion
)
const
handleSubmitQuestion
=
useCallback
(
async
(
question
:
string
)
=>
{
const
handleSubmitQuestion
=
async
(
question
:
string
)
=>
{
// 添加用户提问的问题
// 添加用户提问的问题
setAllItems
(
prevItems
=>
[
setAllItems
(
prevItems
=>
[
...
prevItems
,
...
prevItems
,
...
@@ -80,14 +81,22 @@ export const Chat: React.FC = () => {
...
@@ -80,14 +81,22 @@ export const Chat: React.FC = () => {
return
newItems
return
newItems
})
})
}
}
if
(
msg
.
type
===
'END'
)
{
if
(
isNewConversation
)
{
setTimeout
(()
=>
{
dispatch
(
fetchConversations
())
},
2000
)
}
}
},
},
)
)
}
,
[])
}
const
getUserQaRecordPage
=
useCallback
(
async
(
conversationId
:
string
)
=>
{
const
getUserQaRecordPage
=
useCallback
(
async
(
conversationId
:
string
)
=>
{
setIsLoading
(
true
)
setIsLoading
(
true
)
try
{
try
{
const
res
=
await
fetchUserQaRecordPage
(
conversationId
)
const
res
=
await
fetchUserQaRecordPage
(
conversationId
)
setIsNewConversation
(
res
.
data
.
length
===
0
)
const
messages
=
[{
role
:
'system'
}
as
ChatRecord
,
...
processApiResponse
(
res
.
data
)]
const
messages
=
[{
role
:
'system'
}
as
ChatRecord
,
...
processApiResponse
(
res
.
data
)]
setAllItems
(
messages
)
// 假设 API 返回的数据结构符合 ChatRecord[]
setAllItems
(
messages
)
// 假设 API 返回的数据结构符合 ChatRecord[]
if
(
shouldSendQuestion
)
{
if
(
shouldSendQuestion
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment