import { MouseEventHandler, useCallback } from "react"; import { DatePickerFragment } from "graphql/generated"; import { TranslatedProps } from "types/TranslatedProps"; import { useSmartLanguage } from "hooks/useSmartLanguage"; import { DownPressable } from "components/Containers/DownPressable"; import { isDefined } from "helpers/asserts"; import { cIf, cJoin } from "helpers/className"; /* * ╭─────────────╮ * ───────────────────────────────────────╯ COMPONENT ╰─────────────────────────────────────────── */ interface Props { date: DatePickerFragment; title: string; url: string; active?: boolean; disabled?: boolean; onClick?: MouseEventHandler; } // ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ export const ChroniclePreview = ({ date, url, title, active, disabled, onClick, }: Props): JSX.Element => ( {isDefined(date.year) && (

{date.year}

{prettyMonthDay(date.month, date.day)}

)}

{title}

); /* * ╭──────────────────────╮ * ───────────────────────────────────╯ TRANSLATED VARIANT ╰────────────────────────────────────── */ export const TranslatedChroniclePreview = ({ translations, fallback, ...otherProps }: TranslatedProps[0], "title">): JSX.Element => { const [selectedTranslation] = useSmartLanguage({ items: translations, languageExtractor: useCallback((item: { language: string }): string => item.language, []), }); return ; }; /* * ╭───────────────────╮ * ─────────────────────────────────────╯ PRIVATE METHODS ╰─────────────────────────────────────── */ const prettyMonthDay = ( month?: number | null | undefined, day?: number | null | undefined ): string => { let result = ""; if (month) { result += month.toString().padStart(2, "0"); if (day) { result += "/"; result += day.toString().padStart(2, "0"); } } return result; };