|
| 1 | +/* @proprietary license */ |
| 2 | + |
| 3 | +import { useState } from 'react'; |
| 4 | +import { motion } from 'framer-motion'; |
| 5 | +import { useTranslation } from '@/lib/utils/translation-context'; |
| 6 | +import { getTranslations } from '@/lib/i18n/translations'; |
| 7 | +import Link from 'next/link'; |
| 8 | +import { playClickSound } from '@/lib/utils/sound'; |
| 9 | + |
| 10 | +interface ChangelogEntry { |
| 11 | + date: string; |
| 12 | + version: string; |
| 13 | + title: string; |
| 14 | + changes: string[]; |
| 15 | +} |
| 16 | + |
| 17 | +interface ChangelogEntryCardProps { |
| 18 | + entry: ChangelogEntry; |
| 19 | + index: number; |
| 20 | + hoveredCard: string | null; |
| 21 | + onHover: (id: string | null) => void; |
| 22 | +} |
| 23 | + |
| 24 | +function ChangelogEntryCard({ |
| 25 | + entry, |
| 26 | + index, |
| 27 | + hoveredCard, |
| 28 | + onHover, |
| 29 | +}: ChangelogEntryCardProps) { |
| 30 | + const { currentLanguage } = useTranslation(); |
| 31 | + const translations = getTranslations(currentLanguage); |
| 32 | + |
| 33 | + return ( |
| 34 | + <motion.div |
| 35 | + className="w-full" |
| 36 | + onMouseEnter={() => onHover(`changelog-${index}`)} |
| 37 | + onMouseLeave={() => onHover(null)} |
| 38 | + initial={{ opacity: 0, y: 20 }} |
| 39 | + animate={{ opacity: 1, y: 0 }} |
| 40 | + transition={{ duration: 0.6, delay: index * 0.1 }} |
| 41 | + > |
| 42 | + <Link |
| 43 | + href="/changelog" |
| 44 | + className="group flex flex-col h-full" |
| 45 | + onMouseDown={playClickSound} |
| 46 | + > |
| 47 | + <article className="flex flex-col bg-white dark:bg-zinc-900 rounded-sm overflow-hidden shadow-sm hover:shadow-sm transition-all duration-300 border border-zinc-200 dark:border-zinc-800 h-full p-6 min-h-[200px]"> |
| 48 | + <div className="grow flex flex-col"> |
| 49 | + {/* Date and Badge in same row */} |
| 50 | + <div className="flex justify-between items-center mb-3"> |
| 51 | + <p className="text-zinc-500 dark:text-zinc-400 text-xs"> |
| 52 | + {translations.changelog.title} ·{' '} |
| 53 | + {new Date(entry.date).toLocaleDateString( |
| 54 | + currentLanguage === 'zh' |
| 55 | + ? 'zh-CN' |
| 56 | + : currentLanguage === 'fr' |
| 57 | + ? 'fr-FR' |
| 58 | + : currentLanguage === 'es' |
| 59 | + ? 'es-ES' |
| 60 | + : 'en-US', |
| 61 | + { |
| 62 | + year: 'numeric', |
| 63 | + month: 'short', |
| 64 | + day: 'numeric', |
| 65 | + }, |
| 66 | + )} |
| 67 | + </p> |
| 68 | + <span className="px-2 py-1 text-xs font-normal rounded bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-300"> |
| 69 | + Release |
| 70 | + </span> |
| 71 | + </div> |
| 72 | + |
| 73 | + {/* Title */} |
| 74 | + <h3 className="font-normal leading-tight text-zinc-900 dark:text-white text-lg mb-4 line-clamp-2"> |
| 75 | + {entry.title} |
| 76 | + </h3> |
| 77 | + |
| 78 | + {/* Summary - First change or description */} |
| 79 | + <p className="text-zinc-600 dark:text-zinc-400 text-sm mb-6 line-clamp-3 grow"> |
| 80 | + {entry.changes.length > 0 ? entry.changes[0] : 'New release with improvements and fixes'} |
| 81 | + </p> |
| 82 | + </div> |
| 83 | + |
| 84 | + {/* Bottom section with read text */} |
| 85 | + <div className="mt-auto flex justify-end"> |
| 86 | + <div className="flex items-center text-primary text-sm font-normal"> |
| 87 | + <span |
| 88 | + className={`transition-all duration-300 ${hoveredCard === `changelog-${index}` ? 'opacity-100' : 'opacity-0' |
| 89 | + }`} |
| 90 | + > |
| 91 | + {translations.changelog.read} |
| 92 | + </span> |
| 93 | + </div> |
| 94 | + </div> |
| 95 | + </article> |
| 96 | + </Link> |
| 97 | + </motion.div> |
| 98 | + ); |
| 99 | +} |
| 100 | + |
| 101 | +export function ChangelogCarousel() { |
| 102 | + const { currentLanguage } = useTranslation(); |
| 103 | + const [hoveredCard, setHoveredCard] = useState<string | null>(null); |
| 104 | + |
| 105 | + const translations = getTranslations(currentLanguage); |
| 106 | + const changelogData = translations.changelog as unknown as { |
| 107 | + entries?: ChangelogEntry[]; |
| 108 | + }; |
| 109 | + const changelogEntries = changelogData?.entries || []; |
| 110 | + |
| 111 | + return ( |
| 112 | + <div className="w-full mt-8 relative"> |
| 113 | + {/* Horizontal scrolling for all cards */} |
| 114 | + {changelogEntries.length > 0 && ( |
| 115 | + <div className="overflow-x-auto pb-4 scrollbar-hide"> |
| 116 | + <div className="flex gap-8" style={{ width: 'max-content' }}> |
| 117 | + {changelogEntries.slice(0, 6).map((entry, index) => ( |
| 118 | + <div key={`changelog-${index}`} className="shrink-0 w-[612px]"> |
| 119 | + <ChangelogEntryCard |
| 120 | + entry={entry} |
| 121 | + index={index} |
| 122 | + hoveredCard={hoveredCard} |
| 123 | + onHover={setHoveredCard} |
| 124 | + /> |
| 125 | + </div> |
| 126 | + ))} |
| 127 | + </div> |
| 128 | + </div> |
| 129 | + )} |
| 130 | + </div> |
| 131 | + ); |
| 132 | +} |
0 commit comments