Skip to content

Commit

Permalink
fix: fix sync list
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglun committed Oct 28, 2023
1 parent 707cdd0 commit 6bc0085
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 39 deletions.
62 changes: 25 additions & 37 deletions src/components/Subscribes/useRefresh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const useRefresh = () => {

collectionMeta: state.collectionMeta,
updateCollectionMeta: state.updateCollectionMeta,
syncArticles: state.syncArticles,
}));
const [refreshing, setRefreshing] = useState<boolean>(false);
const [done, setDone] = useState<number>(0);
Expand All @@ -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();
})
Expand All @@ -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)
);
});

Expand All @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/stores/createFeedSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,11 @@ export const createFeedSlice: StateCreator<FeedSlice> = (
.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});
Expand All @@ -272,6 +275,7 @@ export const createFeedSlice: StateCreator<FeedSlice> = (
_.children.forEach(child => {
if (map[child.uuid]) {
child.unread += map[child.uuid][0];
_.unread += map[child.uuid][0];
}
})
}
Expand Down

0 comments on commit 6bc0085

Please sign in to comment.