Skip to content

Commit

Permalink
fix: allow collect entry from list
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoban committed Nov 19, 2024
1 parent fcf775c commit 706f484
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 11 deletions.
5 changes: 3 additions & 2 deletions apps/renderer/src/hooks/biz/useEntryActions.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { FeedViewType } from "@follow/constants"
import { useCallback } from "react"

import {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
},
Expand Down
7 changes: 4 additions & 3 deletions apps/renderer/src/modules/command/commands/entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"), {
Expand Down Expand Up @@ -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 })
Expand All @@ -124,7 +125,7 @@ export const useRegisterEntryCommands = () => {
// width: 252,
// })
// }
collect.mutate(entry.entries.id)
collect.mutate({ entryId, view })
},
}),
defineFollowCommand({
Expand Down
4 changes: 3 additions & 1 deletion apps/renderer/src/modules/command/commands/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Entry commands

import type { FeedViewType } from "@follow/constants"

import type { Command } from "../types"
import type { COMMAND_ID } from "./id"

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions apps/renderer/src/modules/entry-content/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion apps/renderer/src/modules/entry-content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
/>
Expand Down
4 changes: 3 additions & 1 deletion apps/renderer/src/store/entry/store.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { FeedViewType } from "@follow/constants"
import type {
CombinedEntryModel,
EntryModel,
Expand Down Expand Up @@ -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) => {
Expand All @@ -495,6 +496,7 @@ class EntryActions {
await apiClient.collections.$post({
json: {
entryId,
view,
},
})
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7270,6 +7270,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
input: {
json: {
entryId: string;
view?: number | undefined;
};
};
output: {
Expand Down

0 comments on commit 706f484

Please sign in to comment.