refactor: replace useGetCommand with getCommand for improved command retrieval

- Updated the command retrieval method in various hooks and components to use the new getCommand function instead of the deprecated useGetCommand.
- Refactored related tests to ensure type correctness with the new command retrieval approach.
- Enhanced the PictureWaterFallItem component by optimizing mouse event handling with useCallback for better performance.
- Improved animation handling in the PictureWaterFallItem component for smoother transitions.

This change streamlines command access and enhances component performance.

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2024-12-17 00:32:28 +08:00
parent edc9e3008e
commit d0bf0fb657
5 changed files with 42 additions and 31 deletions
@@ -9,7 +9,7 @@ import { FeedViewType } from "@follow/constants"
import { cn } from "@follow/utils/utils"
import { AnimatePresence, m } from "framer-motion"
import type { PropsWithChildren } from "react"
import { memo, useContext, useEffect, useMemo, useState } from "react"
import { memo, useCallback, useContext, useEffect, useMemo, useState } from "react"
import { useTranslation } from "react-i18next"
import { SwipeMedia } from "~/components/ui/media/SwipeMedia"
@@ -64,6 +64,9 @@ const proxySize = {
width: 600,
height: 0,
}
const footerAnimate = { opacity: 1, y: 0 }
const footerExit = { opacity: 0, y: 10 }
export const PictureWaterFallItem = memo(function PictureWaterFallItem({
entryId,
entryPreview,
@@ -93,19 +96,26 @@ export const PictureWaterFallItem = memo(function PictureWaterFallItem({
const [isMouseEnter, setIsMouseEnter] = useState(false)
if (!entry) return null
const media = useMemo(() => filterSmallMedia(entry?.entries.media || []), [entry?.entries.media])
const media = filterSmallMedia(entry.entries.media)
const handleMouseEnter = useCallback(() => {
setIsMouseEnter(true)
}, [])
const handleMouseLeave = useCallback(() => {
setIsMouseEnter(false)
}, [])
if (media?.length === 0) return null
if (!entry) return null
return (
<div
ref={setRef}
data-entry-id={entryId}
data-index={index}
onMouseEnter={() => setIsMouseEnter(true)}
onMouseLeave={() => setIsMouseEnter(false)}
onTouchMove={() => setIsMouseEnter(true)}
onTouchEnd={() => setIsMouseEnter(false)}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
onTouchMove={handleMouseEnter}
onTouchEnd={handleMouseLeave}
className={className}
>
<EntryItemWrapper
@@ -129,9 +139,9 @@ export const PictureWaterFallItem = memo(function PictureWaterFallItem({
<AnimatePresence>
{isMouseEnter && (
<m.div
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: 10 }}
initial={footerExit}
animate={footerAnimate}
exit={footerExit}
className="absolute inset-x-0 -bottom-px z-[3] overflow-hidden rounded-b-md pb-1"
key="footer"
>
@@ -200,6 +210,10 @@ const MasonryItemFixedDimensionWrapper = (
)
}
MasonryItemFixedDimensionWrapper.whyDidYouRender = {
logOnDifferentValues: true,
}
export const PictureItemSkeleton = (
<div className="relative max-w-md rounded-md bg-theme-background text-zinc-700 transition-colors dark:text-neutral-400">
<div className="relative">