重构状态管理:将 useWeChatStore 更名为 useDataCenterStore,并更新相关引用
This commit is contained in:
@@ -39,6 +39,7 @@ const TransmitModal: React.FC = () => {
|
||||
|
||||
// 从 Zustand store 获取更新方法
|
||||
const openTransmitModal = useContactStore(state => state.openTransmitModal);
|
||||
|
||||
const setTransmitModal = useContactStore(state => state.setTransmitModal);
|
||||
const updateSelectedChatRecords = useWeChatStore(
|
||||
state => state.updateSelectedChatRecords,
|
||||
@@ -142,11 +143,11 @@ const TransmitModal: React.FC = () => {
|
||||
<Modal
|
||||
title="转发消息"
|
||||
open={openTransmitModal}
|
||||
onCancel={() => updateTransmitModal(false)}
|
||||
onCancel={() => setTransmitModal(false)}
|
||||
width={"60%"}
|
||||
className={styles.transmitModal}
|
||||
footer={[
|
||||
<Button key="cancel" onClick={() => updateTransmitModal(false)}>
|
||||
<Button key="cancel" onClick={() => setTransmitModal(false)}>
|
||||
取消
|
||||
</Button>,
|
||||
<Button
|
||||
|
||||
@@ -31,7 +31,7 @@ import {
|
||||
* 微信聊天状态管理 Store
|
||||
* 使用 Zustand 管理微信聊天相关的状态和操作
|
||||
*/
|
||||
export const useWeChatStore = create<WeChatState>()(
|
||||
export const useDataCenterStore = create<WeChatState>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
showChatRecordModel: false,
|
||||
@@ -153,7 +153,7 @@ export const useWeChatStore = create<WeChatState>()(
|
||||
contract: ContractData | weChatGroup,
|
||||
isExist?: boolean,
|
||||
) => {
|
||||
const state = useWeChatStore.getState();
|
||||
const state = useDataCenterStore.getState();
|
||||
// 切换联系人时清空当前消息,等待重新加载
|
||||
set({ currentMessages: [], openTransmitModal: false });
|
||||
|
||||
@@ -193,7 +193,7 @@ export const useWeChatStore = create<WeChatState>()(
|
||||
// ==================== 消息加载方法 ====================
|
||||
/** 加载聊天消息 */
|
||||
loadChatMessages: async (Init: boolean, To?: number) => {
|
||||
const state = useWeChatStore.getState();
|
||||
const state = useDataCenterStore.getState();
|
||||
const contact = state.currentContract;
|
||||
set({ messagesLoading: true });
|
||||
set({ isLoadingData: Init });
|
||||
@@ -258,7 +258,7 @@ export const useWeChatStore = create<WeChatState>()(
|
||||
keyword: string;
|
||||
Count?: number;
|
||||
}) => {
|
||||
const state = useWeChatStore.getState();
|
||||
const state = useDataCenterStore.getState();
|
||||
const contact = state.currentContract;
|
||||
set({ messagesLoading: true });
|
||||
|
||||
@@ -302,7 +302,7 @@ export const useWeChatStore = create<WeChatState>()(
|
||||
// ==================== 消息接收处理 ====================
|
||||
/** 接收新消息处理 */
|
||||
receivedMsg: async message => {
|
||||
const currentContract = useWeChatStore.getState().currentContract;
|
||||
const currentContract = useDataCenterStore.getState().currentContract;
|
||||
// 判断是群聊还是私聊
|
||||
const getMessageId =
|
||||
message?.wechatChatroomId || message.wechatFriendId;
|
||||
@@ -468,13 +468,16 @@ export const useWeChatStore = create<WeChatState>()(
|
||||
// ==================== 便捷选择器导出 ====================
|
||||
/** 获取当前联系人的 Hook */
|
||||
export const useCurrentContact = () =>
|
||||
useWeChatStore(state => state.currentContract);
|
||||
useDataCenterStore(state => state.currentContract);
|
||||
/** 获取当前消息列表的 Hook */
|
||||
export const useCurrentMessages = () =>
|
||||
useWeChatStore(state => state.currentMessages);
|
||||
useDataCenterStore(state => state.currentMessages);
|
||||
/** 获取消息加载状态的 Hook */
|
||||
export const useMessagesLoading = () =>
|
||||
useWeChatStore(state => state.messagesLoading);
|
||||
useDataCenterStore(state => state.messagesLoading);
|
||||
/** 获取复选框显示状态的 Hook */
|
||||
export const useShowCheckbox = () =>
|
||||
useWeChatStore(state => state.showCheckbox);
|
||||
useDataCenterStore(state => state.showCheckbox);
|
||||
|
||||
export const useUpdateTransmitModal = (open: boolean) =>
|
||||
useDataCenterStore(state => state.updateTransmitModal(open));
|
||||
|
||||
Reference in New Issue
Block a user