diff --git a/src/stores/ConversationStore.js b/src/stores/ConversationStore.js index 1b8c83b..66dcbe2 100644 --- a/src/stores/ConversationStore.js +++ b/src/stores/ConversationStore.js @@ -2,7 +2,7 @@ import { create } from 'zustand'; import { RealTimeAPI } from '@/channel/realTimeAPI'; import { olog, isEmpty } from '@/utils/commons'; import { receivedMsgTypeMapped, handleNotification } from '@/channel/whatsappUtils'; -import { fetchConversationsList, fetchTemplates, fetchMessages } from '@/actions/ConversationActions'; +import { fetchConversationsList, fetchTemplates, fetchConversationsSearch } from '@/actions/ConversationActions'; import { devtools } from 'zustand/middleware'; import { WS_URL } from '@/config'; @@ -32,6 +32,7 @@ const initialConversationState = { // templates: [], + closedConversationsList: [], // 已关闭的对话列表 conversationsList: [], // 对话列表 currentConversation: {}, // 当前对话 @@ -151,6 +152,7 @@ const conversationSlice = (set, get) => ({ conversationsListLoading: false, conversationsList: [], currentConversation: {}, + closedConversationsList: [], setConversationsListLoading: (conversationsListLoading) => set({ conversationsListLoading }), @@ -161,6 +163,11 @@ const conversationSlice = (set, get) => ({ const conversationsMapped = conversationsList.reduce((r, v) => ({ ...r, [`${v.sn}`]: [] }), {}); return set({ conversationsList, activeConversations: conversationsMapped }); }, + setClosedConversationList: (closedConversationsList) => { + const { activeConversations, } = get(); + const listMapped = closedConversationsList.reduce((r, v) => ({ ...r, [`${v.sn}`]: [] }), {}); + return set({ closedConversationsList, activeConversations: { ...activeConversations, ...listMapped } }); + }, addToConversationList: (newList) => { const { activeConversations, conversationsList } = get(); const conversationsIds = Object.keys(activeConversations); @@ -351,7 +358,7 @@ export const useConversationStore = create( // side effects fetchInitialData: async (userIds) => { - const { addToConversationList, setTemplates, setInitial, } = get(); + const { addToConversationList, setTemplates, setInitial, setClosedConversationList } = get(); const conversationsList = await fetchConversationsList({ opisn: userIds }); addToConversationList(conversationsList); @@ -359,8 +366,10 @@ export const useConversationStore = create( const templates = await fetchTemplates(); setTemplates(templates); - setInitial(true); + const closedList = await fetchConversationsSearch({ opisn: userIds, session_enable: 0 }); + setClosedConversationList(closedList); + setInitial(true); }, reset: () => set(initialConversationState), diff --git a/src/views/Conversations/Online/ConversationsList.jsx b/src/views/Conversations/Online/ConversationsList.jsx index 0f05302..641099c 100644 --- a/src/views/Conversations/Online/ConversationsList.jsx +++ b/src/views/Conversations/Online/ConversationsList.jsx @@ -1,7 +1,7 @@ import { useEffect, useState, useRef } from 'react'; import { useParams, useNavigate, useLocation } from 'react-router-dom'; -import { Dropdown, Input, Button, } from 'antd'; -import { PlusOutlined, WhatsAppOutlined, LoadingOutlined } from '@ant-design/icons'; +import { Dropdown, Input, Button, Empty, Tooltip } from 'antd'; +import { PlusOutlined, WhatsAppOutlined, LoadingOutlined, HistoryOutlined, FireOutlined } from '@ant-design/icons'; import { fetchConversationsList, fetchOrderConversationsList, fetchConversationItemClose, postNewConversationItem } from '@/actions/ConversationActions'; import { ChatItem } from 'react-chat-elements'; import ConversationsNewItem from './ConversationsNewItem'; @@ -28,6 +28,8 @@ const Conversations = ({ mobile }) => { const addToConversationList = useConversationStore((state) => state.addToConversationList); const delConversationitem = useConversationStore((state) => state.delConversationitem); + const closedConversationsList = useConversationStore((state) => state.closedConversationsList); + const isVisible = useVisibilityState(); const [tabSelectedConversation, setTabSelectedConversation] = useState({}); @@ -60,7 +62,7 @@ const Conversations = ({ mobile }) => { useEffect(() => { setDataSource(conversationsList); return () => {}; - }, [conversationsList]); + }, [conversationsList.length]); const [switchToC, setSwitchToC] = useState({}); const [shouldFetchCList, setShouldFetchCList] = useState(true); @@ -165,10 +167,19 @@ const Conversations = ({ mobile }) => { // setNewChatFormValues(values); } + const [activeList, setActiveList] = useState(true); + // const closedVisible = closedConversationsList.length > 0; + const toggleClosedConversationsList = () => { + const _active = activeList; + setDataSource(_active ? closedConversationsList : conversationsList); + setActiveList(!activeList); + setCurrentConversation({}); + } + return (