import { ContentStatus, ContentStatusPhase } from "./db"; export default function UpdateButton({ updateStatus, update, disabled = false, }: { updateStatus: ContentStatus | null; update: () => void; disabled?: boolean; }) { const current = updateStatus?.local?.date && `Last updated: ${Intl.DateTimeFormat([], { dateStyle: "medium" }).format( Date.parse(updateStatus?.local?.date) )}`; let button: JSX.Element | null = null; let info: string | undefined; switch (updateStatus?.phase) { case ContentStatusPhase.INITIAL: info = "Checking for updates"; break; case ContentStatusPhase.IDLE: if (updateStatus?.local?.version === updateStatus?.remote?.latest) { info = "Your content is up to date"; button = ; } else { if (updateStatus?.local) { info = "Update available"; button = ( ); } else { info = "Start using MDN Offline by downloading the latest version of MDN Web Docs"; button = ( ); } } break; case ContentStatusPhase.DOWNLOAD: if (updateStatus?.local) { info = "Update in progress…"; } else { info = "Download in progress…"; } button = ; break; case ContentStatusPhase.UNPACK: if (updateStatus?.local) { info = "Update in progress…"; } else { info = "Download in progress…"; } const progress = (updateStatus?.progress || 0) * 100; button = ( ); break; case ContentStatusPhase.CLEAR: info = "Clearing…"; break; } return (

Update status

{current} {current &&
} {info}
{button}
); }