From eb8d59b2e8dedf4d8f3ff283282a9f84e1460c12 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Tue, 29 Oct 2024 16:20:09 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=BD=93=E5=89=8D=E4=BC=9A=E8=AF=9D:?= =?UTF-8?q?=20=E4=BD=BF=E7=94=A8=E4=BC=9A=E8=AF=9DID,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Online/ConversationsList.jsx | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/views/Conversations/Online/ConversationsList.jsx b/src/views/Conversations/Online/ConversationsList.jsx index e59e47c..fa654de 100644 --- a/src/views/Conversations/Online/ConversationsList.jsx +++ b/src/views/Conversations/Online/ConversationsList.jsx @@ -69,22 +69,37 @@ const Conversations = () => { return () => {}; }, [conversationsList, listUpdateFlag, currentConversation.unread_msg_count]); - const [switchToC, setSwitchToC] = useState({}); - const [shouldFetchCList, setShouldFetchCList] = useState(true); useEffect(() => { - if (order_sn && shouldFetchCList && initialState) { - getOrderConversationList(order_sn); + if (isEmpty(currentConversation.sn) && order_sn && shouldFetchCList && initialState) { + getOrderConversationList(order_sn) } - return () => {}; - }, [order_sn, shouldFetchCList, initialState]); + return () => {} + }, [conversationsList, initialState]) + + + const [switchToC, setSwitchToC] = useState({}); + const [shouldFetchCList, setShouldFetchCList] = useState(true); + // useEffect(() => { + // console.log('shouldFetchCList', order_sn , shouldFetchCList , initialState); + + // if (order_sn && shouldFetchCList && initialState) { + // getOrderConversationList(order_sn); + // } + + // return () => {}; + // }, [order_sn, shouldFetchCList, initialState]); const getOrderConversationList = async (colisn, WHATSAPP_ID = null) => { const { whatsapp_phone_number } = switchToC; const whatsappID = WHATSAPP_ID || coli_guest_WhatsApp || whatsapp_phone_number || ''; // let findCurrentOrderChats = conversationsList.filter((item) => `${item.coli_sn}` === `${colisn}`); // 使用opisn + whatsappID 判断, 解决订单修改whatsappID号码之后获取新会话, 登录账号此处省略 - let findCurrentOrderChats = conversationsList.filter((item) => `${item.whatsapp_phone_number}` === `${whatsappID}` && `${item.coli_sn}` === `${colisn}`); + if (isEmpty(conversationsList)) { + return false; + } + + let findCurrentOrderChats = conversationsList.filter((item) => `${item.whatsapp_phone_number}` === `${whatsappID}` && `${item.coli_sn}` === `${colisn}`) let findCurrentIndex = isEmpty(findCurrentOrderChats) ? -1 : 0; // findCurrentOrderChats.length-1; let findCurrent = findCurrentOrderChats[findCurrentIndex]; if (findCurrentIndex !== -1) { @@ -108,7 +123,7 @@ const Conversations = () => { return findCurrent; } else { // reset chat window - setCurrentConversation({ sn: '', customer_name: '', coli_sn: order_sn }); + // setCurrentConversation({ sn: '', customer_name: '', coli_sn: order_sn }); return false; } };