import { motion } from 'framer-motion' import { useRef } from 'react' import { useLocation } from 'react-router-dom' import PrefetchLink from '@/components/PrefetchLink' import { useClientBehaviourSettings } from '@/lib/useClientBehaviourSettings' import { cn } from '@/lib/utils' import { useSharedTransitionStore } from '@/stores/sharedTransitionStore' import type { FC, MouseEvent } from 'react' import type { Post } from '@/types' type Props = { posts: Post[] onClick?: (event: MouseEvent) => void } const PostList: FC = ({ posts, onClick }) => { const location = useLocation () const behaviourSettings = useClientBehaviourSettings () const thumbnailMode = behaviourSettings.thumbnailMode ?? 'normal' const animationMode = behaviourSettings.animation ?? 'normal' const cardLayoutTransition = animationMode === 'off' ? { duration: 0 } : animationMode === 'reduced' ? { duration: .08, ease: 'linear' as const } : { duration: .2, ease: 'easeOut' as const } const setForLocationKey = useSharedTransitionStore (s => s.setForLocationKey) const cardRef = useRef (null) return (
{posts.map ((post, i) => { const sharedId = `page-${ post.id }` const layoutId = sharedId return ( { setForLocationKey (location.key, sharedId) onClick?.(e) }}> 0 && 'ring-4 ring-green-500', (post.parentPosts ?? []).length > 0 && 'ring-4 ring-yellow-500')} whileHover={{ scale: 1.02 }} onLayoutAnimationStart={() => { if (!(cardRef.current)) return cardRef.current.style.position = 'relative' cardRef.current.style.zIndex = '9999' }} onLayoutAnimationComplete={() => { if (!(cardRef.current)) return cardRef.current.style.zIndex = '' cardRef.current.style.position = '' }} transition={{ layout: cardLayoutTransition }}> {thumbnailMode === 'off' ? (
サムネイルなし
) : ( {post.title)}
) })}
) } export default PostList