From 6bc0085f92adadecf2ccf0d57e3192621eaf106a Mon Sep 17 00:00:00 2001 From: zhanglun Date: Sat, 28 Oct 2023 16:21:45 +0800 Subject: [PATCH] fix: fix sync list --- src/components/Subscribes/useRefresh.tsx | 62 ++++++++++-------------- src/stores/createFeedSlice.ts | 8 ++- 2 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/components/Subscribes/useRefresh.tsx b/src/components/Subscribes/useRefresh.tsx index c6bad644f..f6e0dcc1a 100644 --- a/src/components/Subscribes/useRefresh.tsx +++ b/src/components/Subscribes/useRefresh.tsx @@ -14,6 +14,7 @@ export const useRefresh = () => { collectionMeta: state.collectionMeta, updateCollectionMeta: state.updateCollectionMeta, + syncArticles: state.syncArticles, })); const [refreshing, setRefreshing] = useState(false); const [done, setDone] = useState(0); @@ -24,25 +25,12 @@ export const useRefresh = () => { store.getFeedList(); }; - const loadAndUpdate = (type: string, uuid: string, unread: number) => { - return dataAgent - .syncFeed(type, uuid) - .then((res) => { - const { data } = res; - console.log("%c Line:29 🍌 data", "color:#ffdd4d", data); - - data.forEach((item) => { - const [count, uuid, _msg] = item; - - if (count) { - store.updateCollectionMeta(count, count); - store.updateFeed(uuid, { unread: unread + count }); - } - }); - - return data; + const loadAndUpdate = (channel: FeedResItem) => { + return store.syncArticles(channel) + .then(() => { + return Promise.resolve(); }) - .catch((err) => { + .catch((err: any) => { console.log("%c Line:239 🍬 err", "color:#2eafb0", err); return Promise.resolve(); }) @@ -64,7 +52,7 @@ export const useRefresh = () => { const limit = pLimit(threads); const fns = (store.feedList || []).map((channel: any) => { return limit(() => - loadAndUpdate(channel.item_type, channel.uuid, channel.unread) + loadAndUpdate(channel) ); }); @@ -74,28 +62,28 @@ export const useRefresh = () => { setRefreshing(false); setDone(0); getFeedList(); - loop(); + // loop(); }); }); }; - function loop() { - if (timeRef.current) { - clearTimeout(timeRef.current); - } - - if (store.userConfig.update_interval) { - timeRef.current = setTimeout(() => { - startRefresh(); - console.log("%c Line:113 🥕 startRefresh", "color:#42b983"); - loop(); - }, store?.userConfig?.update_interval * 60 * 60 * 1000); - } - } - - useEffect(() => { - loop(); - }, [store.userConfig.update_interval]); + // function loop() { + // if (timeRef.current) { + // clearTimeout(timeRef.current); + // } + // + // if (store.userConfig.update_interval) { + // timeRef.current = setTimeout(() => { + // startRefresh(); + // console.log("%c Line:113 🥕 startRefresh", "color:#42b983"); + // loop(); + // }, store?.userConfig?.update_interval * 60 * 60 * 1000); + // } + // } + + // useEffect(() => { + // loop(); + // }, [store.userConfig.update_interval]); return [ store.feedList, diff --git a/src/stores/createFeedSlice.ts b/src/stores/createFeedSlice.ts index 93669e156..074b629cc 100644 --- a/src/stores/createFeedSlice.ts +++ b/src/stores/createFeedSlice.ts @@ -258,8 +258,11 @@ export const createFeedSlice: StateCreator = ( .then((resList) => { const map = resList.reduce((acu, { data }) => { console.log('===> data', data); - const [[uuid, values]] = Object.entries(data); - acu[uuid] = values; + const [[uuid, values] = []] = Object.entries(data); + + if (uuid && values) { + acu[uuid] = values; + } return acu; }, {} as { [key: string]: any}); @@ -272,6 +275,7 @@ export const createFeedSlice: StateCreator = ( _.children.forEach(child => { if (map[child.uuid]) { child.unread += map[child.uuid][0]; + _.unread += map[child.uuid][0]; } }) }