diff --git a/src/renderer/src/components/entry-column/index.tsx b/src/renderer/src/components/entry-column/index.tsx index b07f81f0e..ad4f6bee5 100644 --- a/src/renderer/src/components/entry-column/index.tsx +++ b/src/renderer/src/components/entry-column/index.tsx @@ -12,7 +12,7 @@ import { } from "@renderer/components/ui/tooltip" import { views } from "@renderer/lib/constants" import { buildStorageNS } from "@renderer/lib/ns" -import { cn } from "@renderer/lib/utils" +import { cn, getEntriesParams } from "@renderer/lib/utils" import { apiClient } from "@renderer/queries/api-fetch" import { useEntries } from "@renderer/queries/entries" import { feedActions, useFeedStore } from "@renderer/store" @@ -22,7 +22,7 @@ import { useAtom, useAtomValue } from "jotai" import { atomWithStorage } from "jotai/utils" import { debounce } from "lodash-es" import type { FC } from "react" -import { forwardRef } from "react" +import { forwardRef, useCallback, useState } from "react" import type { ListRange } from "react-virtuoso" import { Virtuoso, VirtuosoGrid } from "react-virtuoso" import { useEventCallback } from "usehooks-ts" @@ -169,6 +169,22 @@ const ListHeader: FC = () => { const [unreadOnly, setUnreadOnly] = useAtom(unreadOnlyAtom) const entries = useEntriesByTab() + const [markPopoverOpen, setMarkPopoverOpen] = useState(false) + const handleMarkAllAsRead = useCallback(async () => { + if (!activeList) return + await apiClient.reads.all.$post({ + json: { + ...getEntriesParams({ + level: activeList?.level, + id: activeList?.id, + view: activeList?.view, + }), + }, + }) + entryActions.optimisticUpdateAll({ read: true }) + setMarkPopoverOpen(false) + }, [activeList]) + return (
@@ -196,7 +212,7 @@ const ListHeader: FC = () => { {unreadOnly ? "Unread Only" : "All"} - + @@ -214,7 +230,7 @@ const ListHeader: FC = () => { {/* TODO */} - +
diff --git a/src/renderer/src/hono.ts b/src/renderer/src/hono.ts index 739c2684c..46f4f1dc0 100644 --- a/src/renderer/src/hono.ts +++ b/src/renderer/src/hono.ts @@ -45,6 +45,22 @@ declare const routes: hono_hono_base.HonoBase Promise> upsert: (feedId: string, entry: EntryModel) => void optimisticUpdate: (entryId: string, changed: Partial) => void + optimisticUpdateAll: (changed: Partial) => void getFlattenMapEntries: () => Record } @@ -48,21 +49,15 @@ export const useEntryStore = create( pageParam?: string }) => { - const params: { - feedId?: string - feedIdList?: string[] - } = {} - if (level === levels.folder) { - params.feedIdList = `${id}`.split(",") - } else if (level === levels.feed) { - params.feedId = `${id}` - } const res = await apiClient.entries.$post({ json: { publishedAfter: pageParam as string, - view, read, - ...params, + ...getEntriesParams({ + level, + id, + view, + }), }, }) @@ -89,6 +84,16 @@ export const useEntryStore = create( }), ) }, + optimisticUpdateAll(changed: Partial) { + set((state) => + produce(state, (draft) => { + for (const entry of Object.values(draft.flatMapEntries)) { + Object.assign(entry, changed) + } + return draft + }), + ) + }, upsert(feedId: string, entry: EntryModel) { set((state) =>