Commit 80f76e0f by weiw

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

parent 75e4968b
......@@ -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, createConversation } from '@/store/conversationSlice'
import { clearNavigationFlag } 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,7 +51,8 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
}
if (type === 'add') {
handleCreateConversation()
// handleCreateConversation()
navigate('/')
onSetHistoryVisible(false)
}
......
......@@ -52,17 +52,6 @@ export const Home: React.FC = () => {
const [token, setToken] = useLocalStorageState<string | undefined>('__TOKEN__', {
defaultValue: '',
})
// 检查当前路径是否包含 "/chat/"
// const showOutlet = location.pathname.includes('/chat/')
// const handleCreateConversation = (question: string) => {
// dispatch(
// createConversation({
// conversationData: {},
// shouldNavigate: true,
// shouldSendQuestion: question,
// }),
// )
// }
/** 获取qa记录 */
const getQuestionList = useCallback(async () => {
......@@ -128,37 +117,61 @@ export const Home: React.FC = () => {
let res = {} as any
if (viteOutputObj === 'inner') {
res = await fetchLoginByToken(_loginCode)
if (_loginCode) {
res = await fetchLoginByToken(_loginCode)
if (res.data) {
setToken(res.data.token)
// 主动触发 storage 事件,确保其他组件能监听到变化
window.dispatchEvent(
new StorageEvent('storage', {
key: '__TOKEN__',
oldValue: token,
newValue: res.data.token,
url: window.location.href,
storageArea: localStorage,
}),
)
await getQuestionList()
initConversation()
dispatch(fetchConversations())
}
}
else {
await getQuestionList()
initConversation()
dispatch(fetchConversations())
}
}
else {
// 模拟登录 可以用来测试
res = await fetchLoginByUid('123123')
}
if (res.data) {
setToken(res.data.token)
if (res.data) {
setToken(res.data.token)
// 主动触发 storage 事件,确保其他组件能监听到变化
window.dispatchEvent(
new StorageEvent('storage', {
key: '__TOKEN__',
oldValue: token,
newValue: res.data.token,
url: window.location.href,
storageArea: localStorage,
}),
)
// 主动触发 storage 事件,确保其他组件能监听到变化
window.dispatchEvent(
new StorageEvent('storage', {
key: '__TOKEN__',
oldValue: token,
newValue: res.data.token,
url: window.location.href,
storageArea: localStorage,
}),
)
await getQuestionList()
initConversation()
dispatch(fetchConversations())
await getQuestionList()
initConversation()
dispatch(fetchConversations())
}
}
}, [setToken])
// 修改 useEffect
useEffect(() => {
login()
}, []) // 依赖数组为空,只在组件挂载时执行一次
// 修改 useEffect
useEffect(() => {
login()
}, []) // 依赖数组为空,只在组件挂载时执行一次
return (
<div className={styles.homePage}>
......@@ -173,7 +186,10 @@ useEffect(() => {
<div className="w-full">
<div className="flex justify-center gap-[20px]">
{/* 左侧区域 - 产品问答和您可以试着问我 */}
<div className="flex flex-col gap-[20px] items-center overflow-y-auto scrollbar-hide" style={{ height: 'calc(100vh - 64px)' }}>
<div
className="flex flex-col gap-[20px] items-center overflow-y-auto scrollbar-hide"
style={{ height: 'calc(100vh - 64px)' }}
>
<motion.div className="w-full sm:w-auto" {...getAnimationProps(2)}>
<QuestionList
questions={productQuestions.content}
......
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