open-swe/ui/src/components/PwaUpdateToast.tsx
seahaven-openswe[bot] a7ddd79e98
Some checks are pending
CI / Lint (push) Waiting to run
CI / Format check (push) Waiting to run
CI / Unit tests (push) Waiting to run
CI / Playwright E2E (push) Waiting to run
CI / Docker build smoke (push) Waiting to run
feat: prompt-mode PWA update toast instead of autoUpdate reload (#102)
2026-07-01 21:53:28 -04:00

47 lines
1.2 KiB
TypeScript

import { useEffect, useState } from "react"
import { Button } from "@/components/ui/button"
interface PwaUpdateToastProps {
needRefresh: boolean
updateServiceWorker: (() => Promise<void>) | undefined
}
export function PwaUpdateToast({
needRefresh,
updateServiceWorker,
}: PwaUpdateToastProps) {
const [dismissed, setDismissed] = useState(false)
useEffect(() => {
if (needRefresh) {
setDismissed(false)
}
}, [needRefresh])
if (!needRefresh || dismissed) {
return null
}
return (
<div className="fixed right-4 bottom-4 z-50 flex max-w-sm items-center gap-3 rounded-lg border border-border bg-card p-3 shadow-lg">
<div className="flex-1 text-xs">
<p className="font-medium">A new version is available.</p>
<p className="text-muted-foreground">Reload to update the dashboard.</p>
</div>
<div className="flex items-center gap-2">
<Button
variant="outline"
size="xs"
onClick={() => setDismissed(true)}
aria-label="Dismiss update notice"
>
Later
</Button>
<Button size="xs" onClick={() => void updateServiceWorker?.()}>
Reload
</Button>
</div>
</div>
)
}