Skip to content

Commit 4a00493

Browse files
authored
feat(desktop): hide separator when availableActions is empty (#3045)
1 parent 37a2e68 commit 4a00493

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

apps/desktop/src/renderer/src/modules/command/hooks/use-command.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import { useCallback, useMemo } from "react"
66
import { CommandRegistry } from "../registry/registry"
77
import type { FollowCommandId, FollowCommandMap } from "../types"
88

9+
export const hasCommand = <T extends FollowCommandId>(id: T) => {
10+
const commands = jotaiStore.get(CommandRegistry.atom) as FollowCommandMap
11+
return id in commands
12+
}
13+
914
export const getCommand = <T extends FollowCommandId>(id: T) => {
1015
const commands = jotaiStore.get(CommandRegistry.atom) as FollowCommandMap
1116
return id in commands ? commands[id] : null

apps/desktop/src/renderer/src/modules/entry-content/actions/more-actions.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ import {
1111
} from "~/components/ui/dropdown-menu/dropdown-menu"
1212
import { useSortedEntryActions } from "~/hooks/biz/useEntryActions"
1313
import { COMMAND_ID } from "~/modules/command/commands/id"
14-
import { useCommand } from "~/modules/command/hooks/use-command"
14+
import { hasCommand, useCommand } from "~/modules/command/hooks/use-command"
1515
import type { FollowCommandId } from "~/modules/command/types"
1616

1717
export const MoreActions = ({ entryId, view }: { entryId: string; view?: FeedViewType }) => {
18-
const { moreAction: actionConfigs } = useSortedEntryActions({ entryId, view })
18+
const { moreAction } = useSortedEntryActions({ entryId, view })
19+
20+
const actionConfigs = useMemo(
21+
() => moreAction.filter((action) => hasCommand(action.id)),
22+
[moreAction],
23+
)
24+
1925
const availableActions = useMemo(
2026
() => actionConfigs.filter((item) => item.id !== COMMAND_ID.settings.customizeToolbar),
2127
[actionConfigs],
@@ -26,7 +32,7 @@ export const MoreActions = ({ entryId, view }: { entryId: string; view?: FeedVie
2632
[actionConfigs],
2733
)
2834

29-
if (availableActions.length === 0) {
35+
if (availableActions.length === 0 && extraAction.length === 0) {
3036
return null
3137
}
3238

@@ -44,7 +50,7 @@ export const MoreActions = ({ entryId, view }: { entryId: string; view?: FeedVie
4450
active={config.active}
4551
/>
4652
))}
47-
<DropdownMenuSeparator />
53+
{availableActions.length > 0 && <DropdownMenuSeparator />}
4854
{extraAction.map((config) => (
4955
<CommandDropdownMenuItem
5056
key={config.id}

0 commit comments

Comments
 (0)