Skip to content

Commit

Permalink
feat: check eagle
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed May 16, 2024
1 parent 5067304 commit fbb27e2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 51 deletions.
27 changes: 1 addition & 26 deletions src/renderer/src/components/entry-column/context-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,6 @@ import {
import { useEntryActions } from "@renderer/hooks/useEntryActions"
import { EntriesResponse } from "@renderer/lib/types"

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: "Save Images to Eagle",
icon: "/eagle.svg",
action: "save-to-eagle",
},
{
name: "Share",
className: "i-mingcute-share-2-line",
action: "share",
},
],
]

export function EntryContextMenu({
entry,
view,
Expand All @@ -43,7 +18,7 @@ export function EntryContextMenu({
}) {
if (!entry?.url) return children

const { execAction } = useEntryActions({
const { execAction, items } = useEntryActions({
url: entry.url,
images: entry.images,
})
Expand Down
49 changes: 25 additions & 24 deletions src/renderer/src/components/entry-content/share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
} from "@renderer/components/ui/tooltip"
import { cn } from "@renderer/lib/utils"
import { useEntryActions } from "@renderer/hooks/useEntryActions"
import { items } from "@renderer/components/entry-column/context-menu"
import { ActivedEntry } from "@renderer/lib/types"

export function EntryShare({
Expand All @@ -18,36 +17,38 @@ export function EntryShare({
}) {
if (!entry?.url) return null

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

return (
<div className="px-5 h-14 flex items-center text-lg justify-end text-zinc-500 gap-5">
<TooltipProvider delayDuration={300}>
{items[view].map((item) => (
<Tooltip key={item.name}>
<TooltipTrigger className="flex items-center my-2">
{item.icon ? (
<img
className="w-4 h-4 grayscale cursor-pointer no-drag-region"
src={item.icon}
onClick={() => execAction(item.action)}
/>
) : (
<i
className={cn(
item.className,
"cursor-pointer no-drag-region",
)}
onClick={() => execAction(item.action)}
/>
)}
</TooltipTrigger>
<TooltipContent side="bottom">{item.name}</TooltipContent>
</Tooltip>
))}
{items[view]
.filter((item) => !item.disabled)
.map((item) => (
<Tooltip key={item.name}>
<TooltipTrigger className="flex items-center my-2">
{item.icon ? (
<img
className="w-4 h-4 grayscale cursor-pointer no-drag-region"
src={item.icon}
onClick={() => execAction(item.action)}
/>
) : (
<i
className={cn(
item.className,
"cursor-pointer no-drag-region",
)}
onClick={() => execAction(item.action)}
/>
)}
</TooltipTrigger>
<TooltipContent side="bottom">{item.name}</TooltipContent>
</Tooltip>
))}
</TooltipProvider>
</div>
)
Expand Down
48 changes: 47 additions & 1 deletion src/renderer/src/hooks/useEntryActions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import { useToast } from "@renderer/components/ui/use-toast"
import { useCallback } from "react"
import { ofetch } from "ofetch"
import { useQuery } from "@tanstack/react-query"

export const useCheckEagle = () =>
useQuery({
queryKey: ["check-eagle"],
queryFn: async () => {
try {
await ofetch("http://localhost:41595")
return true
} catch (error: any) {
return error.data?.code === 401
}
},
})

export const useEntryActions = ({
url,
Expand All @@ -8,6 +23,34 @@ export const useEntryActions = ({
url: string
images?: string[]
}) => {
const checkEagle = useCheckEagle()

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: "Save Images to Eagle",
icon: "/eagle.svg",
action: "save-to-eagle",
disabled: checkEagle.isLoading ? true : !checkEagle.data,
},
{
name: "Share",
className: "i-mingcute-share-2-line",
action: "share",
},
],
]

const { toast } = useToast()

const execAction = useCallback(
Expand Down Expand Up @@ -53,5 +96,8 @@ export const useEntryActions = ({
[toast],
)

return { execAction }
return {
execAction,
items,
}
}

0 comments on commit fbb27e2

Please sign in to comment.