refactor(ckbox): 移除SidebarMenu的currentContract属性并优化状态管理
- 移除不再使用的currentContract属性和相关props传递 - 将chatSessions状态管理移至MessageList组件内部 - 添加CmdFriendInfoChanged消息处理器 - 添加调试日志用于会话更新
This commit is contained in:
@@ -3,22 +3,22 @@ import { List, Avatar, Badge } from "antd";
|
||||
import { UserOutlined, TeamOutlined } from "@ant-design/icons";
|
||||
import { ContractData, weChatGroup } from "@/pages/pc/ckbox/data";
|
||||
import { useWeChatStore } from "@/store/module/weChat/weChat";
|
||||
import { useCkChatStore } from "@/store/module/ckchat/ckchat";
|
||||
|
||||
import styles from "./MessageList.module.scss";
|
||||
import { formatWechatTime } from "@/utils/common";
|
||||
interface MessageListProps {
|
||||
chatSessions: ContractData[] | weChatGroup[];
|
||||
}
|
||||
interface MessageListProps {}
|
||||
|
||||
const MessageList: React.FC<MessageListProps> = ({ chatSessions }) => {
|
||||
const MessageList: React.FC<MessageListProps> = () => {
|
||||
const { setCurrentContact, currentContract } = useWeChatStore();
|
||||
|
||||
const chatSessions = useCkChatStore(state => state.getChatSessions());
|
||||
const onContactClick = (session: ContractData | weChatGroup) => {
|
||||
setCurrentContact(session);
|
||||
};
|
||||
return (
|
||||
<div className={styles.messageList}>
|
||||
<List
|
||||
dataSource={chatSessions as ContractData[]}
|
||||
dataSource={chatSessions as (ContractData | weChatGroup)[]}
|
||||
renderItem={session => (
|
||||
<List.Item
|
||||
key={session.id}
|
||||
|
||||
@@ -10,17 +10,11 @@ import WechatFriends from "./WechatFriends";
|
||||
import MessageList from "./MessageList/index";
|
||||
import styles from "./SidebarMenu.module.scss";
|
||||
import { useCkChatStore } from "@/store/module/ckchat/ckchat";
|
||||
import { ContractData, weChatGroup } from "@/pages/pc/ckbox/data";
|
||||
interface SidebarMenuProps {
|
||||
loading?: boolean;
|
||||
currentContract?: ContractData | weChatGroup;
|
||||
}
|
||||
|
||||
const SidebarMenu: React.FC<SidebarMenuProps> = ({
|
||||
loading = false,
|
||||
currentContract,
|
||||
}) => {
|
||||
const chatSessions = useCkChatStore(state => state.getChatSessions());
|
||||
const SidebarMenu: React.FC<SidebarMenuProps> = ({ loading = false }) => {
|
||||
const searchKeyword = useCkChatStore(state => state.searchKeyword);
|
||||
const setSearchKeyword = useCkChatStore(state => state.setSearchKeyword);
|
||||
const clearSearchKeyword = useCkChatStore(state => state.clearSearchKeyword);
|
||||
@@ -128,7 +122,7 @@ const SidebarMenu: React.FC<SidebarMenuProps> = ({
|
||||
const renderContent = () => {
|
||||
switch (activeTab) {
|
||||
case "chats":
|
||||
return <MessageList chatSessions={chatSessions} />;
|
||||
return <MessageList />;
|
||||
case "contracts":
|
||||
return <WechatFriends />;
|
||||
case "groups":
|
||||
|
||||
@@ -64,7 +64,7 @@ const CkboxPage: React.FC = () => {
|
||||
|
||||
{/* 左侧联系人边栏 */}
|
||||
<Sider width={280} className={styles.sider}>
|
||||
<SidebarMenu currentContract={currentContract} loading={loading} />
|
||||
<SidebarMenu loading={loading} />
|
||||
</Sider>
|
||||
|
||||
{/* 主内容区 */}
|
||||
|
||||
Reference in New Issue
Block a user