refactor(chat): remove unused ChatScreenVisible and ChatScreenInvisible events
The screen-lifecycle events were dead code: the transitions in chat-machine (idle <-> ready) had no caller behavior tied to them, and the dispatches in chat-screen.tsx were the only senders. Drop the union members, both state transitions, and the mount-effect dispatches. The idle state remains declared as initial but is no longer reachable at runtime; can be refactored in a follow-up. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
* - **订阅 auth 状态机**(loginStatus)——
|
* - **订阅 auth 状态机**(loginStatus)——
|
||||||
* - 派生 isGuest / 驱动 WS 生命周期 / 驱动初次加载(按 loginStatus 选 ChatInit vs ChatLoadMoreHistory)
|
* - 派生 isGuest / 驱动 WS 生命周期 / 驱动初次加载(按 loginStatus 选 ChatInit vs ChatLoadMoreHistory)
|
||||||
* - 驱动历史加载
|
* - 驱动历史加载
|
||||||
* - 屏幕生命周期事件(init / visible / invisible)
|
* - 屏幕初始化(mount 时按 loginStatus 派初次加载)
|
||||||
* - 配额告警监听(**仅**游客 —— "非游客无消息限制"业务事实)
|
* - 配额告警监听(**仅**游客 —— "非游客无消息限制"业务事实)
|
||||||
* - WebSocket 生命周期管理(基于 auth 状态机的 loginStatus)
|
* - WebSocket 生命周期管理(基于 auth 状态机的 loginStatus)
|
||||||
* - 渲染骨架(背景 + 顶部栏 + 消息区 + 输入栏)
|
* - 渲染骨架(背景 + 顶部栏 + 消息区 + 输入栏)
|
||||||
@@ -103,14 +103,10 @@ export function ChatScreen() {
|
|||||||
const [quotaExhausted, setQuotaExhausted] = useState(false);
|
const [quotaExhausted, setQuotaExhausted] = useState(false);
|
||||||
|
|
||||||
// ─────────────────────────────────────────────────────────────
|
// ─────────────────────────────────────────────────────────────
|
||||||
// 屏幕生命周期 —— mount 时按 loginStatus 派初次加载
|
// mount 时按 loginStatus 派初次加载
|
||||||
// ─────────────────────────────────────────────────────────────
|
// ─────────────────────────────────────────────────────────────
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
chatDispatch({ type: "ChatScreenVisible" });
|
|
||||||
dispatchInitialLoad(authState.loginStatus, chatDispatch);
|
dispatchInitialLoad(authState.loginStatus, chatDispatch);
|
||||||
return () => {
|
|
||||||
chatDispatch({ type: "ChatScreenInvisible" });
|
|
||||||
};
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [chatDispatch]);
|
}, [chatDispatch]);
|
||||||
// 注:mount useEffect 故意**不**依赖 loginStatus —— 首次 mount 时机是固定的
|
// 注:mount useEffect 故意**不**依赖 loginStatus —— 首次 mount 时机是固定的
|
||||||
|
|||||||
@@ -9,8 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
export type ChatEvent =
|
export type ChatEvent =
|
||||||
| { type: "ChatInit" }
|
| { type: "ChatInit" }
|
||||||
| { type: "ChatScreenVisible" }
|
|
||||||
| { type: "ChatScreenInvisible" }
|
|
||||||
| { type: "ChatSendMessage"; content: string }
|
| { type: "ChatSendMessage"; content: string }
|
||||||
| { type: "ChatSendImage"; imageBase64: string }
|
| { type: "ChatSendImage"; imageBase64: string }
|
||||||
| { type: "ChatLoadMoreHistory" }
|
| { type: "ChatLoadMoreHistory" }
|
||||||
|
|||||||
@@ -251,7 +251,6 @@ export const chatMachine = setup({
|
|||||||
idle: {
|
idle: {
|
||||||
on: {
|
on: {
|
||||||
ChatInit: "initializing",
|
ChatInit: "initializing",
|
||||||
ChatScreenVisible: "ready",
|
|
||||||
ChatLoadMoreHistory: "loadingMoreHistory",
|
ChatLoadMoreHistory: "loadingMoreHistory",
|
||||||
ChatSendMessage: {
|
ChatSendMessage: {
|
||||||
guard: ({ event }) => event.content.trim().length > 0,
|
guard: ({ event }) => event.content.trim().length > 0,
|
||||||
@@ -308,7 +307,9 @@ export const chatMachine = setup({
|
|||||||
actions: "appendUserImage",
|
actions: "appendUserImage",
|
||||||
},
|
},
|
||||||
ChatLoadMoreHistory: "loadingMoreHistory",
|
ChatLoadMoreHistory: "loadingMoreHistory",
|
||||||
ChatScreenInvisible: "idle",
|
ChatAuthStatusChanged: {
|
||||||
|
actions: "refreshAuthStatus",
|
||||||
|
},
|
||||||
ChatAISentenceReceived: {
|
ChatAISentenceReceived: {
|
||||||
actions: "appendOrUpdateAISentence",
|
actions: "appendOrUpdateAISentence",
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user