Skip to content

Commit

Permalink
feat: native entry context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed May 18, 2024
1 parent 879efca commit 95e971a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 58 deletions.
44 changes: 0 additions & 44 deletions src/renderer/src/components/entry-column/context-menu.tsx

This file was deleted.

23 changes: 9 additions & 14 deletions src/renderer/src/components/entry-column/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { SocialMediaItem } from "./social-media-item"
import { PictureItem } from "./picture-item"
import { VideoItem } from "./video-item"
import { NotificationItem } from "./notification-item"
import { EntryContextMenu } from "./context-menu"
import { showNativeMenu } from "@renderer/lib/native-menu"
import { EntryItemWrapper } from "./item-wrapper"

const gridMode = [2, 3]

Expand Down Expand Up @@ -69,21 +70,15 @@ export function EntryColumn({
)}
>
{page.data?.map((entry) => (
<div
<EntryItemWrapper
key={entry.id}
className={cn(
"rounded-md transition-colors",
activedEntry?.id === entry.id && "bg-[#DEDDDC]",
)}
onClick={(e) => {
e.stopPropagation()
setActivedEntry(entry)
}}
entry={entry}
activedEntry={activedEntry}
setActivedEntry={setActivedEntry}
view={activedList?.view}
>
<EntryContextMenu entry={entry} view={activedList?.view}>
<Item entry={entry} />
</EntryContextMenu>
</div>
<Item entry={entry} />
</EntryItemWrapper>
))}
</m.div>
))}
Expand Down
55 changes: 55 additions & 0 deletions src/renderer/src/components/entry-column/item-wrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { ActivedEntry, EntriesResponse } from "@renderer/lib/types"
import { cn } from "@renderer/lib/utils"
import { showNativeMenu } from "@renderer/lib/native-menu"
import { useEntryActions } from "@renderer/hooks/useEntryActions"

export function EntryItemWrapper({
entry,
activedEntry,
setActivedEntry,
children,
view,
}: {
entry: EntriesResponse[number]
activedEntry: ActivedEntry
setActivedEntry: (value: ActivedEntry) => void
children: React.ReactNode
view?: number
}) {
if (!entry?.url || view === undefined) return children

const { execAction, items } = useEntryActions({
url: entry.url,
images: entry.images,
view,
})

return (
<div
key={entry.id}
className={cn(
"rounded-md transition-colors",
activedEntry?.id === entry.id && "bg-[#DEDDDC]",
)}
onClick={(e) => {
e.stopPropagation()
setActivedEntry(entry)
}}
onContextMenu={(e) => {
e.preventDefault()
showNativeMenu(
items
.filter((item) => !item.disabled)
.map((item) => ({
type: "text",
label: item.name,
click: () => execAction(item.action),
})),
e,
)
}}
>
{children}
</div>
)
}

0 comments on commit 95e971a

Please sign in to comment.