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
accd38e8
Commit
accd38e8
authored
Aug 09, 2024
by
HoMeTown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 路由守卫中chat/id的处理
parent
59926472
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
2 deletions
+12
-2
src/layouts/HistoryBar/components/HistoryBarList/index.tsx
+7
-1
src/routes/RouteChangeHandler.tsx
+5
-1
No files found.
src/layouts/HistoryBar/components/HistoryBarList/index.tsx
View file @
accd38e8
import
{
motion
}
from
'framer-motion'
import
{
motion
}
from
'framer-motion'
import
{
Button
}
from
'@nextui-org/react'
import
{
Button
}
from
'@nextui-org/react'
import
{
useNavigate
}
from
'react-router-dom'
import
{
containerVariants
,
itemVariants
}
from
'../../motionAnimate'
import
{
containerVariants
,
itemVariants
}
from
'../../motionAnimate'
import
EmptyIcon
from
'@/assets/svg/empty.svg?react'
import
EmptyIcon
from
'@/assets/svg/empty.svg?react'
import
{
useAppSelector
}
from
'@/store/hook'
import
{
useAppSelector
}
from
'@/store/hook'
import
type
{
Conversation
}
from
'@/types/conversation'
export
const
HistoryBarList
:
React
.
FC
=
()
=>
{
export
const
HistoryBarList
:
React
.
FC
=
()
=>
{
const
navigate
=
useNavigate
()
const
{
currentConversationId
,
conversations
}
=
useAppSelector
(
state
=>
state
.
conversation
)
const
{
currentConversationId
,
conversations
}
=
useAppSelector
(
state
=>
state
.
conversation
)
const
handleClick
=
(
conversation
:
Conversation
)
=>
{
navigate
(
`/chat/
${
conversation
.
conversationId
}
`
)
}
return
(
return
(
conversations
.
length
!==
0
conversations
.
length
!==
0
?
(
?
(
...
@@ -34,6 +39,7 @@ export const HistoryBarList: React.FC = () => {
...
@@ -34,6 +39,7 @@ export const HistoryBarList: React.FC = () => {
color=
"primary"
color=
"primary"
variant=
"light"
variant=
"light"
className=
{
`text-left w-full text-[#333] rounded-[23px] data-[hover=true]:bg-[#E5F6FF] data-[hover=true]:text-primary ${currentConversationId === item.conversationId ? 'bg-[#E5F6FF] text-primary' : ''}`
}
className=
{
`text-left w-full text-[#333] rounded-[23px] data-[hover=true]:bg-[#E5F6FF] data-[hover=true]:text-primary ${currentConversationId === item.conversationId ? 'bg-[#E5F6FF] text-primary' : ''}`
}
onClick=
{
()
=>
handleClick
(
item
)
}
>
>
<
div
className=
"w-full text-nowrap text-ellipsis overflow-hidden"
>
<
div
className=
"w-full text-nowrap text-ellipsis overflow-hidden"
>
<
span
>
{
item
.
conversationTitle
}
</
span
>
<
span
>
{
item
.
conversationTitle
}
</
span
>
...
...
src/routes/RouteChangeHandler.tsx
View file @
accd38e8
import
React
,
{
useEffect
}
from
'react'
import
React
,
{
useEffect
}
from
'react'
import
{
useLocation
}
from
'react-router-dom'
import
{
useLocation
}
from
'react-router-dom'
import
{
clearCurrentConversation
}
from
'@/store/conversationSlice'
import
{
clearCurrentConversation
,
setCurrentConversation
}
from
'@/store/conversationSlice'
import
{
useAppDispatch
}
from
'@/store/hook'
import
{
useAppDispatch
}
from
'@/store/hook'
export
function
withRouteChangeHandler
(
WrappedComponent
:
React
.
ComponentType
)
{
export
function
withRouteChangeHandler
(
WrappedComponent
:
React
.
ComponentType
)
{
...
@@ -12,6 +12,10 @@ export function withRouteChangeHandler(WrappedComponent: React.ComponentType) {
...
@@ -12,6 +12,10 @@ export function withRouteChangeHandler(WrappedComponent: React.ComponentType) {
if
(
location
.
pathname
===
'/'
)
{
if
(
location
.
pathname
===
'/'
)
{
dispatch
(
clearCurrentConversation
())
dispatch
(
clearCurrentConversation
())
}
}
else
if
(
location
.
pathname
.
startsWith
(
'/chat/'
))
{
const
conversationId
=
location
.
pathname
.
split
(
'/'
)[
2
]
dispatch
(
setCurrentConversation
(
conversationId
))
}
// 这里可以添加其他路由相关的逻辑
// 这里可以添加其他路由相关的逻辑
},
[
location
,
dispatch
])
},
[
location
,
dispatch
])
...
...
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