import { ArrowDownToLine, RotateCw, X } from 'lucide-react' import React from 'react' import { I18nKey, t } from '../i18n' import { Locale, Task } from '../types' import { Tip } from '../ui/controls' /** Where an available update is: offered, downloading, verified and ready, or failed. */ export type UpdatePhase = 'none' | 'available' | 'downloading' | 'ready' | 'failed' interface Props { locale: Locale phase: UpdatePhase latest: string task?: Task | null /** Opens the About page with the full update details. */ onOpen: () => void onDownload: () => void onCancel: () => void onInstall: () => void /** Hides the card until the next release ("remind me later"). */ onDismiss: () => void } /** Capsule card under the sidebar brand: the update's state and one action. */ export const UpdateCapsule: React.FC = ({ locale, phase, latest, task, onOpen, onDownload, onCancel, onInstall, onDismiss, }) => { if (phase === 'none') return null const tr = (k: I18nKey, v?: Record) => t(locale, k, v) const pct = task && task.percent >= 0 ? Math.round(task.percent) : null let title: string let action: React.ReactNode = null let close: React.ReactNode = null if (phase === 'downloading') { title = pct === null ? tr('updateCapsuleDownloading') : tr('updateCapsuleDownloadingPct', { p: pct }) close = ( ) } else if (phase === 'ready') { title = tr('updateCapsuleReady', { v: latest }) action = } else if (phase === 'failed') { title = tr('updateCapsuleFailed') action = ( ) } else { title = tr('updateCapsuleAvailable', { v: latest }) action = close = ( ) } return (
{action} {close} {phase === 'downloading' && (
) }