feat: useEntryActions
This commit is contained in:
parent
5b0e946c50
commit
0bcf0df849
|
|
@ -0,0 +1,40 @@
|
|||
import { useState } from "react"
|
||||
import {
|
||||
ContextMenu,
|
||||
ContextMenuContent,
|
||||
ContextMenuItem,
|
||||
ContextMenuTrigger,
|
||||
} from "@renderer/components/ui/context-menu"
|
||||
import { useEntryActions } from "@renderer/hooks/useEntryActions"
|
||||
|
||||
export const items = [
|
||||
[
|
||||
{
|
||||
name: "Copy Link",
|
||||
className: "i-mingcute-link-line",
|
||||
action: "copyLink",
|
||||
},
|
||||
{
|
||||
name: "Open in Browser",
|
||||
className: "i-mingcute-world-2-line",
|
||||
action: "openInBrowser",
|
||||
},
|
||||
{
|
||||
name: "Share",
|
||||
className: "i-mingcute-share-2-line",
|
||||
action: "share",
|
||||
},
|
||||
],
|
||||
]
|
||||
|
||||
export function EntryContextMenu({
|
||||
view,
|
||||
url,
|
||||
}: {
|
||||
view?: number
|
||||
url: string
|
||||
}) {
|
||||
const { execAction } = useEntryActions(url)
|
||||
|
||||
return <>{url}</>
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ export function EntryContent({ entry }: { entry: ActivedEntry }) {
|
|||
|
||||
return (
|
||||
<>
|
||||
<EntryShare url={entry?.url} />
|
||||
<EntryShare url={entry?.url} view={0} />
|
||||
<m.div
|
||||
className="px-5 py-5 overflow-y-auto h-full"
|
||||
initial={{ opacity: 0.01, y: 100 }}
|
||||
|
|
|
|||
|
|
@ -4,58 +4,19 @@ import {
|
|||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@renderer/components/ui/tooltip"
|
||||
import { useCallback } from "react"
|
||||
import { useToast } from "@renderer/components/ui/use-toast"
|
||||
import { cn } from "@renderer/lib/utils"
|
||||
import { useEntryActions } from "@renderer/hooks/useEntryActions"
|
||||
import { items } from "@renderer/components/entry-column/context-menu"
|
||||
|
||||
const items = [
|
||||
{
|
||||
name: "Copy Link",
|
||||
className: "i-mingcute-link-line",
|
||||
action: "copyLink",
|
||||
},
|
||||
{
|
||||
name: "Open in Browser",
|
||||
className: "i-mingcute-world-2-line",
|
||||
action: "openInBrowser",
|
||||
},
|
||||
{
|
||||
name: "Share",
|
||||
className: "i-mingcute-share-2-line",
|
||||
action: "share",
|
||||
},
|
||||
]
|
||||
|
||||
export function EntryShare({ url }: { url?: string }) {
|
||||
export function EntryShare({ view, url }: { view: number; url?: string }) {
|
||||
if (!url) return null
|
||||
|
||||
const { toast } = useToast()
|
||||
|
||||
const execAction = useCallback(
|
||||
(action: string) => {
|
||||
switch (action) {
|
||||
case "copyLink":
|
||||
navigator.clipboard.writeText(url)
|
||||
toast({
|
||||
duration: 1000,
|
||||
description: "Link copied to clipboard.",
|
||||
})
|
||||
break
|
||||
case "openInBrowser":
|
||||
window.open(url, "_blank")
|
||||
break
|
||||
case "share":
|
||||
window.electron.ipcRenderer.send("share-url", url)
|
||||
break
|
||||
}
|
||||
},
|
||||
[url],
|
||||
)
|
||||
const { execAction } = useEntryActions(url)
|
||||
|
||||
return (
|
||||
<div className="px-5 h-14 flex items-center text-lg justify-end text-zinc-500 gap-5">
|
||||
<TooltipProvider delayDuration={300}>
|
||||
{items.map((item) => (
|
||||
{items[view].map((item) => (
|
||||
<Tooltip>
|
||||
<TooltipTrigger className="flex items-center my-2">
|
||||
<i
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import {
|
|||
ContextMenuContent,
|
||||
ContextMenuItem,
|
||||
ContextMenuTrigger,
|
||||
ContextMenuSeparator,
|
||||
} from "@renderer/components/ui/context-menu"
|
||||
import { Dialog, DialogTrigger } from "@renderer/components/ui/dialog"
|
||||
import { CategoryRenameDialog } from "./category-rename-dialog"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
import { useToast } from "@renderer/components/ui/use-toast"
|
||||
import { useCallback } from "react"
|
||||
|
||||
export const useEntryActions = (url: string) => {
|
||||
const { toast } = useToast()
|
||||
|
||||
const execAction = useCallback(
|
||||
(action: string) => {
|
||||
switch (action) {
|
||||
case "copyLink":
|
||||
navigator.clipboard.writeText(url)
|
||||
toast({
|
||||
duration: 1000,
|
||||
description: "Link copied to clipboard.",
|
||||
})
|
||||
break
|
||||
case "openInBrowser":
|
||||
window.open(url, "_blank")
|
||||
break
|
||||
case "share":
|
||||
window.electron.ipcRenderer.send("share-url", url)
|
||||
break
|
||||
}
|
||||
},
|
||||
[toast],
|
||||
)
|
||||
|
||||
return { execAction }
|
||||
}
|
||||
Loading…
Reference in New Issue