refactor: scope providers by route and use XState selectors

This commit is contained in:
2026-07-13 19:07:53 +08:00
parent f9b5f22ee9
commit 37ae152abb
24 changed files with 512 additions and 336 deletions
+13 -2
View File
@@ -8,13 +8,24 @@
* 不再承担全局状态同步职责。
*/
import { useEffect, useRef } from "react";
import { shallowEqual } from "@xstate/react";
import { AuthStorage } from "@/data/storage/auth";
import { useAuthState } from "@/stores/auth/auth-context";
import {
selectAuthIsLoading,
useAuthSelector,
} from "@/stores/auth/auth-context";
import { useChatDispatch } from "@/stores/chat/chat-context";
export function ChatAuthSync() {
const authState = useAuthState();
const authState = useAuthSelector(
(state) => ({
hasInitialized: state.context.hasInitialized,
isLoading: selectAuthIsLoading(state),
loginStatus: state.context.loginStatus,
}),
shallowEqual,
);
const chatDispatch = useChatDispatch();
const prevSessionKeyRef = useRef<string | null>(null);