mirror of
https://github.com/Athou/commafeed.git
synced 2026-11-20 02:33:33 +00:00
use Mantine context menu instead of react-contexify (#2380)
This commit is contained in:
23
commafeed-client/package-lock.json
generated
23
commafeed-client/package-lock.json
generated
@@ -31,7 +31,6 @@
|
|||||||
"mousetrap": "1.6.5",
|
"mousetrap": "1.6.5",
|
||||||
"react": "19.3.1",
|
"react": "19.3.1",
|
||||||
"react-async-hook": "4.0.0",
|
"react-async-hook": "4.0.0",
|
||||||
"react-contexify": "6.0.0",
|
|
||||||
"react-dom": "19.3.1",
|
"react-dom": "19.3.1",
|
||||||
"react-draggable": "4.7.2",
|
"react-draggable": "4.7.2",
|
||||||
"react-icons": "5.7.0",
|
"react-icons": "5.7.0",
|
||||||
@@ -4835,28 +4834,6 @@
|
|||||||
"react": ">=16.8"
|
"react": ">=16.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/react-contexify": {
|
|
||||||
"version": "6.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/react-contexify/-/react-contexify-6.0.0.tgz",
|
|
||||||
"integrity": "sha512-jMhz6yZI81Jv3UDj7TXqCkhdkCFEEmvwGCPXsQuA2ZUC8EbCuVQ6Cy8FzKMXa0y454XTDClBN2YFvvmoFlrFkg==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"clsx": "^1.2.1"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"react": ">=16",
|
|
||||||
"react-dom": ">=16"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/react-contexify/node_modules/clsx": {
|
|
||||||
"version": "1.2.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/clsx/-/clsx-1.2.1.tgz",
|
|
||||||
"integrity": "sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==",
|
|
||||||
"license": "MIT",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/react-dom": {
|
"node_modules/react-dom": {
|
||||||
"version": "19.3.1",
|
"version": "19.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.3.1.tgz",
|
||||||
|
|||||||
@@ -38,7 +38,6 @@
|
|||||||
"mousetrap": "1.6.5",
|
"mousetrap": "1.6.5",
|
||||||
"react": "19.3.1",
|
"react": "19.3.1",
|
||||||
"react-async-hook": "4.0.0",
|
"react-async-hook": "4.0.0",
|
||||||
"react-contexify": "6.0.0",
|
|
||||||
"react-dom": "19.3.1",
|
"react-dom": "19.3.1",
|
||||||
"react-draggable": "4.7.2",
|
"react-draggable": "4.7.2",
|
||||||
"react-icons": "5.7.0",
|
"react-icons": "5.7.0",
|
||||||
|
|||||||
@@ -91,7 +91,6 @@ export const Constants = {
|
|||||||
},
|
},
|
||||||
dom: {
|
dom: {
|
||||||
entryId: (entry: Entry) => `entry-id-${entry.id}`,
|
entryId: (entry: Entry) => `entry-id-${entry.id}`,
|
||||||
entryContextMenuId: (entry: Entry) => entry.id,
|
|
||||||
},
|
},
|
||||||
theme: {
|
theme: {
|
||||||
defaultPrimaryColor: "orange",
|
defaultPrimaryColor: "orange",
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { Trans } from "@lingui/react/macro"
|
|||||||
import { Box } from "@mantine/core"
|
import { Box } from "@mantine/core"
|
||||||
import { openModal } from "@mantine/modals"
|
import { openModal } from "@mantine/modals"
|
||||||
import { useEffect } from "react"
|
import { useEffect } from "react"
|
||||||
import { useContextMenu } from "react-contexify"
|
|
||||||
import InfiniteScroll from "react-infinite-scroller"
|
import InfiniteScroll from "react-infinite-scroller"
|
||||||
import { throttle } from "throttle-debounce"
|
import { throttle } from "throttle-debounce"
|
||||||
import { Constants } from "@/app/constants"
|
import { Constants } from "@/app/constants"
|
||||||
@@ -35,7 +34,6 @@ export function FeedEntries() {
|
|||||||
const scrollMarks = useAppSelector(state => state.user.settings?.scrollMarks)
|
const scrollMarks = useAppSelector(state => state.user.settings?.scrollMarks)
|
||||||
const scrollingToEntry = useAppSelector(state => state.entries.scrollingToEntry)
|
const scrollingToEntry = useAppSelector(state => state.entries.scrollingToEntry)
|
||||||
const sidebarVisible = useAppSelector(state => state.tree.sidebarVisible)
|
const sidebarVisible = useAppSelector(state => state.tree.sidebarVisible)
|
||||||
const customContextMenu = useAppSelector(state => state.user.settings?.customContextMenu)
|
|
||||||
const viewMode = useAppSelector(state => state.user.localSettings.viewMode)
|
const viewMode = useAppSelector(state => state.user.localSettings.viewMode)
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
const { openLinkInBackgroundTab } = useBrowserExtension()
|
const { openLinkInBackgroundTab } = useBrowserExtension()
|
||||||
@@ -62,17 +60,6 @@ export function FeedEntries() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const contextMenu = useContextMenu()
|
|
||||||
const headerRightClicked = (entry: ExpendableEntry, event: React.MouseEvent) => {
|
|
||||||
if (event.shiftKey || !customContextMenu) return
|
|
||||||
|
|
||||||
event.preventDefault()
|
|
||||||
contextMenu.show({
|
|
||||||
id: Constants.dom.entryContextMenuId(entry),
|
|
||||||
event,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const bodyClicked = (entry: ExpendableEntry) => {
|
const bodyClicked = (entry: ExpendableEntry) => {
|
||||||
if (viewMode !== "expanded") return
|
if (viewMode !== "expanded") return
|
||||||
|
|
||||||
@@ -91,13 +78,6 @@ export function FeedEntries() {
|
|||||||
|
|
||||||
const swipedLeft = async (entry: ExpendableEntry) => await dispatch(markEntry({ entry, read: !entry.read }))
|
const swipedLeft = async (entry: ExpendableEntry) => await dispatch(markEntry({ entry, read: !entry.read }))
|
||||||
|
|
||||||
// close context menu on scroll
|
|
||||||
useEffect(() => {
|
|
||||||
const listener = throttle(100, () => contextMenu.hideAll())
|
|
||||||
window.addEventListener("scroll", listener)
|
|
||||||
return () => window.removeEventListener("scroll", listener)
|
|
||||||
}, [contextMenu])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const listener = throttle(100, () => {
|
const listener = throttle(100, () => {
|
||||||
if (viewMode !== "expanded") return
|
if (viewMode !== "expanded") return
|
||||||
@@ -305,7 +285,6 @@ export function FeedEntries() {
|
|||||||
}
|
}
|
||||||
maxWidth={sidebarVisible ? Constants.layout.entryMaxWidth : undefined}
|
maxWidth={sidebarVisible ? Constants.layout.entryMaxWidth : undefined}
|
||||||
onHeaderClick={event => headerClicked(entry, event)}
|
onHeaderClick={event => headerClicked(entry, event)}
|
||||||
onHeaderRightClick={event => headerRightClicked(entry, event)}
|
|
||||||
onBodyClick={() => bodyClicked(entry)}
|
onBodyClick={() => bodyClicked(entry)}
|
||||||
onSwipedLeft={async () => await swipedLeft(entry)}
|
onSwipedLeft={async () => await swipedLeft(entry)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ interface FeedEntryProps {
|
|||||||
showSelectionIndicator: boolean
|
showSelectionIndicator: boolean
|
||||||
maxWidth?: number
|
maxWidth?: number
|
||||||
onHeaderClick: (e: React.MouseEvent) => void
|
onHeaderClick: (e: React.MouseEvent) => void
|
||||||
onHeaderRightClick: (e: React.MouseEvent) => void
|
|
||||||
onBodyClick: (e: React.MouseEvent) => void
|
onBodyClick: (e: React.MouseEvent) => void
|
||||||
onSwipedLeft: () => void
|
onSwipedLeft: () => void
|
||||||
}
|
}
|
||||||
@@ -171,6 +170,7 @@ export function FeedEntry(props: Readonly<FeedEntryProps>) {
|
|||||||
"show-selection-indicator": props.showSelectionIndicator,
|
"show-selection-indicator": props.showSelectionIndicator,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
|
<FeedEntryContextMenu entry={props.entry}>
|
||||||
<a
|
<a
|
||||||
className={classes.headerLink}
|
className={classes.headerLink}
|
||||||
href={props.entry.url}
|
href={props.entry.url}
|
||||||
@@ -178,7 +178,10 @@ export function FeedEntry(props: Readonly<FeedEntryProps>) {
|
|||||||
rel="noreferrer"
|
rel="noreferrer"
|
||||||
onClick={props.onHeaderClick}
|
onClick={props.onHeaderClick}
|
||||||
onAuxClick={props.onHeaderClick}
|
onAuxClick={props.onHeaderClick}
|
||||||
onContextMenu={props.onHeaderRightClick}
|
onContextMenuCapture={e => {
|
||||||
|
// keep the browser context menu when shift is pressed
|
||||||
|
if (e.shiftKey) e.stopPropagation()
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Box px={paddingX} py={paddingY} {...swipeHandlers}>
|
<Box px={paddingX} py={paddingY} {...swipeHandlers}>
|
||||||
{compactHeader && (
|
{compactHeader && (
|
||||||
@@ -198,6 +201,7 @@ export function FeedEntry(props: Readonly<FeedEntryProps>) {
|
|||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</a>
|
</a>
|
||||||
|
</FeedEntryContextMenu>
|
||||||
{props.expanded && (
|
{props.expanded && (
|
||||||
<Box px={paddingX} pb={paddingY} onClick={props.onBodyClick}>
|
<Box px={paddingX} pb={paddingY} onClick={props.onBodyClick}>
|
||||||
<Box className={`${classes.body} cf-content`}>
|
<Box className={`${classes.body} cf-content`}>
|
||||||
@@ -207,8 +211,6 @@ export function FeedEntry(props: Readonly<FeedEntryProps>) {
|
|||||||
<FeedEntryFooter entry={props.entry} />
|
<FeedEntryFooter entry={props.entry} />
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<FeedEntryContextMenu entry={props.entry} />
|
|
||||||
</Paper>
|
</Paper>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,111 +1,101 @@
|
|||||||
import { Trans } from "@lingui/react/macro"
|
import { Trans } from "@lingui/react/macro"
|
||||||
import { Group } from "@mantine/core"
|
import { Menu } from "@mantine/core"
|
||||||
import { Item, Menu, Separator } from "react-contexify"
|
import { type ReactElement, useEffect, useState } from "react"
|
||||||
import { TbArrowBarToDown, TbExternalLink, TbMail, TbMailOpened, TbRss, TbStar, TbStarOff } from "react-icons/tb"
|
import { TbArrowBarToDown, TbExternalLink, TbMail, TbMailOpened, TbRss, TbStar, TbStarOff } from "react-icons/tb"
|
||||||
import { Constants } from "@/app/constants"
|
import { throttle } from "throttle-debounce"
|
||||||
import { markEntriesUpToEntry, markEntry, starEntry } from "@/app/entries/thunks"
|
import { markEntriesUpToEntry, markEntry, starEntry } from "@/app/entries/thunks"
|
||||||
import { redirectToFeed } from "@/app/redirect/thunks"
|
import { redirectToFeed } from "@/app/redirect/thunks"
|
||||||
import { useAppDispatch, useAppSelector } from "@/app/store"
|
import { useAppDispatch, useAppSelector } from "@/app/store"
|
||||||
import type { Entry } from "@/app/types"
|
import type { Entry } from "@/app/types"
|
||||||
import { truncate } from "@/app/utils"
|
import { truncate } from "@/app/utils"
|
||||||
import { useBrowserExtension } from "@/hooks/useBrowserExtension"
|
import { useBrowserExtension } from "@/hooks/useBrowserExtension"
|
||||||
import { useColorScheme } from "@/hooks/useColorScheme"
|
|
||||||
import { tss } from "@/tss"
|
|
||||||
|
|
||||||
interface FeedEntryContextMenuProps {
|
interface FeedEntryContextMenuProps {
|
||||||
entry: Entry
|
entry: Entry
|
||||||
|
// element that opens the menu when right-clicked
|
||||||
|
children: ReactElement
|
||||||
}
|
}
|
||||||
|
|
||||||
const iconSize = 16
|
const iconSize = 16
|
||||||
const useStyles = tss.create(({ theme, colorScheme }) => ({
|
|
||||||
menu: {
|
|
||||||
// apply mantine theme from MenuItem.styles.ts
|
|
||||||
fontSize: theme.fontSizes.sm,
|
|
||||||
"--contexify-item-color": `${colorScheme === "dark" ? theme.colors.dark[0] : theme.black} !important`,
|
|
||||||
"--contexify-activeItem-color": `${colorScheme === "dark" ? theme.colors.dark[0] : theme.black} !important`,
|
|
||||||
"--contexify-activeItem-bgColor": `${colorScheme === "dark" ? theme.colors.dark[4] : theme.colors.gray[1]} !important`,
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
export function FeedEntryContextMenu(props: Readonly<FeedEntryContextMenuProps>) {
|
export function FeedEntryContextMenu(props: Readonly<FeedEntryContextMenuProps>) {
|
||||||
const colorScheme = useColorScheme()
|
const [opened, setOpened] = useState(false)
|
||||||
const { classes } = useStyles()
|
const customContextMenu = useAppSelector(state => state.user.settings?.customContextMenu)
|
||||||
const sourceType = useAppSelector(state => state.entries.source.type)
|
const sourceType = useAppSelector(state => state.entries.source.type)
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
const { openLinkInBackgroundTab } = useBrowserExtension()
|
const { openLinkInBackgroundTab } = useBrowserExtension()
|
||||||
|
|
||||||
|
// close context menu on scroll
|
||||||
|
useEffect(() => {
|
||||||
|
if (!opened) return
|
||||||
|
|
||||||
|
const listener = throttle(100, () => setOpened(false))
|
||||||
|
window.addEventListener("scroll", listener)
|
||||||
|
return () => window.removeEventListener("scroll", listener)
|
||||||
|
}, [opened])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Menu
|
<Menu position="bottom-start" opened={opened} onChange={setOpened}>
|
||||||
id={Constants.dom.entryContextMenuId(props.entry)}
|
<Menu.ContextMenu disabled={!customContextMenu}>{props.children}</Menu.ContextMenu>
|
||||||
theme={colorScheme}
|
<Menu.Dropdown>
|
||||||
animation={false}
|
<Menu.Item
|
||||||
className={classes.menu}
|
leftSection={<TbExternalLink size={iconSize} />}
|
||||||
>
|
|
||||||
<Item
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
window.open(props.entry.url, "_blank", "noreferrer")
|
window.open(props.entry.url, "_blank", "noreferrer")
|
||||||
dispatch(markEntry({ entry: props.entry, read: true }))
|
dispatch(markEntry({ entry: props.entry, read: true }))
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Group>
|
|
||||||
<TbExternalLink size={iconSize} />
|
|
||||||
<Trans>Open link in new tab</Trans>
|
<Trans>Open link in new tab</Trans>
|
||||||
</Group>
|
</Menu.Item>
|
||||||
</Item>
|
<Menu.Item
|
||||||
<Item
|
leftSection={<TbExternalLink size={iconSize} />}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
openLinkInBackgroundTab(props.entry.url)
|
openLinkInBackgroundTab(props.entry.url)
|
||||||
dispatch(markEntry({ entry: props.entry, read: true }))
|
dispatch(markEntry({ entry: props.entry, read: true }))
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Group>
|
|
||||||
<TbExternalLink size={iconSize} />
|
|
||||||
<Trans>Open link in new background tab</Trans>
|
<Trans>Open link in new background tab</Trans>
|
||||||
</Group>
|
</Menu.Item>
|
||||||
</Item>
|
|
||||||
|
|
||||||
<Separator />
|
<Menu.Divider />
|
||||||
|
|
||||||
{props.entry.markable && (
|
{props.entry.markable && (
|
||||||
<Item
|
<Menu.Item
|
||||||
|
leftSection={props.entry.starred ? <TbStarOff size={iconSize} /> : <TbStar size={iconSize} />}
|
||||||
onClick={async () =>
|
onClick={async () =>
|
||||||
await dispatch(starEntry({ entry: props.entry, starred: !props.entry.starred }))
|
await dispatch(starEntry({ entry: props.entry, starred: !props.entry.starred }))
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Group>
|
|
||||||
{props.entry.starred ? <TbStarOff size={iconSize} /> : <TbStar size={iconSize} />}
|
|
||||||
{props.entry.starred ? <Trans>Unstar</Trans> : <Trans>Star</Trans>}
|
{props.entry.starred ? <Trans>Unstar</Trans> : <Trans>Star</Trans>}
|
||||||
</Group>
|
</Menu.Item>
|
||||||
</Item>
|
|
||||||
)}
|
)}
|
||||||
{props.entry.markable && (
|
{props.entry.markable && (
|
||||||
<Item onClick={async () => await dispatch(markEntry({ entry: props.entry, read: !props.entry.read }))}>
|
<Menu.Item
|
||||||
<Group>
|
leftSection={props.entry.read ? <TbMail size={iconSize} /> : <TbMailOpened size={iconSize} />}
|
||||||
{props.entry.read ? <TbMail size={iconSize} /> : <TbMailOpened size={iconSize} />}
|
onClick={async () => await dispatch(markEntry({ entry: props.entry, read: !props.entry.read }))}
|
||||||
|
>
|
||||||
{props.entry.read ? <Trans>Keep unread</Trans> : <Trans>Mark as read</Trans>}
|
{props.entry.read ? <Trans>Keep unread</Trans> : <Trans>Mark as read</Trans>}
|
||||||
</Group>
|
</Menu.Item>
|
||||||
</Item>
|
|
||||||
)}
|
)}
|
||||||
<Item onClick={async () => await dispatch(markEntriesUpToEntry(props.entry))}>
|
<Menu.Item
|
||||||
<Group>
|
leftSection={<TbArrowBarToDown size={iconSize} />}
|
||||||
<TbArrowBarToDown size={iconSize} />
|
onClick={async () => await dispatch(markEntriesUpToEntry(props.entry))}
|
||||||
|
>
|
||||||
<Trans>Mark as read up to here</Trans>
|
<Trans>Mark as read up to here</Trans>
|
||||||
</Group>
|
</Menu.Item>
|
||||||
</Item>
|
|
||||||
|
|
||||||
{sourceType === "category" && <Separator />}
|
{sourceType === "category" && <Menu.Divider />}
|
||||||
{sourceType === "category" && (
|
{sourceType === "category" && (
|
||||||
<Item
|
<Menu.Item
|
||||||
|
leftSection={<TbRss size={iconSize} />}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
dispatch(redirectToFeed(props.entry.feedId))
|
dispatch(redirectToFeed(props.entry.feedId))
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Group>
|
|
||||||
<TbRss size={iconSize} />
|
|
||||||
<Trans>Go to {truncate(props.entry.feedName, 30)}</Trans>
|
<Trans>Go to {truncate(props.entry.feedName, 30)}</Trans>
|
||||||
</Group>
|
</Menu.Item>
|
||||||
</Item>
|
|
||||||
)}
|
)}
|
||||||
|
</Menu.Dropdown>
|
||||||
</Menu>
|
</Menu>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import "@fontsource/open-sans"
|
|||||||
import "@mantine/core/styles.css"
|
import "@mantine/core/styles.css"
|
||||||
import "@mantine/notifications/styles.css"
|
import "@mantine/notifications/styles.css"
|
||||||
import "@mantine/spotlight/styles.css"
|
import "@mantine/spotlight/styles.css"
|
||||||
import "react-contexify/ReactContexify.css"
|
|
||||||
import dayjs from "dayjs"
|
import dayjs from "dayjs"
|
||||||
import duration from "dayjs/plugin/duration"
|
import duration from "dayjs/plugin/duration"
|
||||||
import relativeTime from "dayjs/plugin/relativeTime"
|
import relativeTime from "dayjs/plugin/relativeTime"
|
||||||
|
|||||||
Reference in New Issue
Block a user