From b3edbbcc006c71db6cdd892b8e4ffd7071fe314c Mon Sep 17 00:00:00 2001 From: yohlo Date: Wed, 20 Aug 2025 22:50:00 -0500 Subject: [PATCH] remove unused haptics hook --- src/hooks/use-haptic.ts | 61 ----------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 src/hooks/use-haptic.ts diff --git a/src/hooks/use-haptic.ts b/src/hooks/use-haptic.ts deleted file mode 100644 index 04d6da0..0000000 --- a/src/hooks/use-haptic.ts +++ /dev/null @@ -1,61 +0,0 @@ -// Sneaky way of triggering haptic feedback, without using the vibration API (not available on iOS) -// Source: https://github.com/posaune0423/use-haptic - -import { useCallback, useEffect, useMemo, useRef } from "react"; - -const detectiOS = (): boolean => { - if (typeof navigator === "undefined") { - return false; - } - - const toMatch = [/iPhone/i, /iPad/i, /iPod/i]; - - return toMatch.some((toMatchItem) => { - return RegExp(toMatchItem).exec(navigator.userAgent); - }); -}; - -const useHaptic = ( - duration = 200, -): { triggerHaptic: () => void } => { - const inputRef = useRef(null); - const labelRef = useRef(null); - const isIOS = useMemo(() => detectiOS(), []); - - useEffect(() => { - const input = document.createElement("input"); - input.type = "checkbox"; - input.id = "haptic-switch"; - input.setAttribute("switch", ""); - input.style.display = "none"; - document.body.appendChild(input); - inputRef.current = input; - - const label = document.createElement("label"); - label.htmlFor = "haptic-switch"; - label.style.display = "none"; - document.body.appendChild(label); - labelRef.current = label; - - return () => { - document.body.removeChild(input); - document.body.removeChild(label); - }; - }, []); - - const triggerHaptic = useCallback(() => { - if (isIOS) { - labelRef.current?.click(); - } else { - if (navigator?.vibrate) { - navigator.vibrate(duration); - } else { - labelRef.current?.click(); - } - } - }, [isIOS]); - - return { triggerHaptic }; -}; - -export default useHaptic;