Skip to content

Commit

Permalink
fix: add bg when context menu trigger, fix #389
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Sep 14, 2024
1 parent a498228 commit 53f3185
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/renderer/src/modules/feed-column/category.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { useMutation } from "@tanstack/react-query"
import { AnimatePresence, m } from "framer-motion"
import type { FC } from "react"
import { Fragment, memo, useEffect, useRef, useState } from "react"
import {useTranslation } from "react-i18next"
import { useOnClickOutside } from "usehooks-ts"
import { useTranslation } from "react-i18next"
import { useClickAnyWhere, useOnClickOutside } from "usehooks-ts"

import { useModalStack } from "../../components/ui/modal/stacked/hooks"
import { useFeedListSortSelector } from "./atom"
Expand Down Expand Up @@ -108,6 +108,10 @@ function FeedCategoryImpl({

const [isCategoryEditing, setIsCategoryEditing] = useState(false)

const [isContextMenuOpen, setIsContextMenuOpen] = useState(false)
useClickAnyWhere(() => {
setIsContextMenuOpen(false)
})
const isCategoryIsWaiting = isChangePending

return (
Expand All @@ -116,7 +120,7 @@ function FeedCategoryImpl({
<div
className={cn(
"flex w-full items-center justify-between rounded-md px-2.5 transition-colors",
isActive && "bg-native-active",
(isActive || isContextMenuOpen) && "bg-native-active",
)}
onClick={(e) => {
e.stopPropagation()
Expand All @@ -125,6 +129,7 @@ function FeedCategoryImpl({
}
}}
onContextMenu={(e) => {
setIsContextMenuOpen(true)
showNativeMenu(
[
{
Expand Down
11 changes: 9 additions & 2 deletions src/renderer/src/modules/feed-column/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import { useSubscriptionByFeedId } from "@renderer/store/subscription"
import { useFeedUnreadStore } from "@renderer/store/unread"
import { WEB_URL } from "@shared/constants"
import dayjs from "dayjs"
import { memo, useCallback } from "react"
import { memo, useCallback, useState } from "react"
import { useTranslation } from "react-i18next"
import { useClickAnyWhere } from "usehooks-ts"

import { UnreadNumber } from "./unread-number"

Expand Down Expand Up @@ -60,6 +61,10 @@ const FeedItemImpl = ({ view, feedId, className, showUnreadCount = true }: FeedI

const { items } = useFeedActions({ feedId, view })

const [isContextMenuOpen, setIsContextMenuOpen] = useState(false)
useClickAnyWhere(() => {
setIsContextMenuOpen(false)
})
if (!feed) return null

return (
Expand All @@ -68,14 +73,16 @@ const FeedItemImpl = ({ view, feedId, className, showUnreadCount = true }: FeedI
data-feed-id={feedId}
className={cn(
"flex w-full items-center justify-between rounded-md py-[2px] pr-2.5 text-sm font-medium leading-loose",
isActive && "bg-native-active",
(isActive || isContextMenuOpen) && "bg-native-active",

className,
)}
onClick={handleNavigate}
onDoubleClick={() => {
window.open(`${WEB_URL}/feed/${feedId}?view=${view}`, "_blank")
}}
onContextMenu={(e) => {
setIsContextMenuOpen(true)
const nextItems = items.concat()
if (feed.errorAt && feed.errorMessage) {
nextItems.push(
Expand Down

0 comments on commit 53f3185

Please sign in to comment.