"use client"; import { Fragment } from "react"; import { Avatar, Badge, Box, Divider, Group, Image, Stack, Text, TooltipFloating, UnstyledButton } from "@mantine/core"; import { IconBook, IconCalendar, IconClock, IconStarFilled } from "@tabler/icons-react"; import type { RouterOutputs } from "@homarr/api"; import { clientApi } from "@homarr/api/client"; import { getMantineColor, toValidDate } from "@homarr/common"; import { getIconUrl } from "@homarr/definitions"; import type { MediaRelease } from "@homarr/integrations/types"; import { mediaTypeConfigurations } from "@homarr/integrations/types"; import type { TranslationFunction } from "@homarr/translation"; import { useCurrentLocale, useI18n } from "@homarr/translation/client"; import type { TablerIcon } from "@homarr/ui"; import { OverflowBadge } from "@homarr/ui"; import type { WidgetComponentProps } from "../definition"; export default function MediaReleasesWidget({ options, integrationIds }: WidgetComponentProps<"mediaReleases">) { const { data: releases = [] } = clientApi.widget.mediaRelease.getMediaReleases.useQuery({ integrationIds, }); return ( {releases.map((item, index) => ( {index !== 0 && options.layout === "poster" && } ))} ); } interface ItemProps { item: RouterOutputs["widget"]["mediaRelease"]["getMediaReleases"][number]; options: WidgetComponentProps<"mediaReleases">["options"]; } const formatReleaseDate = (value: unknown, locale: string) => { const date = toValidDate(value); if (!date) return "—"; return Intl.DateTimeFormat(locale, { month: "2-digit", year: "numeric", day: "2-digit", hour: "2-digit", minute: "2-digit", hour12: false, }).format(date); }; const Item = ({ item, options }: ItemProps) => { const locale = useCurrentLocale(); const t = useI18n(); const length = formatLength(item.length, item.type, t); return ( {options.layout === "backdrop" && ( )} {options.layout === "poster" && {item.title}} {item.title} {item.subtitle !== undefined && ( {item.subtitle} )} {length !== undefined && ( <> )} {item.producer !== undefined && ( <> )} {item.rating !== undefined && ( <> )} {item.price !== undefined && ( <> )} {item.tags.length > 0 && ( )} {(options.showType || options.showSource) && ( {options.showType && ( {item.type} )} {options.showSource && ( )} )} ); }; interface IconAndLabelProps { icon?: TablerIcon; label: string; } const InfoDivider = () => ( • ); const Info = ({ icon: Icon, label }: IconAndLabelProps) => { return ( {Icon && } {label} ); }; const formatLength = (length: number | undefined, type: MediaRelease["type"], t: TranslationFunction) => { if (!length) return undefined; if (type === "movie" || type === "tv" || type === "video" || type === "music" || type === "article") { return { type: "duration" as const, label: t("widget.mediaReleases.length.duration", { length: Math.round(length / 60).toString(), }), }; } if (type === "book") { return { type: "page" as const, label: length.toString(), }; } return undefined; };