From 706f4847576fbb0237925434d4dace5c22fdbf93 Mon Sep 17 00:00:00 2001
From: Stephen Zhou <38493346+hyoban@users.noreply.github.com>
Date: Tue, 19 Nov 2024 16:45:29 +0800
Subject: [PATCH] fix: allow collect entry from list
---
apps/renderer/src/hooks/biz/useEntryActions.tsx | 5 +++--
apps/renderer/src/modules/command/commands/entry.tsx | 7 ++++---
apps/renderer/src/modules/command/commands/types.ts | 4 +++-
apps/renderer/src/modules/entry-content/header.tsx | 6 +++---
apps/renderer/src/modules/entry-content/index.tsx | 2 +-
apps/renderer/src/store/entry/store.ts | 4 +++-
packages/shared/src/hono.ts | 1 +
7 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/apps/renderer/src/hooks/biz/useEntryActions.tsx b/apps/renderer/src/hooks/biz/useEntryActions.tsx
index b4231de13..366c9103a 100644
--- a/apps/renderer/src/hooks/biz/useEntryActions.tsx
+++ b/apps/renderer/src/hooks/biz/useEntryActions.tsx
@@ -1,3 +1,4 @@
+import type { FeedViewType } from "@follow/constants"
import { useCallback } from "react"
import {
@@ -54,7 +55,7 @@ export const useEntryReadabilityToggle = ({ id, url }: { id: string; url: string
}
}, [id, url])
-export const useEntryActions = ({ entryId }: { entryId: string }) => {
+export const useEntryActions = ({ entryId, view }: { entryId: string; view?: FeedViewType }) => {
const entry = useEntry(entryId)
const feed = useFeedById(entry?.feedId, (feed) => {
return {
@@ -111,7 +112,7 @@ export const useEntryActions = ({ entryId }: { entryId: string }) => {
},
{
id: COMMAND_ID.entry.star,
- onClick: runCmdFn(COMMAND_ID.entry.star, [{ entryId }]),
+ onClick: runCmdFn(COMMAND_ID.entry.star, [{ entryId, view }]),
hide: !!entry?.collections,
shortcut: shortcuts.entry.toggleStarred.key,
},
diff --git a/apps/renderer/src/modules/command/commands/entry.tsx b/apps/renderer/src/modules/command/commands/entry.tsx
index 04230cd72..d49e3495d 100644
--- a/apps/renderer/src/modules/command/commands/entry.tsx
+++ b/apps/renderer/src/modules/command/commands/entry.tsx
@@ -20,7 +20,8 @@ import { COMMAND_ID } from "./id"
const useCollect = () => {
const { t } = useTranslation()
return useMutation({
- mutationFn: async (entryId: string) => entryActions.markStar(entryId, true),
+ mutationFn: async ({ entryId, view }: { entryId: string; view?: FeedViewType }) =>
+ entryActions.markStar(entryId, true, view),
onSuccess: () => {
toast.success(t("entry_actions.starred"), {
@@ -109,7 +110,7 @@ export const useRegisterEntryCommands = () => {
id: COMMAND_ID.entry.star,
label: t("entry_actions.star"),
icon: ,
- run: ({ entryId }) => {
+ run: ({ entryId, view }) => {
const entry = useEntryStore.getState().flatMapEntries[entryId]
if (!entry) {
toast.error("Failed to star: entry is not available", { duration: 3000 })
@@ -124,7 +125,7 @@ export const useRegisterEntryCommands = () => {
// width: 252,
// })
// }
- collect.mutate(entry.entries.id)
+ collect.mutate({ entryId, view })
},
}),
defineFollowCommand({
diff --git a/apps/renderer/src/modules/command/commands/types.ts b/apps/renderer/src/modules/command/commands/types.ts
index 2ae84c7ab..244be39bc 100644
--- a/apps/renderer/src/modules/command/commands/types.ts
+++ b/apps/renderer/src/modules/command/commands/types.ts
@@ -1,5 +1,7 @@
// Entry commands
+import type { FeedViewType } from "@follow/constants"
+
import type { Command } from "../types"
import type { COMMAND_ID } from "./id"
@@ -10,7 +12,7 @@ export type TipCommand = Command<{
export type StarCommand = Command<{
id: typeof COMMAND_ID.entry.star
- fn: (data: { entryId: string }) => void
+ fn: (data: { entryId: string; view?: FeedViewType }) => void
}>
export type UnStarCommand = Command<{
id: typeof COMMAND_ID.entry.unstar
diff --git a/apps/renderer/src/modules/entry-content/header.tsx b/apps/renderer/src/modules/entry-content/header.tsx
index cc802d034..1899248fc 100644
--- a/apps/renderer/src/modules/entry-content/header.tsx
+++ b/apps/renderer/src/modules/entry-content/header.tsx
@@ -32,8 +32,8 @@ import { ImageGallery } from "./actions/picture-gallery"
import { useEntryContentScrollToTop, useEntryTitleMeta } from "./atoms"
import { EntryReadHistory } from "./components/EntryReadHistory"
-const EntryHeaderActions = ({ entryId }: { entryId: string }) => {
- const actionConfigs = useEntryActions({ entryId })
+const EntryHeaderActions = ({ entryId, view }: { entryId: string; view?: FeedViewType }) => {
+ const actionConfigs = useEntryActions({ entryId, view })
const entry = useEntry(entryId)
const hasModal = useHasModal()
@@ -131,7 +131,7 @@ function EntryHeaderImpl({
{!compact && }
-
+
diff --git a/apps/renderer/src/modules/entry-content/index.tsx b/apps/renderer/src/modules/entry-content/index.tsx
index 21d2b21c5..6ffc48c39 100644
--- a/apps/renderer/src/modules/entry-content/index.tsx
+++ b/apps/renderer/src/modules/entry-content/index.tsx
@@ -196,7 +196,7 @@ export const EntryContentRender: Component<{
<>
diff --git a/apps/renderer/src/store/entry/store.ts b/apps/renderer/src/store/entry/store.ts
index ebbaf2f5b..ed000cef1 100644
--- a/apps/renderer/src/store/entry/store.ts
+++ b/apps/renderer/src/store/entry/store.ts
@@ -1,3 +1,4 @@
+import type { FeedViewType } from "@follow/constants"
import type {
CombinedEntryModel,
EntryModel,
@@ -471,7 +472,7 @@ class EntryActions {
await tx.run()
}
- async markStar(entryId: string, star: boolean) {
+ async markStar(entryId: string, star: boolean, view?: FeedViewType) {
const tx = createTransaction({})
tx.optimistic(async (_, ctx) => {
@@ -495,6 +496,7 @@ class EntryActions {
await apiClient.collections.$post({
json: {
entryId,
+ view,
},
})
} else {
diff --git a/packages/shared/src/hono.ts b/packages/shared/src/hono.ts
index 19c0cdba6..c365dbea5 100644
--- a/packages/shared/src/hono.ts
+++ b/packages/shared/src/hono.ts
@@ -7270,6 +7270,7 @@ declare const _routes: hono_hono_base.HonoBase