feat: 支持自动跳转到第一条会话

This commit is contained in:
arvinxx
2023-07-24 23:19:01 +08:00
parent 53c81aef10
commit 54f01c7bd3

View File

@@ -1 +1,24 @@
export { default } from './[id]/index.page';
import Router from 'next/router';
import { useEffect } from 'react';
import { sessionSelectors, useSessionStore } from '@/store/session';
import Chat from './[id]/index.page';
export default () => {
// 支持用户在进到首页时,自动激活第一个列表中的角色
useEffect(() => {
const hasRehydrated = useSessionStore.persist.hasHydrated();
// 只有当水合完毕后,才往下走
if (!hasRehydrated) return;
// 如果当前有会话,那么就激活第一个会话
const list = sessionSelectors.chatList(useSessionStore.getState());
if (list.length > 0) {
const sessionId = list[0].id;
Router.push(`/chat/${sessionId}`);
}
}, []);
return <Chat />;
};