From 8d2478c6a93aa9f5a99fddc55bbb8e532e1a0fe1 Mon Sep 17 00:00:00 2001 From: Innei Date: Fri, 1 Nov 2024 18:19:01 +0800 Subject: [PATCH] fix: auto archived list flash (#1269) * fix: auto archived list flash Signed-off-by: Innei * fix: reset isArchived on location change * chore: auto-fix linting and formatting issues * fix --------- Signed-off-by: Innei Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Co-authored-by: hyoban --- .../src/modules/entry-column/hooks.ts | 7 ++- .../src/modules/entry-column/index.tsx | 43 +++++++++++-------- apps/renderer/src/queries/entries.ts | 2 +- locales/app/ja.json | 1 - 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/apps/renderer/src/modules/entry-column/hooks.ts b/apps/renderer/src/modules/entry-column/hooks.ts index b42d375c9..ab8c1130e 100644 --- a/apps/renderer/src/modules/entry-column/hooks.ts +++ b/apps/renderer/src/modules/entry-column/hooks.ts @@ -135,12 +135,15 @@ export const useEntriesByView = ({ const isFetchingFirstPage = query.isFetching && !query.isFetchingNextPage useEffect(() => { + if (isArchived) { + return + } if (!isFetchingFirstPage) { prevEntryIdsRef.current = entryIds setMergedEntries({ ...mergedEntries, [view]: entryIds }) onReset?.() } - }, [isFetchingFirstPage]) + }, [isFetchingFirstPage, isArchived]) const [mergedEntries, setMergedEntries] = useState>({ 0: [], @@ -207,7 +210,7 @@ export const useEntriesByView = ({ } return counts - }, [groupByDate, sortEntries, view]) + }, [groupByDate, listId, sortEntries, view]) return { ...query, diff --git a/apps/renderer/src/modules/entry-column/index.tsx b/apps/renderer/src/modules/entry-column/index.tsx index 072aa755d..861667cd9 100644 --- a/apps/renderer/src/modules/entry-column/index.tsx +++ b/apps/renderer/src/modules/entry-column/index.tsx @@ -52,13 +52,19 @@ function EntryColumnImpl() { virtuosoRef.current?.scrollTo({ top: 0, }) - setIsArchived(false) }, []), isArchived, }) const { entriesIds, isFetchingNextPage, groupedCounts } = entries useSnapEntryIdList(entriesIds) + const prevEntriesIdsRef = useRef(entriesIds) + + useEffect(() => { + if (entriesIds.length > 0) { + prevEntriesIdsRef.current = entriesIds + } + }, [entriesIds]) const { entryId: activeEntryId, @@ -69,6 +75,11 @@ function EntryColumnImpl() { inboxId, listId, } = useRouteParams() + + useEffect(() => { + setIsArchived(false) + }, [view, routeFeedId]) + const activeEntry = useEntry(activeEntryId) const feed = useFeedById(routeFeedId) const title = useFeedHeaderTitle() @@ -99,24 +110,17 @@ function EntryColumnImpl() { } }, [isArchived]) - const showArchivedButton = - !isArchived && - !unreadOnly && - !isCollection && - routeFeedId !== ROUTE_FEED_PENDING && - entries.totalCount < 40 && - feed?.type === "feed" + // Common conditions for both showArchivedButton and shouldLoadArchivedEntries + const commonConditions = + !isArchived && !unreadOnly && !isCollection && routeFeedId !== ROUTE_FEED_PENDING + // Determine if the archived button should be shown + const showArchivedButton = commonConditions && entries.totalCount < 40 && feed?.type === "feed" + const hasNoEntries = entries.totalCount === 0 && !entries.isLoading + + // Determine if archived entries should be loaded const shouldLoadArchivedEntries = - !isArchived && - !unreadOnly && - !isCollection && - routeFeedId !== ROUTE_FEED_PENDING && - (feed?.type === "feed" || !feed) && - !inboxId && - !listId && - entries.totalCount === 0 && - !entries.isLoading + commonConditions && (feed?.type === "feed" || !feed) && !inboxId && !listId && hasNoEntries // automatically fetch archived entries when there is no entries in timeline useEffect(() => { @@ -125,6 +129,9 @@ function EntryColumnImpl() { } }, [shouldLoadArchivedEntries]) + const finalEntriesIds = + hasNoEntries && !isArchived ? prevEntriesIdsRef.current || entriesIds : entriesIds + const scrollRef = useRef(null) const virtuosoOptions = { components: { @@ -173,7 +180,7 @@ function EntryColumnImpl() { } } }, [entries]), - data: entriesIds, + data: finalEntriesIds, onScroll: () => { if (!isInteracted.current) { isInteracted.current = true diff --git a/apps/renderer/src/queries/entries.ts b/apps/renderer/src/queries/entries.ts index 6c84dc27d..19c21a496 100644 --- a/apps/renderer/src/queries/entries.ts +++ b/apps/renderer/src/queries/entries.ts @@ -24,7 +24,7 @@ export const entries = { isArchived?: boolean }) => defineQuery( - ["entries", inboxId || listId || feedId, view, read, limit], + ["entries", inboxId || listId || feedId, view, read, limit, isArchived], async ({ pageParam }) => entryActions.fetchEntries({ feedId, diff --git a/locales/app/ja.json b/locales/app/ja.json index 2816475f0..a864aea92 100644 --- a/locales/app/ja.json +++ b/locales/app/ja.json @@ -14,7 +14,6 @@ "achievement.list_subscribe_500": "500 リスト購読者", "achievement.list_subscribe_500_description": "あなたが作成したリストの購読者数が 500 人を超えました", "achievement.list_subscribe_50_description": "あなたが作成したリストの購読者数が 50 人を超えました", - "achievement.mint_more_power": "ハードコア プレイヤーになるとさらなる報酬を得られます ", "achievement.product_hunt_vote": "Product Hunt 投票者", "achievement.product_hunt_vote_description": "あなたは Product Hunt での Follow サポーターです", "activation.activate": "有効化",