From 43b38dc9e6e5e0a441090b263852be11ea636473 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 d6a9621462..88286dba82 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 0000000000..2062e70d26 --- /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 480f6bdb7f..eca8c99e92 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/*"] }