From 5b060f8f8417d58bb2abccbf9316a7cf06fc7938 Mon Sep 17 00:00:00 2001
From: Stephen Zhou <38493346+hyoban@users.noreply.github.com>
Date: Tue, 12 Nov 2024 13:17:40 +0800
Subject: [PATCH] refactor: use isHotkeyPressed
---
.../renderer/src/modules/feed-column/list.tsx | 6 ++--
packages/hooks/src/index.ts | 1 -
packages/hooks/src/useKeyPressing.ts | 29 -------------------
3 files changed, 2 insertions(+), 34 deletions(-)
delete mode 100644 packages/hooks/src/useKeyPressing.ts
diff --git a/apps/renderer/src/modules/feed-column/list.tsx b/apps/renderer/src/modules/feed-column/list.tsx
index 98ffb8713..22ba219b6 100644
--- a/apps/renderer/src/modules/feed-column/list.tsx
+++ b/apps/renderer/src/modules/feed-column/list.tsx
@@ -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 (
@@ -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}
diff --git a/packages/hooks/src/index.ts b/packages/hooks/src/index.ts
index 5579cf1d9..cc321c9ba 100644
--- a/packages/hooks/src/index.ts
+++ b/packages/hooks/src/index.ts
@@ -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"
diff --git a/packages/hooks/src/useKeyPressing.ts b/packages/hooks/src/useKeyPressing.ts
deleted file mode 100644
index 38aa4dee1..000000000
--- a/packages/hooks/src/useKeyPressing.ts
+++ /dev/null
@@ -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
-}