refactor: migrate state imports from contexts to stores directory

This commit is contained in:
2026-06-09 18:47:04 +08:00
parent f79755f6ec
commit a5d8214650
29 changed files with 72 additions and 50 deletions
+24 -22
View File
@@ -1,11 +1,8 @@
"use client";
import { useRouter } from "next/navigation";
import { useEffect, useRef } from "react";
import { useAuthState } from "@/contexts/auth/auth-context";
import { useChatDispatch } from "@/contexts/chat/chat-context";
import { useUserDispatch } from "@/contexts/user/user-context";
import { useAuthState } from "@/stores/auth/auth-context";
import { useChatDispatch } from "@/stores/chat/chat-context";
import { useUserDispatch } from "@/stores/user/user-context";
import { useAuthGate } from "@/lib/auth/use-auth-gate";
import { ROUTES } from "@/lib/routes";
import { MobileShell } from "@/app/_components/core/mobile-shell";
@@ -17,26 +14,31 @@ import { SplashButton } from "./splash-button";
import styles from "./splash-screen.module.css";
export function SplashScreen() {
const router = useRouter();
const { isAuthed } = useAuthGate();
// useAuthGate 仍消费(仅读取 isAuthed 用于子组件 gating,不触发跳转)
useAuthGate();
// 以下 state/dispatch 当前未在本组件消费;保留以便未来按状态驱动的跳转
// 重新启用时再解注释 useEffect 即可。
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const state = useAuthState();
const wasSuccess = useRef(false);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const chatDispatch = useChatDispatch();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const userDispatch = useUserDispatch();
useEffect(() => {
if (isAuthed) router.replace(ROUTES.chat);
}, [isAuthed, router]);
// 已登录时跳 /chat(已注释:改由 SplashButton 的 Link + 路由守卫统一处理)
// useEffect(() => {
// if (isAuthed) router.replace(ROUTES.chat);
// }, [isAuthed, router]);
// 登录成功跳 /chat
useEffect(() => {
if (state.isSuccess && !wasSuccess.current) {
wasSuccess.current = true;
chatDispatch({ type: "ChatAuthStatusChanged" });
userDispatch({ type: "UserInit" });
router.replace(ROUTES.chat);
}
}, [state.isSuccess, chatDispatch, userDispatch, router]);
// 登录成功跳 /chat(已注释:改由 SplashButton 的 Link + 路由守卫统一处理)
// useEffect(() => {
// if (state.isSuccess && !wasSuccess.current) {
// wasSuccess.current = true;
// chatDispatch({ type: "ChatAuthStatusChanged" });
// userDispatch({ type: "UserInit" });
// router.replace(ROUTES.chat);
// }
// }, [state.isSuccess, chatDispatch, userDispatch, router]);
return (
<MobileShell background="var(--color-sidebar-background)">
@@ -50,7 +52,7 @@ export function SplashScreen() {
<SplashContent />
<div className={styles.buttonArea}>
<SplashButton
onSkip={() => router.push(ROUTES.chat)}
skipHref={ROUTES.chat}
onFacebookLogin={() => {
/* Facebook 登录触发由 SplashButton 内部 dispatch */
}}