改 state 为 reducer state, Context 共享数据修改, 完善资料卡对话框逻辑, 完善

This commit is contained in:
CrescentLeaf
2025-12-13 18:05:09 +08:00
parent dee8a24f0b
commit 3351d7dc4e
7 changed files with 183 additions and 29 deletions

View File

@@ -0,0 +1,21 @@
import { Chat, UserMySelf } from "lingchair-client-protocol"
export interface SharedState {
favouriteChats: Chat[]
currentSelectedChatId: string
}
type Action =
| { type: 'update_favourite_chat', data: Chat[] }
| { type: 'update_selected_chat_id', data: string }
export default function MainSharedReducer(state: SharedState, action: Action): SharedState {
switch (action.type) {
case 'update_favourite_chat':
return { ...state, favouriteChats: action.data }
case 'update_selected_chat_id':
return { ...state, currentSelectedChatId: action.data }
default:
return state
}
}