From deeb2672daa9edbb0cfc2d0742c1fd07d28409d9 Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 9 Jul 2024 16:05:57 +0800 Subject: [PATCH] fix: remote data first, add comment for explain why Signed-off-by: Innei --- .../src/modules/entry-column/hooks.ts | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/renderer/src/modules/entry-column/hooks.ts b/src/renderer/src/modules/entry-column/hooks.ts index 81a0d2ae2..6b743a4f3 100644 --- a/src/renderer/src/modules/entry-column/hooks.ts +++ b/src/renderer/src/modules/entry-column/hooks.ts @@ -3,10 +3,7 @@ import { useRouteParamsSelector, useRouteParms, } from "@renderer/hooks/biz/useRouteParams" -import { - levels, - views, -} from "@renderer/lib/constants" +import { levels, views } from "@renderer/lib/constants" import { shortcuts } from "@renderer/lib/shortcuts" import { useEntries } from "@renderer/queries/entries" import { entryActions, useEntryIdsByFeedIdOrView } from "@renderer/store/entry" @@ -75,13 +72,10 @@ export const useEntriesByView = () => { view, ...(unreadOnly === true && { read: false }), }) - const entries = useEntryIdsByFeedIdOrView( - isAllFeeds ? view : feedId!, - { - unread: unreadOnly, - view, - }, - ) + const entries = useEntryIdsByFeedIdOrView(isAllFeeds ? view : feedId!, { + unread: unreadOnly, + view, + }) useHotkeys( shortcuts.entries.refetch.key, @@ -116,21 +110,26 @@ export const useEntriesByView = () => { prevEntries.current = nextIds return nextIds }, [entries, prevEntries, unreadOnly]) - const sortedLocalEntries = useMemo( - () => - isCollection ? - sortEntriesIdByStarAt(localEntries) : - sortEntriesIdByEntryPublishedAt(localEntries), - [isCollection, localEntries], - ) + + const sortLocalEntries = () => + isCollection ? + sortEntriesIdByStarAt(localEntries) : + sortEntriesIdByEntryPublishedAt(localEntries) + const remoteEntryIds = query.data?.pages + ?.map((page) => page.data?.map((entry) => entry.entries.id)) + .flat() return { ...query, // If remote data is not available, we use the local data, get the local data length - totalCount: query.data?.pages?.[0]?.total ? Math.max(query.data?.pages?.[0]?.total, localEntries.length) : localEntries.length, - entriesIds: sortedLocalEntries, - // entriesIds: remoteEntryIds, + // FIXME: remote first, then local store data + // NOTE: We still can't use the store's data handling directly. + // Imagine that the local data may be persistent, and then if there are incremental updates to the data on the server side, + // then we have no way to incrementally update the data. + // We need to add an interface to incrementally update the data based on the version hash. + entriesIds: remoteEntryIds ?? sortLocalEntries(), + totalCount: query.data?.pages?.[0]?.total ?? localEntries.length, } }