"use client"; import { useEffect, useRef, useState } from "preact/hooks"; import { type PubLeafletBlocksText, type PubLeafletDocument, } from "npm:@atcute/leaflet"; import { cx } from "../lib/cx.ts"; import { PostInfo } from "./post-info.tsx"; import { Title } from "./typography.tsx"; export function PostListItem({ post, rkey, }: { post: PubLeafletDocument.Main; rkey: string; }) { const [isHovered, setIsHovered] = useState(false); const [isLeaving, setIsLeaving] = useState(false); const timeoutRef = useRef | null>(null); // Clean up any timeouts on unmount useEffect(() => { return () => { if (timeoutRef.current) { clearTimeout(timeoutRef.current); } }; }, []); const handleMouseEnter = () => { if (timeoutRef.current) { clearTimeout(timeoutRef.current); } setIsLeaving(false); setIsHovered(true); }; const handleMouseLeave = () => { setIsLeaving(true); timeoutRef.current = setTimeout(() => { setIsHovered(false); setIsLeaving(false); }, 300); // Match animation duration }; // Gather all text blocks' plaintext for preview and reading time const allText = post.pages?.[0]?.blocks ?.filter((block) => block.block.$type === "pub.leaflet.blocks.text") .map((block) => (block.block as PubLeafletBlocksText.Main).plaintext) .join(" ") || ""; return ( <> {isHovered && (
{Array(8).fill(post.title).join(" ยท ")}
)}
{post.title}

{allText}

); }