import { Text, Group, UnstyledButton, Avatar, Tooltip } from "@mantine/core"; import { CustomAvatar } from "@/components/ui/custom-avatar.tsx"; import { formattedDate } from "@/lib/time"; import classes from "./css/history.module.css"; import clsx from "clsx"; import { IPageHistory } from "@/features/page-history/types/page.types"; import { memo, useCallback } from "react"; const MAX_VISIBLE_AVATARS = 5; interface HistoryItemProps { historyItem: IPageHistory; index: number; onSelect: (id: string, index: number) => void; onHover?: (id: string, index: number) => void; onHoverEnd?: () => void; isActive: boolean; } const HistoryItem = memo(function HistoryItem({ historyItem, index, onSelect, onHover, onHoverEnd, isActive, }: HistoryItemProps) { const handleClick = useCallback(() => { onSelect(historyItem.id, index); }, [onSelect, historyItem.id, index]); const handleMouseEnter = useCallback(() => { onHover?.(historyItem.id, index); }, [onHover, historyItem.id, index]); const contributors = historyItem.contributors; const hasContributors = contributors && contributors.length > 0; return ( {formattedDate(new Date(historyItem.createdAt))} {hasContributors ? ( <> {contributors.slice(0, MAX_VISIBLE_AVATARS).map((contributor) => ( ))} {contributors.length > MAX_VISIBLE_AVATARS && ( (
{c.name}
))} > +{contributors.length - MAX_VISIBLE_AVATARS}
)}
{contributors.length === 1 && ( {contributors[0].name} )} ) : ( <> {historyItem.lastUpdatedBy?.name} )}
); }); export default HistoryItem;