feat: add entry share shortcut

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei 2024-07-27 21:40:10 +08:00
parent da34ecaff1
commit a07827d59a
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
3 changed files with 130 additions and 114 deletions

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="#fff" fill-opacity=".01" d="M24 0v24H0V0z"/><path stroke="#10161F" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 13c1.63-4.89 6.582-7.787 8.358-8.692.21-.107.181-.431-.049-.487-1.794-.434-3.483-.574-5.309-.07m-5-.233c-2.172.055-3.45.275-4.328 1.153C3.5 5.842 3.5 7.728 3.5 11.499v1c0 3.771 0 5.657 1.172 6.829 1.171 1.171 3.057 1.171 6.828 1.171h1c3.771 0 5.657 0 6.828-1.171C20.5 18.156 20.5 16.27 20.5 12.499v-1c0-.537 0-1.036-.003-1.5"/></svg>

After

Width:  |  Height:  |  Size: 558 B

View File

@ -77,5 +77,9 @@ export const shortcuts = {
name: "Tip Power",
key: "Shift+Meta+T",
},
share: {
name: "Share",
key: "Meta+Alt+S",
},
},
} as const

View File

@ -2,6 +2,7 @@ import { COPY_MAP } from "@renderer/constants"
import { shortcuts } from "@renderer/constants/shortcuts"
import { tipcClient } from "@renderer/lib/client"
import { nextFrame } from "@renderer/lib/dom"
import { getOS } from "@renderer/lib/utils"
import type { CombinedEntryModel } from "@renderer/models"
import { useTipModal } from "@renderer/modules/wallet/hooks"
import type { FlatEntryModel } from "@renderer/store/entry"
@ -93,131 +94,141 @@ export const useEntryActions = ({
const items = useMemo(() => {
if (!populatedEntry || view === undefined) return []
const items = [
[
{
key: "tip",
shortcut: shortcuts.entry.tip.key,
name: `Tip`,
className: "i-mgc-power-outline",
onClick: () => {
nextFrame(openTipModal)
},
const items: {
key: string
className?: string
shortcut?: string
name: string
icon?: string
disabled?: boolean
onClick: () => void
}[] = [
{
key: "tip",
shortcut: shortcuts.entry.tip.key,
name: `Tip`,
className: "i-mgc-power-outline",
onClick: () => {
nextFrame(openTipModal)
},
{
key: "star",
shortcut: shortcuts.entry.toggleStarred.key,
name: `Star`,
className: "i-mgc-star-cute-re",
disabled: !!populatedEntry.collections,
onClick: () => {
collect.mutate()
},
},
{
key: "star",
shortcut: shortcuts.entry.toggleStarred.key,
name: `Star`,
className: "i-mgc-star-cute-re",
disabled: !!populatedEntry.collections,
onClick: () => {
collect.mutate()
},
{
key: "unstar",
name: `Unstar`,
shortcut: shortcuts.entry.toggleStarred.key,
className: "i-mgc-star-cute-fi text-orange-500",
disabled: !populatedEntry.collections,
onClick: () => {
uncollect.mutate()
},
},
{
key: "unstar",
name: `Unstar`,
shortcut: shortcuts.entry.toggleStarred.key,
className: "i-mgc-star-cute-fi text-orange-500",
disabled: !populatedEntry.collections,
onClick: () => {
uncollect.mutate()
},
{
name: "Copy Link",
className: "i-mgc-link-cute-re",
disabled: !populatedEntry.entries.url,
shortcut: shortcuts.entry.copyLink.key,
onClick: () => {
if (!populatedEntry.entries.url) return
navigator.clipboard.writeText(populatedEntry.entries.url)
toast("Link copied to clipboard.", {
duration: 1000,
})
},
},
{
key: "copyLink",
name: "Copy Link",
className: "i-mgc-link-cute-re",
disabled: !populatedEntry.entries.url,
shortcut: shortcuts.entry.copyLink.key,
onClick: () => {
if (!populatedEntry.entries.url) return
navigator.clipboard.writeText(populatedEntry.entries.url)
toast("Link copied to clipboard.", {
duration: 1000,
})
},
{
key: "openInBrowser",
name: COPY_MAP.OpenInBrowser(),
shortcut: shortcuts.entry.openInBrowser.key,
className: "i-mgc-world-2-cute-re",
disabled: !populatedEntry.entries.url,
onClick: () => {
if (!populatedEntry.entries.url) return
window.open(populatedEntry.entries.url, "_blank")
},
},
{
key: "openInBrowser",
name: COPY_MAP.OpenInBrowser(),
shortcut: shortcuts.entry.openInBrowser.key,
className: "i-mgc-world-2-cute-re",
disabled: !populatedEntry.entries.url,
onClick: () => {
if (!populatedEntry.entries.url) return
window.open(populatedEntry.entries.url, "_blank")
},
{
name: "Save Media to Eagle",
icon: "/eagle.svg",
disabled:
(checkEagle.isLoading ? true : !checkEagle.data) ||
!populatedEntry.entries.media?.length,
onClick: async () => {
if (
!populatedEntry.entries.url ||
!populatedEntry.entries.media?.length
) {
return
}
const response = await tipcClient?.saveToEagle({
url: populatedEntry.entries.url,
mediaUrls: populatedEntry.entries.media.map((m) => m.url),
})
if (response?.status === "success") {
toast("Saved to Eagle.", {
duration: 3000,
})
} else {
toast("Failed to save to Eagle.", {
duration: 3000,
})
}
},
},
{
name: "Share",
className: "i-mgc-share-forward-cute-re",
disabled:
!window.electron && !navigator.share,
onClick: () => {
if (!populatedEntry.entries.url) return
if (window.electron) {
return tipcClient?.showShareMenu(populatedEntry.entries.url)
} else {
navigator.share({
url: populatedEntry.entries.url,
})
}
},
{
name: "Save Media to Eagle",
icon: "/eagle.svg",
key: "saveToEagle",
disabled:
(checkEagle.isLoading ? true : !checkEagle.data) ||
!populatedEntry.entries.media?.length,
onClick: async () => {
if (
!populatedEntry.entries.url ||
!populatedEntry.entries.media?.length
) {
return
},
}
const response = await tipcClient?.saveToEagle({
url: populatedEntry.entries.url,
mediaUrls: populatedEntry.entries.media.map((m) => m.url),
})
if (response?.status === "success") {
toast("Saved to Eagle.", {
duration: 3000,
})
} else {
toast("Failed to save to Eagle.", {
duration: 3000,
})
}
},
{
key: "read",
name: `Mark as Read`,
shortcut: shortcuts.entry.toggleRead.key,
className: "i-mgc-round-cute-fi",
disabled: !!populatedEntry.read || populatedEntry.collections,
onClick: () => {
read.mutate(populatedEntry)
},
},
{
name: "Share",
key: "share",
className: getOS() === "macOS" ? `i-mgc-share-3-cute-re` : "i-mgc-share-forward-cute-re",
shortcut: shortcuts.entry.share.key,
disabled: !window.electron && !navigator.share,
onClick: () => {
if (!populatedEntry.entries.url) return
if (window.electron) {
return tipcClient?.showShareMenu(populatedEntry.entries.url)
} else {
navigator.share({
url: populatedEntry.entries.url,
})
}
return
},
{
key: "unread",
name: `Mark as Unread`,
shortcut: shortcuts.entry.toggleRead.key,
className: "i-mgc-round-cute-re",
disabled: !populatedEntry.read || populatedEntry.collections,
onClick: () => {
unread.mutate(populatedEntry)
},
},
{
key: "read",
name: `Mark as Read`,
shortcut: shortcuts.entry.toggleRead.key,
className: "i-mgc-round-cute-fi",
disabled: !!(!!populatedEntry.read || populatedEntry.collections),
onClick: () => {
read.mutate(populatedEntry)
},
],
},
{
key: "unread",
name: `Mark as Unread`,
shortcut: shortcuts.entry.toggleRead.key,
className: "i-mgc-round-cute-re",
disabled: !!(!populatedEntry.read || populatedEntry.collections),
onClick: () => {
unread.mutate(populatedEntry)
},
},
]
return items[view] || items[0]
return items
}, [
checkEagle.data,
checkEagle.isLoading,