diff options
| author | Dhravya <[email protected]> | 2024-05-25 18:41:26 -0500 |
|---|---|---|
| committer | Dhravya <[email protected]> | 2024-05-25 18:41:26 -0500 |
| commit | 075f45986fd4d198292226e64afb71b3515576b4 (patch) | |
| tree | 5c728356cd0310f1c1c012fd6618c72a836c314b /apps/web/src/hooks | |
| parent | added social material (diff) | |
| download | archived-supermemory-075f45986fd4d198292226e64afb71b3515576b4.tar.xz archived-supermemory-075f45986fd4d198292226e64afb71b3515576b4.zip | |
refactored UI, with shared components and UI, better rules and million lint
Diffstat (limited to 'apps/web/src/hooks')
| -rw-r--r-- | apps/web/src/hooks/useDebounce.ts | 27 | ||||
| -rw-r--r-- | apps/web/src/hooks/useTouchHold.ts | 27 | ||||
| -rw-r--r-- | apps/web/src/hooks/useViewport.ts | 34 |
3 files changed, 0 insertions, 88 deletions
diff --git a/apps/web/src/hooks/useDebounce.ts b/apps/web/src/hooks/useDebounce.ts deleted file mode 100644 index d133b1ae..00000000 --- a/apps/web/src/hooks/useDebounce.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { useEffect, useState } from "react"; - -/** - * Use this hook when you need to debounce a value. - * @param value - * @param delay in milliseconds - */ -export const useDebounce = <T>(value: T, delay: number) => { - // State and setters for debounced value - const [debouncedValue, setDebouncedValue] = useState<T>(value); - - useEffect(() => { - // Update debounced value after delay - const handler = setTimeout(() => { - setDebouncedValue(value); - }, delay); - - // Cancel the timeout if value changes (also on delay change or unmount) - // This is how we prevent debounced value from updating if the value is changed - // within the delay period. Timeout gets cleared and restarted. - return () => { - clearTimeout(handler); - }; - }, [value, delay]); - - return debouncedValue; -}; diff --git a/apps/web/src/hooks/useTouchHold.ts b/apps/web/src/hooks/useTouchHold.ts deleted file mode 100644 index 52e56491..00000000 --- a/apps/web/src/hooks/useTouchHold.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { useState } from "react"; - -// holdDuration (in ms) -const useTouchHold = ({ - onHold, - holdDuration = 500, -}: { - holdDuration?: number; - onHold: () => Promise<void> | void; -}) => { - const [touchTimeout, setTouchTimeout] = useState<ReturnType< - typeof setTimeout - > | null>(null); - - return { - onTouchStart: () => { - setTouchTimeout(setTimeout(onHold, holdDuration)); - }, - onTouchEnd: () => { - if (touchTimeout) { - clearTimeout(touchTimeout); - } - }, - }; -}; - -export default useTouchHold; diff --git a/apps/web/src/hooks/useViewport.ts b/apps/web/src/hooks/useViewport.ts deleted file mode 100644 index 7ba90861..00000000 --- a/apps/web/src/hooks/useViewport.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { useState, useEffect } from "react"; - -function getViewport() { - try { - const { innerWidth: width, innerHeight: height } = window ?? { - innerWidth: 0, - innerHeight: 0, - }; - return { - width, - height, - }; - } catch { - return { - width: 0, - height: 0, - }; - } -} - -export default function useViewport() { - const [viewport, setViewport] = useState(getViewport()); - - useEffect(() => { - function handleResize() { - setViewport(getViewport()); - } - - window.addEventListener("resize", handleResize); - return () => window.removeEventListener("resize", handleResize); - }, []); - - return viewport; -} |