feat: load archived entries

This commit is contained in:
DIYgod
2024-09-03 23:58:21 +08:00
parent 1dcffc60d2
commit d7f4bb6b9f
6 changed files with 63 additions and 16 deletions
+2
View File
@@ -3279,6 +3279,8 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
publishedAfter?: string | undefined;
publishedBefore?: string | undefined;
collected?: boolean | undefined;
isCollection?: boolean | undefined;
isArchived?: boolean | undefined;
};
};
output: {
@@ -49,7 +49,7 @@ export const styledButtonVariant = cva(
outline: cn(
"bg-theme-background font-semibold transition-colors duration-200",
"border border-border hover:bg-zinc-50/20 dark:bg-neutral-900/30",
"border border-border hover:bg-zinc-50 dark:bg-neutral-900/30 dark:hover:bg-neutral-900/80",
"focus:border-accent/80",
),
text: cn(
@@ -56,7 +56,13 @@ export const useEntryMarkReadHandler = (entriesIds: string[]) => {
scrollMarkUnread,
])
}
export const useEntriesByView = ({ onReset }: { onReset?: () => void }) => {
export const useEntriesByView = ({
onReset,
isArchived,
}: {
onReset?: () => void
isArchived?: boolean
}) => {
const routeParams = useRouteParms()
const unreadOnly = useGeneralSettingKey("unreadOnly")
@@ -71,6 +77,7 @@ export const useEntriesByView = ({ onReset }: { onReset?: () => void }) => {
id: folderIds?.join(",") || feedId,
view,
...(unreadOnly === true && { read: false }),
isArchived,
}
const query = useEntries(entriesOptions)
@@ -1,8 +1,10 @@
import { useGeneralSettingKey } from "@renderer/atoms/settings/general"
import { useUISettingKey } from "@renderer/atoms/settings/ui"
import { m } from "@renderer/components/common/Motion"
import { FeedFoundCanBeFollowError } from "@renderer/components/errors/FeedFoundCanBeFollowErrorFallback"
import { FeedNotFound } from "@renderer/components/errors/FeedNotFound"
import { AutoResizeHeight } from "@renderer/components/ui/auto-resize-height"
import { Button } from "@renderer/components/ui/button"
import { LoadingCircle } from "@renderer/components/ui/loading"
import { ScrollArea } from "@renderer/components/ui/scroll-area"
import {
@@ -22,7 +24,7 @@ import { useFeed } from "@renderer/queries/feed"
import { entryActions, useEntry } from "@renderer/store/entry"
import { useFeedByIdSelector } from "@renderer/store/feed"
import { useSubscriptionByFeedId } from "@renderer/store/subscription"
import { useCallback, useEffect, useRef } from "react"
import { useCallback, useEffect, useRef, useState } from "react"
import type {
ScrollSeekConfiguration,
VirtuosoGridProps,
@@ -44,12 +46,15 @@ const scrollSeekConfiguration: ScrollSeekConfiguration = {
}
export function EntryColumn() {
const virtuosoRef = useRef<VirtuosoHandle>(null)
const [isArchived, setIsArchived] = useState(false)
const unreadOnly = useGeneralSettingKey("unreadOnly")
const entries = useEntriesByView({
onReset: useCallback(() => {
virtuosoRef.current?.scrollTo({
top: 0,
})
}, []),
isArchived,
})
const { entriesIds, isFetchingNextPage, groupedCounts } = entries
@@ -79,14 +84,41 @@ export function EntryColumn() {
const handleMarkReadInRange = useEntryMarkReadHandler(entriesIds)
useEffect(() => {
if (isArchived) {
if (entries.hasNextPage) {
entries.fetchNextPage()
} else {
entries.refetch()
}
}
}, [isArchived])
const showArchivedButton = !isArchived && !unreadOnly && !isCollection && routeFeedId !== ROUTE_FEED_PENDING && entries.totalCount < 40
const scrollRef = useRef<HTMLDivElement>(null)
const virtuosoOptions = {
components: {
List: EntryListContent,
Footer: useCallback(() => {
if (!isFetchingNextPage) return null
return <EntryItemSkeleton view={view} count={Math.min(entries.data?.pages?.[0].data?.length || 20, entries.data?.pages.at(-1)?.remaining || 20)} />
}, [isFetchingNextPage, view]),
if (!isFetchingNextPage) {
if (showArchivedButton) {
return (
<div className="flex justify-center py-4">
<Button
variant="outline"
onClick={() => setIsArchived(true)}
>
Load archived entries
</Button>
</div>
)
} else {
return null
}
} else {
return <EntryItemSkeleton view={view} count={Math.min(entries.data?.pages?.[0].data?.length || 20, entries.data?.pages.at(-1)?.remaining || 20)} />
}
}, [isFetchingNextPage, view, unreadOnly, isArchived, entries]),
ScrollSeekPlaceholder: useCallback(
() => <EntryItemSkeleton view={view} count={1} />,
[view],
@@ -102,8 +134,11 @@ export function EntryColumn() {
totalCount: entries.totalCount,
endReached: useCallback(async () => {
if (!entries.isFetchingNextPage && entries.hasNextPage) {
await entries.fetchNextPage()
if (!entries.isFetchingNextPage) {
const remaining = entries.data?.pages.at(-1)?.remaining
if (entries.hasNextPage && remaining) {
await entries.fetchNextPage()
}
}
}, [entries]),
data: entriesIds,
@@ -169,7 +204,7 @@ export function EntryColumn() {
rootClassName="h-full"
viewportClassName="[&>div]:grow flex"
>
{virtuosoOptions.totalCount === 0 ? (
{virtuosoOptions.totalCount === 0 && !showArchivedButton ? (
entries.isLoading ?
null :
(
+7 -7
View File
@@ -11,11 +11,13 @@ export const entries = {
view,
read,
limit,
isArchived,
}: {
id?: number | string
view?: number
read?: boolean
limit?: number
isArchived?: boolean
}) =>
defineQuery(
["entries", id, view, read, limit],
@@ -26,6 +28,7 @@ export const entries = {
read,
limit,
pageParam: pageParam as string,
isArchived,
}),
{
rootKey: ["entries", id],
@@ -109,19 +112,16 @@ export const useEntries = ({
id,
view,
read,
isArchived,
}: {
id?: number | string
view?: number
read?: boolean
isArchived?: boolean
}) =>
useAuthInfiniteQuery(entries.entries({ id, view, read }), {
useAuthInfiniteQuery(entries.entries({ id, view, read, isArchived }), {
enabled: id !== undefined,
getNextPageParam: (lastPage) => {
if (!lastPage.data?.length || lastPage.remaining === 0) {
return null
}
return lastPage.data.at(-1)!.entries.publishedAt
},
getNextPageParam: (lastPage) => lastPage.data?.at(-1)?.entries.publishedAt,
initialPageParam: undefined,
refetchOnWindowFocus: false,
refetchOnReconnect: false,
+3
View File
@@ -85,18 +85,21 @@ class EntryActions {
read,
limit,
pageParam,
isArchived,
}: {
id?: number | string
view?: number
read?: boolean
limit?: number
pageParam?: string
isArchived?: boolean
}) {
const data = await apiClient.entries.$post({
json: {
publishedAfter: pageParam,
read,
limit,
isArchived,
// withContent: true,
...getEntriesParams({
id,