refactor: use isHotkeyPressed

This commit is contained in:
Stephen Zhou 2024-11-12 13:17:40 +08:00
parent 52f6f21abb
commit 5b060f8f84
No known key found for this signature in database
3 changed files with 2 additions and 34 deletions

View File

@ -2,12 +2,12 @@ import { useDraggable } from "@dnd-kit/core"
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
import type { FeedViewType } from "@follow/constants"
import { views } from "@follow/constants"
import { useKeyPressing } from "@follow/hooks"
import { stopPropagation } from "@follow/utils/dom"
import { cn } from "@follow/utils/utils"
import * as HoverCard from "@radix-ui/react-hover-card"
import { AnimatePresence, m } from "framer-motion"
import { memo, useMemo, useRef, useState } from "react"
import { isHotkeyPressed } from "react-hotkeys-hook"
import { useTranslation } from "react-i18next"
import { Link } from "react-router-dom"
import Selecto from "react-selecto"
@ -191,8 +191,6 @@ function FeedListImpl({ className, view }: { className?: string; view: number })
const shouldFreeUpSpace = useShouldFreeUpSpace()
const isMetaKeyPressed = useKeyPressing("Meta")
return (
<div className={cn(className, "font-medium")}>
<ListHeader view={view} />
@ -201,7 +199,7 @@ function FeedListImpl({ className, view }: { className?: string; view: number })
ref={selectoRef}
rootContainer={document.body}
dragContainer={"#feeds-area"}
dragCondition={() => selectedFeedIds.length === 0 || isMetaKeyPressed}
dragCondition={() => selectedFeedIds.length === 0 || isHotkeyPressed("Meta")}
selectableTargets={["[data-feed-id]"]}
continueSelect
hitRate={10}

View File

@ -5,7 +5,6 @@ export * from "./useDark"
export * from "./useInputComposition"
export * from "./useInterval"
export * from "./useIsOnline"
export * from "./useKeyPressing"
export * from "./useMeasure"
export * from "./useOnce"
export * from "./usePageVisibility"

View File

@ -1,29 +0,0 @@
import { useEffect, useState } from "react"
export function useKeyPressing(key: string) {
const [isKeyPressed, setIsKeyPressed] = useState(false)
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === key) {
setIsKeyPressed(true)
}
}
const handleKeyUp = (event: KeyboardEvent) => {
if (event.key === key) {
setIsKeyPressed(false)
}
}
window.addEventListener("keydown", handleKeyDown)
window.addEventListener("keyup", handleKeyUp)
return () => {
window.removeEventListener("keydown", handleKeyDown)
window.removeEventListener("keyup", handleKeyUp)
}
}, [key])
return isKeyPressed
}