|
| 1 | +import { useTranslation } from "react-i18next"; |
| 2 | +import { openUrl } from "@tauri-apps/plugin-opener"; |
| 3 | +import { |
| 4 | + X, |
| 5 | + Sparkles, |
| 6 | + Bug, |
| 7 | + AlertTriangle, |
| 8 | + Rocket, |
| 9 | + ExternalLink, |
| 10 | + Loader2, |
| 11 | + Github, |
| 12 | +} from "lucide-react"; |
| 13 | +import { Modal } from "../ui/Modal"; |
| 14 | +import { DiscordIcon } from "../icons/DiscordIcon"; |
| 15 | +import { type ChangelogEntry } from "../../utils/changelog"; |
| 16 | +import { GITHUB_URL, DISCORD_URL } from "../../config/links"; |
| 17 | + |
| 18 | +interface WhatsNewModalProps { |
| 19 | + isOpen: boolean; |
| 20 | + onClose: () => void; |
| 21 | + entries: ChangelogEntry[]; |
| 22 | + isLoading: boolean; |
| 23 | +} |
| 24 | + |
| 25 | +const UTM_SUFFIX = "?utm_src=tabularis-app"; |
| 26 | + |
| 27 | +export const WhatsNewModal = ({ |
| 28 | + isOpen, |
| 29 | + onClose, |
| 30 | + entries, |
| 31 | + isLoading, |
| 32 | +}: WhatsNewModalProps) => { |
| 33 | + const { t } = useTranslation(); |
| 34 | + |
| 35 | + return ( |
| 36 | + <Modal isOpen={isOpen} onClose={onClose}> |
| 37 | + <div className="bg-elevated border border-strong rounded-xl shadow-2xl w-[600px] max-h-[90vh] overflow-hidden flex flex-col"> |
| 38 | + {/* Header */} |
| 39 | + <div className="flex items-center justify-between p-4 border-b border-default bg-base"> |
| 40 | + <div className="flex items-center gap-3"> |
| 41 | + <div className="p-2 bg-purple-900/30 rounded-lg"> |
| 42 | + <Sparkles size={20} className="text-purple-400" /> |
| 43 | + </div> |
| 44 | + <div> |
| 45 | + <h2 className="text-lg font-semibold text-primary"> |
| 46 | + {t("whatsNew.title")} |
| 47 | + </h2> |
| 48 | + {entries.length > 0 && ( |
| 49 | + <p className="text-xs text-secondary"> |
| 50 | + {t("whatsNew.subtitle", { version: entries[0].version })} |
| 51 | + </p> |
| 52 | + )} |
| 53 | + </div> |
| 54 | + </div> |
| 55 | + <button |
| 56 | + onClick={onClose} |
| 57 | + className="text-secondary hover:text-primary transition-colors" |
| 58 | + > |
| 59 | + <X size={20} /> |
| 60 | + </button> |
| 61 | + </div> |
| 62 | + |
| 63 | + {/* Content */} |
| 64 | + <div className="p-6 space-y-6 overflow-y-auto"> |
| 65 | + {isLoading && ( |
| 66 | + <div className="text-center py-8 text-muted"> |
| 67 | + <Loader2 size={24} className="animate-spin mx-auto mb-2" /> |
| 68 | + {t("common.loading")} |
| 69 | + </div> |
| 70 | + )} |
| 71 | + |
| 72 | + {!isLoading && |
| 73 | + entries.map((entry) => ( |
| 74 | + <div key={entry.version} className="space-y-4"> |
| 75 | + <div className="flex items-center justify-between"> |
| 76 | + <div className="flex items-center gap-2"> |
| 77 | + <span className="text-sm font-semibold text-primary"> |
| 78 | + v{entry.version} |
| 79 | + </span> |
| 80 | + <span className="text-xs text-muted"> |
| 81 | + {new Date(entry.date).toLocaleDateString()} |
| 82 | + </span> |
| 83 | + </div> |
| 84 | + {entry.url && ( |
| 85 | + <button |
| 86 | + onClick={() => |
| 87 | + openUrl(`${entry.url}${UTM_SUFFIX}`) |
| 88 | + } |
| 89 | + className="flex items-center gap-1.5 text-xs text-blue-400 hover:text-blue-300 transition-colors" |
| 90 | + > |
| 91 | + {t("whatsNew.readMore")} |
| 92 | + <ExternalLink size={12} /> |
| 93 | + </button> |
| 94 | + )} |
| 95 | + </div> |
| 96 | + |
| 97 | + {entry.features.length > 0 && ( |
| 98 | + <ChangelogSection |
| 99 | + icon={<Rocket size={14} className="text-green-400" />} |
| 100 | + label={t("whatsNew.features")} |
| 101 | + items={entry.features} |
| 102 | + dotColor="before:bg-green-400/60" |
| 103 | + /> |
| 104 | + )} |
| 105 | + |
| 106 | + {entry.bugFixes.length > 0 && ( |
| 107 | + <ChangelogSection |
| 108 | + icon={<Bug size={14} className="text-blue-400" />} |
| 109 | + label={t("whatsNew.bugFixes")} |
| 110 | + items={entry.bugFixes} |
| 111 | + dotColor="before:bg-blue-400/60" |
| 112 | + /> |
| 113 | + )} |
| 114 | + |
| 115 | + {entry.breakingChanges.length > 0 && ( |
| 116 | + <ChangelogSection |
| 117 | + icon={ |
| 118 | + <AlertTriangle size={14} className="text-yellow-400" /> |
| 119 | + } |
| 120 | + label={t("whatsNew.breakingChanges")} |
| 121 | + items={entry.breakingChanges} |
| 122 | + dotColor="before:bg-yellow-400/60" |
| 123 | + /> |
| 124 | + )} |
| 125 | + |
| 126 | + {entries.indexOf(entry) < entries.length - 1 && ( |
| 127 | + <div className="border-t border-default" /> |
| 128 | + )} |
| 129 | + </div> |
| 130 | + ))} |
| 131 | + </div> |
| 132 | + |
| 133 | + {/* Footer */} |
| 134 | + <div className="p-4 border-t border-default bg-base/50 flex items-center justify-between"> |
| 135 | + <div className="flex items-center gap-2"> |
| 136 | + <button |
| 137 | + onClick={() => openUrl(GITHUB_URL)} |
| 138 | + className="p-2 text-secondary hover:text-primary hover:bg-surface-tertiary rounded-lg transition-colors" |
| 139 | + title="GitHub" |
| 140 | + > |
| 141 | + <Github size={18} /> |
| 142 | + </button> |
| 143 | + <button |
| 144 | + onClick={() => openUrl(DISCORD_URL)} |
| 145 | + className="p-2 text-secondary hover:text-indigo-400 hover:bg-indigo-900/20 rounded-lg transition-colors" |
| 146 | + title="Discord" |
| 147 | + > |
| 148 | + <DiscordIcon size={18} /> |
| 149 | + </button> |
| 150 | + </div> |
| 151 | + <button |
| 152 | + onClick={onClose} |
| 153 | + className="px-4 py-2 bg-blue-600 hover:bg-blue-500 text-white rounded-lg text-sm font-medium transition-colors" |
| 154 | + > |
| 155 | + {t("whatsNew.dismiss")} |
| 156 | + </button> |
| 157 | + </div> |
| 158 | + </div> |
| 159 | + </Modal> |
| 160 | + ); |
| 161 | +}; |
| 162 | + |
| 163 | +function ChangelogSection({ |
| 164 | + icon, |
| 165 | + label, |
| 166 | + items, |
| 167 | + dotColor, |
| 168 | +}: { |
| 169 | + icon: React.ReactNode; |
| 170 | + label: string; |
| 171 | + items: string[]; |
| 172 | + dotColor: string; |
| 173 | +}) { |
| 174 | + return ( |
| 175 | + <div> |
| 176 | + <div className="flex items-center gap-2 mb-2"> |
| 177 | + {icon} |
| 178 | + <span className="text-xs uppercase font-bold text-muted">{label}</span> |
| 179 | + </div> |
| 180 | + <ul className="space-y-1.5 overflow-hidden"> |
| 181 | + {items.map((item, i) => ( |
| 182 | + <li |
| 183 | + key={i} |
| 184 | + className={`text-sm text-secondary pl-5 relative break-words before:content-[''] before:absolute before:left-1.5 before:top-2 before:w-1.5 before:h-1.5 before:rounded-full ${dotColor}`} |
| 185 | + > |
| 186 | + {item} |
| 187 | + </li> |
| 188 | + ))} |
| 189 | + </ul> |
| 190 | + </div> |
| 191 | + ); |
| 192 | +} |
0 commit comments