import { useAppLayout } from "contexts/AppLayoutContext"; import { DatePickerFragment, PricePickerFragment, UploadImageFragment, } from "graphql/generated"; import { AppStaticProps } from "graphql/getAppStaticProps"; import { prettyDate, prettyDuration, prettyPrice, prettyShortenNumber, } from "helpers/formatters"; import { ImageQuality } from "helpers/img"; import { Immutable } from "helpers/types"; import Link from "next/link"; import Chip from "./Chip"; import Img from "./Img"; interface Props { thumbnail?: UploadImageFragment | string | null | undefined; thumbnailAspectRatio?: string; href: string; pre_title?: string | null | undefined; title: string | null | undefined; subtitle?: string | null | undefined; description?: string | null | undefined; topChips?: string[]; bottomChips?: string[]; keepInfoVisible?: boolean; metadata?: { currencies?: AppStaticProps["currencies"]; release_date?: DatePickerFragment | null; price?: PricePickerFragment | null; views?: number; author?: string; position: "Bottom" | "Top"; }; hoverlay?: | { __typename: "Video"; duration: number; } | { __typename: "anotherHoverlayName" }; } export default function PreviewCard(props: Immutable): JSX.Element { const { href, thumbnail, pre_title, title, subtitle, description, topChips, bottomChips, keepInfoVisible, thumbnailAspectRatio, metadata, hoverlay, } = props; const appLayout = useAppLayout(); const metadataJSX = metadata && (metadata.release_date || metadata.price) ? (
{metadata.release_date && (

event {prettyDate(metadata.release_date)}

)} {metadata.price && metadata.currencies && (

shopping_cart {prettyPrice( metadata.price, metadata.currencies, appLayout.currency )}

)} {metadata.views && (

visibility {prettyShortenNumber(metadata.views)}

)} {metadata.author && (

person {metadata.author}

)}
) : ( <> ); return (
{thumbnail ? (
{hoverlay && hoverlay.__typename === "Video" && ( <>
play_circle_outline
{prettyDuration(hoverlay.duration)}
)}
) : (
)}
{metadata?.position === "Top" && metadataJSX} {topChips && topChips.length > 0 && (
{topChips.map((text, index) => ( {text} ))}
)}
{pre_title &&

{pre_title}

} {title && (

{title}

)} {subtitle &&

{subtitle}

}
{description &&

{description}

} {bottomChips && bottomChips.length > 0 && (
{bottomChips.map((text, index) => ( {text} ))}
)} {metadata?.position === "Bottom" && metadataJSX}
); }