fix: allow collect entry from list
This commit is contained in:
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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: <i className="i-mgc-star-cute-re" />,
|
||||
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({
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 && <ElectronAdditionActions view={view} entry={entry} key={entry.entries.id} />}
|
||||
|
||||
<SpecialActions id={entry.entries.id} />
|
||||
<EntryHeaderActions entryId={entry.entries.id} />
|
||||
<EntryHeaderActions entryId={entry.entries.id} view={view} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -196,7 +196,7 @@ export const EntryContentRender: Component<{
|
||||
<>
|
||||
<EntryHeader
|
||||
entryId={entry.entries.id}
|
||||
view={0}
|
||||
view={view}
|
||||
className={cn("h-[55px] shrink-0 px-3 @container", classNames?.header)}
|
||||
compact={compact}
|
||||
/>
|
||||
|
||||
@@ -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<unknown, { prevIsStar: boolean }>({})
|
||||
|
||||
tx.optimistic(async (_, ctx) => {
|
||||
@@ -495,6 +496,7 @@ class EntryActions {
|
||||
await apiClient.collections.$post({
|
||||
json: {
|
||||
entryId,
|
||||
view,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
|
||||
@@ -7270,6 +7270,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
|
||||
input: {
|
||||
json: {
|
||||
entryId: string;
|
||||
view?: number | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
|
||||
Reference in New Issue
Block a user