Преглед на файлове

refactor: 减少联系人页、数据页请求

王晓东 преди 2 месеца
родител
ревизия
a7f76819d5
променени са 3 файла, в които са добавени 13 реда и са изтрити 10 реда
  1. 3 1
      src/pages/contact/index.tsx
  2. 9 8
      src/pages/dashboard/index.tsx
  3. 1 1
      src/service/chat.ts

+ 3 - 1
src/pages/contact/index.tsx

@@ -44,7 +44,9 @@ export default function Index() {
   };
   const { data, list, setSize, mutate, pageIndex } = useLoadMoreInfinite<
     TContactItem[]
-  >(getKey, fetcher);
+  >(getKey, fetcher, {
+    revalidateOnMount: false
+  });
 
   const handleSearchBarChanged = (v: string) => {
     setSearchValue(v);

+ 9 - 8
src/pages/dashboard/index.tsx

@@ -35,7 +35,9 @@ export default () => {
   };
   const { list, loadMore, mutate } = useLoadMoreInfinite<TVisitorAgent[]>(
     createKey(`getVisitorList ${currentAgent?.agentId}`, 20, [currentAgent?.agentId]),
-    fetcher);
+    fetcher, {
+      revalidateOnMount: false
+    });
 
   
   // 统计数据
@@ -48,16 +50,18 @@ export default () => {
 
   const fetchInitData = async () => {
     await fetchAgents();
-    fetchSummary()
-    
   }
 
+  useEffect(()=> {
+    fetchInitData();
+  }, [])
+
   useEffect(() => {
     fetchSummary()
+    mutate()
   }, [currentAgent])
 
   useDidShow(()=> {
-    fetchInitData()
     mutate()
   })
 
@@ -65,6 +69,7 @@ export default () => {
   // 登录完成后
   const onLoginEnd = ()=> {
     fetchInitData()
+    fetchSummary()
     mutate()
   }
   
@@ -74,10 +79,6 @@ export default () => {
     loadMore()
   })
 
-  useDidShow(()=> {
-    mutate()
-  })
-
   const unprocessedDislikeCnt = summary?.unprocessedDislikeCnt ?? 0
 
   if(!agents) {

+ 1 - 1
src/service/chat.ts

@@ -101,7 +101,7 @@ export const requestStream = <T>({
     onFinished(m);
   });
   
-  const onChunkReceived = (chunk: any) => {
+  const onChunkReceived = (chunk: {data: ArrayBuffer}) => {
     // console.log('chunkReceived: ', chunk);
     const uint8Array = new Uint8Array(chunk.data);
     // console.log('uint8Array: ', uint8Array);