feat: mark all as read api
This commit is contained in:
@@ -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 (
|
||||
<div className="mb-5 flex w-full items-center justify-between pl-9 pr-2">
|
||||
<div>
|
||||
@@ -196,7 +212,7 @@ const ListHeader: FC = () => {
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">{unreadOnly ? "Unread Only" : "All"}</TooltipContent>
|
||||
</Tooltip>
|
||||
<Popover>
|
||||
<Popover open={markPopoverOpen} onOpenChange={setMarkPopoverOpen}>
|
||||
<PopoverTrigger>
|
||||
<Tooltip>
|
||||
<TooltipTrigger>
|
||||
@@ -214,7 +230,7 @@ const ListHeader: FC = () => {
|
||||
<Button size="sm" variant="outline">Cancel</Button>
|
||||
</PopoverClose>
|
||||
{/* TODO */}
|
||||
<Button size="sm">Confirm</Button>
|
||||
<Button size="sm" onClick={handleMarkAllAsRead}>Confirm</Button>
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
||||
@@ -45,6 +45,22 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
status: 200;
|
||||
};
|
||||
};
|
||||
"/reads/all": {
|
||||
$post: {
|
||||
input: {
|
||||
json: {
|
||||
feedId?: string | undefined;
|
||||
view?: number | undefined;
|
||||
feedIdList?: string[] | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 0;
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
};
|
||||
};
|
||||
} & {
|
||||
"/collections": {
|
||||
$get: {
|
||||
|
||||
@@ -2,6 +2,8 @@ import type { ClassValue } from "clsx"
|
||||
import { clsx } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
|
||||
import { levels } from "./constants"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
@@ -9,3 +11,27 @@ export function cn(...inputs: ClassValue[]) {
|
||||
export function clamp(value, min, max) {
|
||||
return Math.max(Math.min(max, value), min)
|
||||
}
|
||||
|
||||
export function getEntriesParams({
|
||||
level,
|
||||
id,
|
||||
view,
|
||||
}: {
|
||||
level?: string
|
||||
id?: number | string
|
||||
view?: number
|
||||
}) {
|
||||
const params: {
|
||||
feedId?: string
|
||||
feedIdList?: string[]
|
||||
} = {}
|
||||
if (level === levels.folder) {
|
||||
params.feedIdList = `${id}`.split(",")
|
||||
} else if (level === levels.feed) {
|
||||
params.feedId = `${id}`
|
||||
}
|
||||
return {
|
||||
view,
|
||||
...params,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { levels } from "@renderer/lib/constants"
|
||||
import type { EntryModel } from "@renderer/lib/types"
|
||||
import { getEntriesParams } from "@renderer/lib/utils"
|
||||
import { apiClient } from "@renderer/queries/api-fetch"
|
||||
import type { InferResponseType } from "hono/client"
|
||||
import { produce } from "immer"
|
||||
@@ -24,6 +24,7 @@ interface EntryActions {
|
||||
}) => Promise<InferResponseType<typeof apiClient.entries.$post>>
|
||||
upsert: (feedId: string, entry: EntryModel) => void
|
||||
optimisticUpdate: (entryId: string, changed: Partial<EntryModel>) => void
|
||||
optimisticUpdateAll: (changed: Partial<EntryModel>) => void
|
||||
getFlattenMapEntries: () => Record<string, EntryModel>
|
||||
}
|
||||
|
||||
@@ -48,21 +49,15 @@ export const useEntryStore = create<EntryState & { actions: EntryActions }>(
|
||||
|
||||
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<EntryState & { actions: EntryActions }>(
|
||||
}),
|
||||
)
|
||||
},
|
||||
optimisticUpdateAll(changed: Partial<EntryModel>) {
|
||||
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) =>
|
||||
|
||||
Reference in New Issue
Block a user