diff options
| author | Yash <[email protected]> | 2024-04-06 16:55:37 +0000 |
|---|---|---|
| committer | Yash <[email protected]> | 2024-04-06 16:55:37 +0000 |
| commit | ad7906431700722da44cf2129906e652384f8a19 (patch) | |
| tree | c4c04d799db9305da9622f38ac2fad76a73f9d98 /apps/web/src/hooks | |
| parent | better phone ui (diff) | |
| download | archived-supermemory-ad7906431700722da44cf2129906e652384f8a19.tar.xz archived-supermemory-ad7906431700722da44cf2129906e652384f8a19.zip | |
better phone controls
Diffstat (limited to 'apps/web/src/hooks')
| -rw-r--r-- | apps/web/src/hooks/useTouchHold.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/apps/web/src/hooks/useTouchHold.ts b/apps/web/src/hooks/useTouchHold.ts new file mode 100644 index 00000000..52e56491 --- /dev/null +++ b/apps/web/src/hooks/useTouchHold.ts @@ -0,0 +1,27 @@ +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; |