From 42bdc2add9a2e549f892a860bfefd578afe74910 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 9 May 2023 21:30:10 +0200 Subject: [PATCH] Copy hooks/useHovering.ts to glitch-soc --- .../flavours/glitch/components/avatar.tsx | 2 +- .../flavours/glitch/hooks/useHovering.ts | 17 +++++++++++++++++ tsconfig.json | 4 +++- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 app/javascript/flavours/glitch/hooks/useHovering.ts diff --git a/app/javascript/flavours/glitch/components/avatar.tsx b/app/javascript/flavours/glitch/components/avatar.tsx index d6a962146..88286dba8 100644 --- a/app/javascript/flavours/glitch/components/avatar.tsx +++ b/app/javascript/flavours/glitch/components/avatar.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; import classNames from 'classnames'; import { autoPlayGif } from 'flavours/glitch/initial_state'; -import { useHovering } from 'hooks/useHovering'; +import { useHovering } from 'flavours/glitch/hooks/useHovering'; import type { Account } from 'flavours/glitch/types/resources'; type Props = { diff --git a/app/javascript/flavours/glitch/hooks/useHovering.ts b/app/javascript/flavours/glitch/hooks/useHovering.ts new file mode 100644 index 000000000..2062e70d2 --- /dev/null +++ b/app/javascript/flavours/glitch/hooks/useHovering.ts @@ -0,0 +1,17 @@ +import { useCallback, useState } from 'react'; + +export const useHovering = (animate?: boolean) => { + const [hovering, setHovering] = useState(animate ?? false); + + const handleMouseEnter = useCallback(() => { + if (animate) return; + setHovering(true); + }, [animate]); + + const handleMouseLeave = useCallback(() => { + if (animate) return; + setHovering(false); + }, [animate]); + + return { hovering, handleMouseEnter, handleMouseLeave }; +}; diff --git a/tsconfig.json b/tsconfig.json index 480f6bdb7..eca8c99e9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,9 @@ "skipLibCheck": true, "baseUrl": "./", "paths": { - "*": ["app/javascript/*"], + "locales": ["app/javascript/locales"], + "flavours/glitch": ["app/javascript/flavours/glitch"], + "flavours/glitch/*": ["app/javascript/flavours/glitch/*"], "mastodon": ["app/javascript/mastodon"], "mastodon/*": ["app/javascript/mastodon/*"] }