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
12db6782
Commit
12db6782
authored
Aug 14, 2024
by
HoMeTown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 新建会话&会话名称更新
parent
662bca48
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
6 deletions
+14
-6
src/pages/Chat/Chat.tsx
+2
-3
src/pages/Home/components/QuestionList/QuestionList.tsx
+12
-3
No files found.
src/pages/Chat/Chat.tsx
View file @
12db6782
...
...
@@ -25,7 +25,6 @@ export const Chat: React.FC = () => {
let
ignore
=
false
const
{
id
}
=
useParams
<
{
id
:
string
}
>
()
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
)
const
[
isNewConversation
,
setIsNewConversation
]
=
useState
(
false
)
const
[
allItems
,
setAllItems
]
=
useState
<
ChatRecord
[]
>
([])
const
dispatch
=
useAppDispatch
()
const
shouldSendQuestion
=
useAppSelector
((
state
:
RootState
)
=>
state
.
conversation
.
shouldSendQuestion
)
...
...
@@ -33,6 +32,7 @@ export const Chat: React.FC = () => {
const
position
=
useScroll
(
scrollableRef
)
const
handleSubmitQuestion
=
async
(
question
:
string
)
=>
{
const
isNew
=
allItems
.
length
===
0
dispatch
(
setIsAsking
(
true
))
// 添加用户提问的问题
setAllItems
(
prevItems
=>
[
...
...
@@ -88,7 +88,7 @@ export const Chat: React.FC = () => {
})
}
if
(
msg
.
type
===
'END'
)
{
if
(
isNew
Conversation
)
{
if
(
isNew
)
{
setTimeout
(()
=>
{
dispatch
(
fetchConversations
())
},
2000
)
...
...
@@ -102,7 +102,6 @@ export const Chat: React.FC = () => {
setIsLoading
(
true
)
try
{
const
res
=
await
fetchUserQaRecordPage
(
conversationId
)
setIsNewConversation
(
res
.
data
.
length
===
0
)
const
messages
=
[{
role
:
'system'
}
as
ChatRecord
,
...
processApiResponse
(
res
.
data
)]
setAllItems
(
messages
)
// 假设 API 返回的数据结构符合 ChatRecord[]
if
(
shouldSendQuestion
)
{
...
...
src/pages/Home/components/QuestionList/QuestionList.tsx
View file @
12db6782
...
...
@@ -5,6 +5,8 @@ import { AnimatePresence, motion } from 'framer-motion'
import
{
useCallback
,
useEffect
,
useState
}
from
'react'
import
Refresh
from
'@/assets/svg/refresh.svg?react'
import
{
type
WithAuthProps
,
withAuth
}
from
'@/auth/withAuth'
import
{
useAppDispatch
}
from
'@/store/hook'
import
{
createConversation
}
from
'@/store/conversationSlice'
interface
QuestionListProps
{
title
:
string
...
...
@@ -50,6 +52,7 @@ function getRandomIndices(total: number, count: number): number[] {
const
QuestionListBase
:
React
.
FC
<
QuestionListProps
&
WithAuthProps
>
=
({
checkAuth
,
questions
,
dotColor
,
title
,
iconImg
,
showRefresh
=
true
,
displayCount
=
4
})
=>
{
const
[
isRotating
,
setIsRotating
]
=
useState
(
false
)
const
[
displayedItems
,
setDisplayedItems
]
=
useState
<
string
[]
>
([])
const
dispatch
=
useAppDispatch
()
const
updateDisplayedItems
=
useCallback
(()
=>
{
const
indices
=
getRandomIndices
(
questions
.
length
,
Math
.
min
(
displayCount
,
questions
.
length
))
...
...
@@ -61,8 +64,14 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({ checkAu
updateDisplayedItems
()
setIsRotating
(
false
)
}
const
handleClick
=
()
=>
{
checkAuth
()
const
handleClick
=
(
item
:
string
)
=>
{
if
(
checkAuth
())
{
dispatch
(
createConversation
({
conversationData
:
{},
shouldNavigate
:
true
,
shouldSendQuestion
:
item
,
}))
}
}
useEffect
(()
=>
{
...
...
@@ -122,7 +131,7 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({ checkAu
layout
className=
"w-full"
>
<
Button
onClick=
{
handleClick
}
color=
"primary"
variant=
"light"
className=
"text-left bg-[#F7FCFF] w-full text-[#333] rounded-[23px] data-[hover=true]:bg-[#E5F6FF] data-[hover=true]:text-primary"
>
<
Button
onClick=
{
()
=>
handleClick
(
item
)
}
color=
"primary"
variant=
"light"
className=
"text-left bg-[#F7FCFF] w-full text-[#333] rounded-[23px] data-[hover=true]:bg-[#E5F6FF] data-[hover=true]:text-primary"
>
<
div
className=
"w-full text-nowrap text-ellipsis overflow-hidden"
>
<
span
style=
{
{
color
:
dotColor
}
}
>
·
</
span
>
<
span
className=
"ml-[8px]"
>
{
item
}
</
span
>
...
...
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