import { useCallback } from "react"; import { useRouter } from "next/router"; import { Markdown } from "./Markdown/Markdown"; import { Chip } from "components/Chip"; import { Ico } from "components/Ico"; import { Img } from "components/Img"; import { UpPressable } from "components/Containers/UpPressable"; import { DatePickerFragment, PricePickerFragment, UploadImageFragment } from "graphql/generated"; import { cIf, cJoin } from "helpers/className"; import { prettyDate, prettyDuration, prettyPrice, prettyShortenNumber } from "helpers/formatters"; import { ImageQuality } from "helpers/img"; import { useDeviceSupportsHover } from "hooks/useMediaQuery"; import { useSmartLanguage } from "hooks/useSmartLanguage"; import { TranslatedProps } from "types/TranslatedProps"; import { atoms } from "contexts/atoms"; import { useAtomGetter } from "helpers/atoms"; /* * ╭─────────────╮ * ───────────────────────────────────────╯ COMPONENT ╰─────────────────────────────────────────── */ interface Props { thumbnail?: UploadImageFragment | string | null | undefined; thumbnailAspectRatio?: string; thumbnailForceAspectRatio?: boolean; thumbnailRounded?: boolean; 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?: { releaseDate?: DatePickerFragment | null; releaseDateFormat?: Intl.DateTimeFormatOptions["dateStyle"]; price?: PricePickerFragment | null; views?: number; author?: string; position: "Bottom" | "Top"; }; infoAppend?: React.ReactNode; hoverlay?: | { __typename: "Video"; duration: number; } | { __typename: "anotherHoverlayName" }; disabled?: boolean; className?: string; } // ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ export const PreviewCard = ({ href, thumbnail, thumbnailAspectRatio = "4/3", thumbnailForceAspectRatio = false, thumbnailRounded = true, pre_title, title, subtitle, description, topChips, bottomChips, keepInfoVisible, metadata, hoverlay, infoAppend, className, disabled = false, }: Props): JSX.Element => { const currency = useAtomGetter(atoms.settings.currency); const currencies = useAtomGetter(atoms.localData.currencies); const isHoverable = useDeviceSupportsHover(); const router = useRouter(); const metadataJSX = ( <> {metadata && (metadata.releaseDate || metadata.price) && (