Commit 80f76e0f by weiw

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

parent 75e4968b
...@@ -5,7 +5,7 @@ import { useNavigate } from 'react-router-dom' ...@@ -5,7 +5,7 @@ import { useNavigate } from 'react-router-dom'
import { useClickAway, useSessionStorageState } from 'ahooks' import { useClickAway, useSessionStorageState } from 'ahooks'
import styles from './Navbar.module.less' import styles from './Navbar.module.less'
import { NavBarItem } from './components/NavBarItem' import { NavBarItem } from './components/NavBarItem'
import { clearNavigationFlag, createConversation } from '@/store/conversationSlice' import { clearNavigationFlag } from '@/store/conversationSlice'
import type { WithAuthProps } from '@/auth/withAuth' import type { WithAuthProps } from '@/auth/withAuth'
import { withAuth } from '@/auth/withAuth' import { withAuth } from '@/auth/withAuth'
import { NAV_BAR_ITEMS } from '@/config/nav' import { NAV_BAR_ITEMS } from '@/config/nav'
...@@ -24,13 +24,13 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c ...@@ -24,13 +24,13 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
const { currentConversationId, shouldNavigateToNewConversation } = useAppSelector(state => state.conversation) const { currentConversationId, shouldNavigateToNewConversation } = useAppSelector(state => state.conversation)
const handleCreateConversation = () => { // const handleCreateConversation = () => {
dispatch(createConversation({ // dispatch(createConversation({
conversationData: {}, // conversationData: {},
shouldNavigate: true, // shouldNavigate: true,
shouldSendQuestion: '', // shouldSendQuestion: '',
})) // }))
} // }
const [isH5NavVisible, setIsH5NavVisible] = useState(isMobile()) const [isH5NavVisible, setIsH5NavVisible] = useState(isMobile())
...@@ -51,7 +51,8 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c ...@@ -51,7 +51,8 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
} }
if (type === 'add') { if (type === 'add') {
handleCreateConversation() // handleCreateConversation()
navigate('/')
onSetHistoryVisible(false) onSetHistoryVisible(false)
} }
......
...@@ -52,17 +52,6 @@ export const Home: React.FC = () => { ...@@ -52,17 +52,6 @@ export const Home: React.FC = () => {
const [token, setToken] = useLocalStorageState<string | undefined>('__TOKEN__', { const [token, setToken] = useLocalStorageState<string | undefined>('__TOKEN__', {
defaultValue: '', defaultValue: '',
}) })
// 检查当前路径是否包含 "/chat/"
// const showOutlet = location.pathname.includes('/chat/')
// const handleCreateConversation = (question: string) => {
// dispatch(
// createConversation({
// conversationData: {},
// shouldNavigate: true,
// shouldSendQuestion: question,
// }),
// )
// }
/** 获取qa记录 */ /** 获取qa记录 */
const getQuestionList = useCallback(async () => { const getQuestionList = useCallback(async () => {
...@@ -128,37 +117,61 @@ export const Home: React.FC = () => { ...@@ -128,37 +117,61 @@ export const Home: React.FC = () => {
let res = {} as any let res = {} as any
if (viteOutputObj === 'inner') { 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 { else {
// 模拟登录 可以用来测试 // 模拟登录 可以用来测试
res = await fetchLoginByUid('123123') res = await fetchLoginByUid('123123')
} if (res.data) {
setToken(res.data.token)
if (res.data) { // 主动触发 storage 事件,确保其他组件能监听到变化
setToken(res.data.token) window.dispatchEvent(
new StorageEvent('storage', {
key: '__TOKEN__',
oldValue: token,
newValue: res.data.token,
url: window.location.href,
storageArea: localStorage,
}),
)
// 主动触发 storage 事件,确保其他组件能监听到变化 await getQuestionList()
window.dispatchEvent( initConversation()
new StorageEvent('storage', { dispatch(fetchConversations())
key: '__TOKEN__', }
oldValue: token,
newValue: res.data.token,
url: window.location.href,
storageArea: localStorage,
}),
)
await getQuestionList()
initConversation()
dispatch(fetchConversations())
} }
}, [setToken]) }, [setToken])
// 修改 useEffect // 修改 useEffect
useEffect(() => { useEffect(() => {
login() login()
}, []) // 依赖数组为空,只在组件挂载时执行一次 }, []) // 依赖数组为空,只在组件挂载时执行一次
return ( return (
<div className={styles.homePage}> <div className={styles.homePage}>
...@@ -173,7 +186,10 @@ useEffect(() => { ...@@ -173,7 +186,10 @@ useEffect(() => {
<div className="w-full"> <div className="w-full">
<div className="flex justify-center gap-[20px]"> <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)}> <motion.div className="w-full sm:w-auto" {...getAnimationProps(2)}>
<QuestionList <QuestionList
questions={productQuestions.content} 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