Commit 48cf7ad7 by weiw

fix:修复收藏页点击新建时的bug

parent 80f76e0f
......@@ -5,7 +5,7 @@ import { useNavigate } from 'react-router-dom'
import { useClickAway, useSessionStorageState } from 'ahooks'
import styles from './Navbar.module.less'
import { NavBarItem } from './components/NavBarItem'
import { clearNavigationFlag } from '@/store/conversationSlice'
import { clearNavigationFlag, createConversation } from '@/store/conversationSlice'
import type { WithAuthProps } from '@/auth/withAuth'
import { withAuth } from '@/auth/withAuth'
import { NAV_BAR_ITEMS } from '@/config/nav'
......@@ -24,13 +24,13 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
const { currentConversationId, shouldNavigateToNewConversation } = useAppSelector(state => state.conversation)
// const handleCreateConversation = () => {
// dispatch(createConversation({
// conversationData: {},
// shouldNavigate: true,
// shouldSendQuestion: '',
// }))
// }
const handleCreateConversation = () => {
dispatch(createConversation({
conversationData: {},
shouldNavigate: true,
shouldSendQuestion: '',
}))
}
const [isH5NavVisible, setIsH5NavVisible] = useState(isMobile())
......@@ -51,8 +51,12 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
}
if (type === 'add') {
// handleCreateConversation()
navigate('/')
if (location.pathname.includes('/chat')) {
handleCreateConversation()
}
else {
navigate('/')
}
onSetHistoryVisible(false)
}
......
import { useEffect, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import { Button, Modal, ModalBody, ModalContent, ModalFooter, ModalHeader, Tooltip } from '@heroui/react'
import { motion } from 'framer-motion'
import { useNavigate } from 'react-router-dom'
......@@ -17,6 +17,7 @@ import SdreamLoading from '@/components/SdreamLoading'
export const Collect: React.FC = () => {
const navigate = useNavigate()
const hasLoaded = useRef(false)
const [isLoading, setIsLoading] = useState(false)
const [isOpen, setIsOpen] = useState(false)
......@@ -27,20 +28,31 @@ export const Collect: React.FC = () => {
const [total, setTotal] = useState(0)
const getCollectList = async () => {
// 防止重复调用
if (hasLoaded.current) {
return
}
hasLoaded.current = true
setIsLoading(true)
const params = {
pageNum,
pageSize,
}
const res = await fetchQueryCollectionList(params)
let timer = null as any
timer = setTimeout(() => {
setCollectList([...collectList, ...res.data.records])
try {
const res = await fetchQueryCollectionList(params)
// 使用函数式更新确保获取最新的 collectList 值
setCollectList((prevList: any) => [...prevList, ...res.data.records])
setTotal(res.data.total)
}
catch (error) {
console.error('获取收藏列表失败:', error)
hasLoaded.current = false // 出错时重置标志位
}
finally {
setIsLoading(false)
clearTimeout(timer)
timer = null
}, 500)
}
}
const handleDelete = (item: any) => {
......@@ -79,7 +91,11 @@ export const Collect: React.FC = () => {
useEffect(() => {
getCollectList()
}, [pageNum])
// 清理函数,在组件卸载时重置标志位
return () => {
hasLoaded.current = false
}
}, [])
return (
<div className={styles.scrollView}>
<div className={`${styles.collectPage} relative`}>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment