refactor(chat): remove legacy screen visibility events and use absolute state refs

- Remove ChatScreenVisible and ChatScreenInvisible events from chat state machine
- Remove legacy ChatInit event handler
- Migrate state transitions to use absolute references (#chat.guestSession, #chat.userSession, #chat.idle)
- Adjust legal text wording for Cozsweet privacy agreement
This commit is contained in:
2026-06-11 19:10:01 +08:00
parent 1b13e4fa19
commit 6394c8ba7b
4 changed files with 11 additions and 20 deletions
+2 -2
View File
@@ -32,14 +32,14 @@ export function AuthLegalText() {
{checked ? <span className={styles.checkboxInner} /> : null} {checked ? <span className={styles.checkboxInner} /> : null}
</button> </button>
<p className={styles.text}> <p className={styles.text}>
I agree to the{" "} I agree to the Cozsweet {" "}
<a <a
href={AppConstants.privacyPolicyUrl} href={AppConstants.privacyPolicyUrl}
className={styles.link} className={styles.link}
target="_blank" target="_blank"
rel="noreferrer" rel="noreferrer"
> >
Cozsweet Privacy Agreement Privacy Agreement
</a>{" "} </a>{" "}
and{" "} and{" "}
<a <a
-2
View File
@@ -96,10 +96,8 @@ export function ChatScreen() {
// 屏幕生命周期 + 派初次鉴权生命周期事件 // 屏幕生命周期 + 派初次鉴权生命周期事件
// ───────────────────────────────────────────────────────────── // ─────────────────────────────────────────────────────────────
useEffect(() => { useEffect(() => {
chatDispatch({ type: "ChatScreenVisible" });
dispatchAuthLifecycle(authState.loginStatus, chatDispatch); dispatchAuthLifecycle(authState.loginStatus, chatDispatch);
return () => { return () => {
chatDispatch({ type: "ChatScreenInvisible" });
}; };
// 注:mount useEffect 故意**不**依赖 loginStatus —— 首次 mount 时机是固定的 // 注:mount useEffect 故意**不**依赖 loginStatus —— 首次 mount 时机是固定的
// "用户进 /chat 那一刻"),loginStatus 由 splash/auth-screen 提前 settle。 // "用户进 /chat 那一刻"),loginStatus 由 splash/auth-screen 提前 settle。
-2
View File
@@ -18,8 +18,6 @@
export type ChatEvent = export type ChatEvent =
// 内部 UI 事件 // 内部 UI 事件
| { type: "ChatInit" } | { type: "ChatInit" }
| { type: "ChatScreenVisible" }
| { type: "ChatScreenInvisible" }
// 鉴权生命周期(**用户**显式触发登录后由 chat-screen 派) // 鉴权生命周期(**用户**显式触发登录后由 chat-screen 派)
| { type: "ChatGuestLogin" } | { type: "ChatGuestLogin" }
| { type: "ChatNonGuestLogin"; token: string } | { type: "ChatNonGuestLogin"; token: string }
+9 -14
View File
@@ -297,10 +297,8 @@ export const chatMachine = setup({
// ───────────────────────────────────────────────────────────── // ─────────────────────────────────────────────────────────────
idle: { idle: {
on: { on: {
ChatGuestLogin: "guestSession", ChatGuestLogin: "#chat.guestSession",
ChatNonGuestLogin: "userSession", ChatNonGuestLogin: "#chat.userSession",
// 兼容旧事件(**无**资源 —— 旧 chat-screen 还在派 ChatInit
ChatInit: "guestSession",
ChatLoadMoreHistory: "loadingMoreHistory", // 旧逻辑保留(翻历史用) ChatLoadMoreHistory: "loadingMoreHistory", // 旧逻辑保留(翻历史用)
}, },
}, },
@@ -345,10 +343,9 @@ export const chatMachine = setup({
actions: "appendUserImage", actions: "appendUserImage",
}, },
ChatLoadMoreHistory: "loadingMore", ChatLoadMoreHistory: "loadingMore",
ChatScreenInvisible: "idle", // 屏不可见 → idle ChatLogout: "#chat.idle", // 登出 → idle
ChatLogout: "idle", // 登出 → idle
// 跨态(游客 → email // 跨态(游客 → email
ChatNonGuestLogin: "userSession", ChatNonGuestLogin: "#chat.userSession",
ChatAISentenceReceived: { ChatAISentenceReceived: {
actions: "appendOrUpdateAISentence", actions: "appendOrUpdateAISentence",
}, },
@@ -426,10 +423,9 @@ export const chatMachine = setup({
actions: "appendUserImage", actions: "appendUserImage",
}, },
ChatLoadMoreHistory: "loadingMore", ChatLoadMoreHistory: "loadingMore",
ChatScreenInvisible: "idle", // 屏不可见 → idlecleanup WS via parent state exit ChatLogout: "#chat.idle", // 登出 → idlecleanup WS
ChatLogout: "idle", // 登出 → idlecleanup WS
// 跨态(email → 游客) // 跨态(email → 游客)
ChatGuestLogin: "guestSession", ChatGuestLogin: "#chat.guestSession",
ChatAISentenceReceived: { ChatAISentenceReceived: {
actions: "appendOrUpdateAISentence", actions: "appendOrUpdateAISentence",
}, },
@@ -501,10 +497,9 @@ export const chatMachine = setup({
actions: "appendUserImage", actions: "appendUserImage",
}, },
ChatLoadMoreHistory: "loadingMoreHistory", ChatLoadMoreHistory: "loadingMoreHistory",
ChatScreenInvisible: "idle", ChatLogout: "#chat.idle",
ChatLogout: "idle", ChatGuestLogin: "#chat.guestSession",
ChatGuestLogin: "guestSession", ChatNonGuestLogin: "#chat.userSession",
ChatNonGuestLogin: "userSession",
ChatAISentenceReceived: { ChatAISentenceReceived: {
actions: "appendOrUpdateAISentence", actions: "appendOrUpdateAISentence",
}, },