diff --git a/commafeed-client/src/components/content/FeedEntries.tsx b/commafeed-client/src/components/content/FeedEntries.tsx index 901c31f0..d538793c 100644 --- a/commafeed-client/src/components/content/FeedEntries.tsx +++ b/commafeed-client/src/components/content/FeedEntries.tsx @@ -1,7 +1,7 @@ import { Trans } from "@lingui/react/macro" import { Box } from "@mantine/core" import { openModal } from "@mantine/modals" -import { useEffect } from "react" +import { useEffect, useState } from "react" import InfiniteScroll from "react-infinite-scroller" import { throttle } from "throttle-debounce" import { Constants } from "@/app/constants" @@ -78,6 +78,23 @@ export function FeedEntries() { const swipedLeft = async (entry: ExpendableEntry) => await dispatch(markEntry({ entry, read: !entry.read })) + // only one context menu can be opened at a time + const [contextMenuEntryId, setContextMenuEntryId] = useState() + const contextMenuChanged = (entry: ExpendableEntry, opened: boolean) => + setContextMenuEntryId(current => { + if (opened) return entry.id + return current === entry.id ? undefined : current + }) + + // close context menu on scroll + useEffect(() => { + if (!contextMenuEntryId) return + + const listener = throttle(100, () => setContextMenuEntryId(undefined)) + window.addEventListener("scroll", listener) + return () => window.removeEventListener("scroll", listener) + }, [contextMenuEntryId]) + useEffect(() => { const listener = throttle(100, () => { if (viewMode !== "expanded") return @@ -287,6 +304,8 @@ export function FeedEntries() { onHeaderClick={event => headerClicked(entry, event)} onBodyClick={() => bodyClicked(entry)} onSwipedLeft={async () => await swipedLeft(entry)} + contextMenuOpened={entry.id === contextMenuEntryId} + onContextMenuChange={opened => contextMenuChanged(entry, opened)} /> ))} diff --git a/commafeed-client/src/components/content/FeedEntry.tsx b/commafeed-client/src/components/content/FeedEntry.tsx index accc6add..176145c7 100644 --- a/commafeed-client/src/components/content/FeedEntry.tsx +++ b/commafeed-client/src/components/content/FeedEntry.tsx @@ -21,6 +21,8 @@ interface FeedEntryProps { onHeaderClick: (e: React.MouseEvent) => void onBodyClick: (e: React.MouseEvent) => void onSwipedLeft: () => void + contextMenuOpened: boolean + onContextMenuChange: (opened: boolean) => void } const useStyles = tss @@ -170,7 +172,11 @@ export function FeedEntry(props: Readonly) { "show-selection-indicator": props.showSelectionIndicator, })} > - + void // element that opens the menu when right-clicked children: ReactElement } @@ -19,23 +20,13 @@ interface FeedEntryContextMenuProps { const iconSize = 16 export function FeedEntryContextMenu(props: Readonly) { - 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 ( - + {props.children}