改 state 为 reducer state, Context 共享数据修改, 完善资料卡对话框逻辑, 完善
This commit is contained in:
21
client/ui/MainSharedReducer.ts
Normal file
21
client/ui/MainSharedReducer.ts
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user