From ad193793186ad32026786ffb387d0a56c34a3af3 Mon Sep 17 00:00:00 2001 From: Athou Date: Tue, 10 Nov 2026 12:28:26 +0100 Subject: [PATCH] use Mantine context menu instead of react-contexify (#2380) --- commafeed-client/package-lock.json | 23 --- commafeed-client/package.json | 1 - commafeed-client/src/app/constants.ts | 1 - .../src/components/content/FeedEntries.tsx | 21 --- .../src/components/content/FeedEntry.tsx | 62 +++---- .../content/FeedEntryContextMenu.tsx | 156 ++++++++---------- commafeed-client/src/main.tsx | 1 - 7 files changed, 105 insertions(+), 160 deletions(-) diff --git a/commafeed-client/package-lock.json b/commafeed-client/package-lock.json index 73d7e55a..1091a5eb 100644 --- a/commafeed-client/package-lock.json +++ b/commafeed-client/package-lock.json @@ -31,7 +31,6 @@ "mousetrap": "1.6.5", "react": "19.3.1", "react-async-hook": "4.0.0", - "react-contexify": "6.0.0", "react-dom": "19.3.1", "react-draggable": "4.7.2", "react-icons": "5.7.0", @@ -4835,28 +4834,6 @@ "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": { "version": "19.3.1", "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.3.1.tgz", diff --git a/commafeed-client/package.json b/commafeed-client/package.json index 06bf4c3e..204811fc 100644 --- a/commafeed-client/package.json +++ b/commafeed-client/package.json @@ -38,7 +38,6 @@ "mousetrap": "1.6.5", "react": "19.3.1", "react-async-hook": "4.0.0", - "react-contexify": "6.0.0", "react-dom": "19.3.1", "react-draggable": "4.7.2", "react-icons": "5.7.0", diff --git a/commafeed-client/src/app/constants.ts b/commafeed-client/src/app/constants.ts index ee178b81..31e44b9b 100644 --- a/commafeed-client/src/app/constants.ts +++ b/commafeed-client/src/app/constants.ts @@ -91,7 +91,6 @@ export const Constants = { }, dom: { entryId: (entry: Entry) => `entry-id-${entry.id}`, - entryContextMenuId: (entry: Entry) => entry.id, }, theme: { defaultPrimaryColor: "orange", diff --git a/commafeed-client/src/components/content/FeedEntries.tsx b/commafeed-client/src/components/content/FeedEntries.tsx index ff557e46..901c31f0 100644 --- a/commafeed-client/src/components/content/FeedEntries.tsx +++ b/commafeed-client/src/components/content/FeedEntries.tsx @@ -2,7 +2,6 @@ import { Trans } from "@lingui/react/macro" import { Box } from "@mantine/core" import { openModal } from "@mantine/modals" import { useEffect } from "react" -import { useContextMenu } from "react-contexify" import InfiniteScroll from "react-infinite-scroller" import { throttle } from "throttle-debounce" import { Constants } from "@/app/constants" @@ -35,7 +34,6 @@ export function FeedEntries() { const scrollMarks = useAppSelector(state => state.user.settings?.scrollMarks) const scrollingToEntry = useAppSelector(state => state.entries.scrollingToEntry) const sidebarVisible = useAppSelector(state => state.tree.sidebarVisible) - const customContextMenu = useAppSelector(state => state.user.settings?.customContextMenu) const viewMode = useAppSelector(state => state.user.localSettings.viewMode) const dispatch = useAppDispatch() 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) => { if (viewMode !== "expanded") return @@ -91,13 +78,6 @@ export function FeedEntries() { 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(() => { const listener = throttle(100, () => { if (viewMode !== "expanded") return @@ -305,7 +285,6 @@ export function FeedEntries() { } maxWidth={sidebarVisible ? Constants.layout.entryMaxWidth : undefined} onHeaderClick={event => headerClicked(entry, event)} - onHeaderRightClick={event => headerRightClicked(entry, event)} onBodyClick={() => bodyClicked(entry)} onSwipedLeft={async () => await swipedLeft(entry)} /> diff --git a/commafeed-client/src/components/content/FeedEntry.tsx b/commafeed-client/src/components/content/FeedEntry.tsx index 5f935609..accc6add 100644 --- a/commafeed-client/src/components/content/FeedEntry.tsx +++ b/commafeed-client/src/components/content/FeedEntry.tsx @@ -19,7 +19,6 @@ interface FeedEntryProps { showSelectionIndicator: boolean maxWidth?: number onHeaderClick: (e: React.MouseEvent) => void - onHeaderRightClick: (e: React.MouseEvent) => void onBodyClick: (e: React.MouseEvent) => void onSwipedLeft: () => void } @@ -171,33 +170,38 @@ export function FeedEntry(props: Readonly) { "show-selection-indicator": props.showSelectionIndicator, })} > - - - {compactHeader && ( - - )} - {!compactHeader && ( - - )} - - + + { + // keep the browser context menu when shift is pressed + if (e.shiftKey) e.stopPropagation() + }} + > + + {compactHeader && ( + + )} + {!compactHeader && ( + + )} + + + {props.expanded && ( @@ -207,8 +211,6 @@ export function FeedEntry(props: Readonly) { )} - - ) } diff --git a/commafeed-client/src/components/content/FeedEntryContextMenu.tsx b/commafeed-client/src/components/content/FeedEntryContextMenu.tsx index 910f1807..5e445ae0 100644 --- a/commafeed-client/src/components/content/FeedEntryContextMenu.tsx +++ b/commafeed-client/src/components/content/FeedEntryContextMenu.tsx @@ -1,111 +1,101 @@ import { Trans } from "@lingui/react/macro" -import { Group } from "@mantine/core" -import { Item, Menu, Separator } from "react-contexify" +import { Menu } from "@mantine/core" +import { type ReactElement, useEffect, useState } from "react" 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 { redirectToFeed } from "@/app/redirect/thunks" import { useAppDispatch, useAppSelector } from "@/app/store" import type { Entry } from "@/app/types" import { truncate } from "@/app/utils" import { useBrowserExtension } from "@/hooks/useBrowserExtension" -import { useColorScheme } from "@/hooks/useColorScheme" -import { tss } from "@/tss" interface FeedEntryContextMenuProps { entry: Entry + // element that opens the menu when right-clicked + children: ReactElement } 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) { - const colorScheme = useColorScheme() - const { classes } = useStyles() + const [opened, setOpened] = useState(false) + const customContextMenu = useAppSelector(state => state.user.settings?.customContextMenu) const sourceType = useAppSelector(state => state.entries.source.type) const dispatch = useAppDispatch() 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 ( - - { - window.open(props.entry.url, "_blank", "noreferrer") - dispatch(markEntry({ entry: props.entry, read: true })) - }} - > - - - Open link in new tab - - - { - openLinkInBackgroundTab(props.entry.url) - dispatch(markEntry({ entry: props.entry, read: true })) - }} - > - - - Open link in new background tab - - - - - - {props.entry.markable && ( - - await dispatch(starEntry({ entry: props.entry, starred: !props.entry.starred })) - } - > - - {props.entry.starred ? : } - {props.entry.starred ? Unstar : Star} - - - )} - {props.entry.markable && ( - await dispatch(markEntry({ entry: props.entry, read: !props.entry.read }))}> - - {props.entry.read ? : } - {props.entry.read ? Keep unread : Mark as read} - - - )} - await dispatch(markEntriesUpToEntry(props.entry))}> - - - Mark as read up to here - - - - {sourceType === "category" && } - {sourceType === "category" && ( - + {props.children} + + } onClick={() => { - dispatch(redirectToFeed(props.entry.feedId)) + window.open(props.entry.url, "_blank", "noreferrer") + dispatch(markEntry({ entry: props.entry, read: true })) }} > - - + Open link in new tab + + } + onClick={() => { + openLinkInBackgroundTab(props.entry.url) + dispatch(markEntry({ entry: props.entry, read: true })) + }} + > + Open link in new background tab + + + + + {props.entry.markable && ( + : } + onClick={async () => + await dispatch(starEntry({ entry: props.entry, starred: !props.entry.starred })) + } + > + {props.entry.starred ? Unstar : Star} + + )} + {props.entry.markable && ( + : } + onClick={async () => await dispatch(markEntry({ entry: props.entry, read: !props.entry.read }))} + > + {props.entry.read ? Keep unread : Mark as read} + + )} + } + onClick={async () => await dispatch(markEntriesUpToEntry(props.entry))} + > + Mark as read up to here + + + {sourceType === "category" && } + {sourceType === "category" && ( + } + onClick={() => { + dispatch(redirectToFeed(props.entry.feedId)) + }} + > Go to {truncate(props.entry.feedName, 30)} - - - )} + + )} + ) } diff --git a/commafeed-client/src/main.tsx b/commafeed-client/src/main.tsx index e0377032..36ad4884 100644 --- a/commafeed-client/src/main.tsx +++ b/commafeed-client/src/main.tsx @@ -2,7 +2,6 @@ import "@fontsource/open-sans" import "@mantine/core/styles.css" import "@mantine/notifications/styles.css" import "@mantine/spotlight/styles.css" -import "react-contexify/ReactContexify.css" import dayjs from "dayjs" import duration from "dayjs/plugin/duration" import relativeTime from "dayjs/plugin/relativeTime"