fix(entry-column): pre-render cached entries

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei 2024-10-29 22:15:42 +08:00
parent 120cf43bcd
commit 5065c8e52d
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
1 changed files with 11 additions and 11 deletions

View File

@ -49,6 +49,7 @@ export const useEntryMarkReadHandler = (entriesIds: string[]) => {
return
}, [feedView, handleMarkReadInRange, handleRenderAsRead, renderAsRead, scrollMarkUnread])
}
const anyString = [] as string[]
export const useEntriesByView = ({
onReset,
isArchived,
@ -103,16 +104,15 @@ export const useEntriesByView = ({
setPauseQuery(hasUpdate)
}, [hasUpdate])
const remoteEntryIds = useMemo(
() =>
// FIXME The back end should not return duplicate data, and the front end the unique id here.
[
...new Set(
query.data?.pages?.map((page) => page.data?.map((entry) => entry.entries.id)).flat(),
).values(),
] as string[],
[query.data?.pages],
)
const remoteEntryIds = useMemo(() => {
if (!query.data?.pages) return void 0
// FIXME The back end should not return duplicate data, and the front end the unique id here.
return [
...new Set(
query.data?.pages?.map((page) => page.data?.map((entry) => entry.entries.id)).flat(),
).values(),
] as string[]
}, [query.data?.pages])
const currentEntries = useEntryIdsByFeedIdOrView(isAllFeeds ? view : folderIds || feedId!, {
unread: unreadOnly,
@ -126,7 +126,7 @@ export const useEntriesByView = ({
// 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.
const entryIds = remoteEntryIds || currentEntries
const entryIds: string[] = remoteEntryIds || currentEntries || anyString
// in unread only entries only can grow the data, but not shrink
// so we memo this previous data to avoid the flicker