import { Download, LoaderCircle } from "lucide-react"; import { Link } from "react-router-dom"; import type { Resource } from "../api"; import { assetUrl } from "../api"; import { useI18n } from "../i18n"; import { useMemo, useState } from "react"; import { formatDateYmd } from "../utils/format"; import { DownloadCloudIcon } from "./icons/DownloadCloudIcon"; import { officialRecommendationCoverFallbacks } from "./FigmaBanner"; import { downloadAttachment, downloadFile, } from "./messageStream/utils/downloadFile"; function isPlaceholderAsset(path: string | undefined | null) { return !path || path.includes("placeholder-cover"); } const CARD_CLASS = "group flex w-[208px] shrink-0 flex-col overflow-hidden rounded-xl border bg-[#1D1E23] transition hover:border-ark-gold/55 md:w-[240px] lg:w-[246.4px] min-[1100px]:max-xl:w-[273px] xl:w-[246.4px]"; type RecommendedResource = Resource & { downloadPostId?: string; downloadAttachmentId?: string; }; export function RecommendedCard({ r, visualIndex = 0, useFigmaDesign = false, }: { r: RecommendedResource; visualIndex?: number; useFigmaDesign?: boolean; }) { const { t } = useI18n(); const [isDownloading, setIsDownloading] = useState(false); const figmaCover = officialRecommendationCoverFallbacks[ visualIndex % officialRecommendationCoverFallbacks.length ]; const cover = useMemo(() => { if (useFigmaDesign) return figmaCover; const original = r.coverImage || r.previewUrl; if (isPlaceholderAsset(original)) { return figmaCover; } return assetUrl(original); }, [figmaCover, r.coverImage, r.previewUrl, useFigmaDesign]); const displayTitle = r.title; const displayCategoryName = r.categoryName; const dateStr = formatDateYmd(r.updatedAt); const dateTime = r.updatedAt; const dl = r.isDownloadable && (r.fileUrl || r.previewUrl) ? assetUrl(r.fileUrl || r.previewUrl) : ""; const handleDownload = async () => { if (isDownloading) return; setIsDownloading(true); try { if (r.downloadPostId && r.downloadAttachmentId) { await downloadAttachment( r.downloadPostId, r.downloadAttachmentId, displayTitle, ); return; } await downloadFile(dl, displayTitle); } catch { /* ignore */ } finally { setIsDownloading(false); } }; return (
{cover ? ( ) : (
)} {!useFigmaDesign && r.badgeLabel ? ( {r.badgeLabel} ) : null}
{displayTitle} {useFigmaDesign ? (
{displayCategoryName}
) : null}
{useFigmaDesign ? null : ( <> {displayCategoryName} · )}
{dl ? ( ) : null}
); } export function ComingSoonRecommendedCard({ visualIndex = 0, }: { visualIndex?: number; }) { const cover = officialRecommendationCoverFallbacks[ visualIndex % officialRecommendationCoverFallbacks.length ]; return (
即将到来
即将到来
更多内容准备中
); }