feat: reuse feed actions in entry column

This commit is contained in:
DIYgod 2024-07-26 00:00:24 +08:00
parent 72e90f7f6a
commit a3e24e7a3d
No known key found for this signature in database
2 changed files with 33 additions and 12 deletions

View File

@ -12,9 +12,11 @@ import { useDeleteSubscription } from "./useSubscriptionActions"
export const useFeedActions = ({
feedId,
view,
type,
}: {
feedId: string
view?: number
type?: "feedList" | "entryList"
}) => {
const feed = useFeedById(feedId)
const subscription = useSubscriptionByFeedId(feedId)
@ -25,12 +27,14 @@ export const useFeedActions = ({
feedId,
})
const isEntryList = type === "entryList"
const items = useMemo(() => {
if (!feed) return []
const items = [
{
type: "text" as const,
label: "Edit",
label: isEntryList ? "Edit Feed" : "Edit",
click: () => {
present({
@ -43,16 +47,17 @@ export const useFeedActions = ({
},
{
type: "text" as const,
label: "Unfollow",
label: isEntryList ? "Unfollow Feed" : "Unfollow",
click: () => deleteSubscription.mutate(subscription),
},
{
type: "separator" as const,
disabled: isEntryList,
},
...(!feed.ownerUserId && !!feed.id ?
[{
type: "text" as const,
label: "Claim",
label: isEntryList ? "Claim Feed" : "Claim",
click: () => {
claimFeed()
},
@ -68,16 +73,19 @@ export const useFeedActions = ({
[]),
{
type: "separator" as const,
disabled: isEntryList,
},
{
type: "text" as const,
label: "Open Feed in Browser",
disabled: isEntryList,
click: () =>
window.open(`${WEB_URL}/feed/${feedId}?view=${view}`, "_blank"),
},
{
type: "text" as const,
label: "Open Site in Browser",
disabled: isEntryList,
click: () => {
const feed = getFeedById(feedId)
if (feed) {

View File

@ -2,6 +2,7 @@ import { useGeneralSettingKey } from "@renderer/atoms/settings/general"
import { views } from "@renderer/constants"
import { useAsRead } from "@renderer/hooks/biz/useAsRead"
import { useEntryActions } from "@renderer/hooks/biz/useEntryActions"
import { useFeedActions } from "@renderer/hooks/biz/useFeedActions"
import { useNavigateEntry } from "@renderer/hooks/biz/useNavigateEntry"
import { useRouteParamsSelector } from "@renderer/hooks/biz/useRouteParams"
import { useAuthQuery } from "@renderer/hooks/common"
@ -41,6 +42,12 @@ function EntryItemImpl({
entry,
})
const { items: feedItems } = useFeedActions({
feedId: entry.feedId,
view,
type: "entryList",
})
const translation = useAuthQuery(
Queries.ai.translation({
entry,
@ -130,18 +137,24 @@ function EntryItemImpl({
(e) => {
e.preventDefault()
showNativeMenu(
items
.filter((item) => !item.disabled)
.map((item) => ({
type: "text",
label: item.name,
click: item.onClick,
shortcut: item.shortcut,
})),
[
...(items
.filter((item) => !item.disabled)
.map((item) => ({
type: "text" as const,
label: item.name,
click: item.onClick,
shortcut: item.shortcut,
}))),
{
type: "separator" as const,
},
...(feedItems.filter((item) => !item.disabled)),
],
e,
)
},
[items],
[items, feedItems],
)
return (