From f0daae30cd908ee6c1a5f230b7e7719a11f7f44a Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Sun, 13 Dec 2020 00:22:49 +0100 Subject: [PATCH] Fix timeline when length is short When list is short, it somehow can fetch more --- src/components/Timelines/Timeline.tsx | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/components/Timelines/Timeline.tsx b/src/components/Timelines/Timeline.tsx index 989ec54f..fc509685 100644 --- a/src/components/Timelines/Timeline.tsx +++ b/src/components/Timelines/Timeline.tsx @@ -39,7 +39,16 @@ const Timeline: React.FC = ({ return () => AppState.removeEventListener('change', handleAppStateChange) }) - const queryKey: App.QueryKey = [page, { page, hashtag, list, toot, account }] + const queryKey: App.QueryKey = [ + page, + { + page, + ...(hashtag && { hashtag }), + ...(list && { list }), + ...(toot && { toot }), + ...(account && { account }) + } + ] const { isSuccess, isLoading, @@ -50,7 +59,14 @@ const Timeline: React.FC = ({ fetchMore, refetch } = useInfiniteQuery(queryKey, timelineFetch, { - getFetchMore: last => last?.toots.length > 0 + getFetchMore: (last, all) => { + const allLastGroup = all[all.length - 1]! + return ( + last?.toots.length > 0 && + allLastGroup.toots[allLastGroup.toots.length - 1].id !== + last?.toots[last?.toots.length - 1].id + ) + } }) const flattenData = data ? data.flatMap(d => [...d?.toots]) : [] const flattenPointer = data ? data.flatMap(d => [d?.pointer]) : [] @@ -71,7 +87,7 @@ const Timeline: React.FC = ({ const flRenderItem = useCallback(({ item }) => { switch (page) { case 'Conversations': - return + return case 'Notifications': return default: