refactor: scope providers by route and use XState selectors
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user