Spaces:
Running
Running
Download frontend/src/UpdatePrompt.tsx from Kurzga/SmartStock: direct link, hf CLI and curl.
- Browser
- Download file 2.33 kB
-
https://huggingface.co/spaces/Kurzga/SmartStock/resolve/main/frontend/src/UpdatePrompt.tsx
- Command line
-
hf download hf://spaces/Kurzga/SmartStock/frontend/src/UpdatePrompt.tsx
-
curl -L -o UpdatePrompt.tsx https://huggingface.co/spaces/Kurzga/SmartStock/resolve/main/frontend/src/UpdatePrompt.tsx
2.33 kB
| import { useRegisterSW } from 'virtual:pwa-register/react' | |
| // PWA yeni sürüm bildirimi. vite.config.ts'de registerType:'prompt' olduğu için service | |
| // worker yeni bir versiyon bulduğunda otomatik devreye girmez, bunun yerine needRefresh | |
| // true olur ve burada kullanıcıya "Yeni sürüm mevcut" bildirimi + Güncelle butonu gösteririz. | |
| // Butona basınca updateServiceWorker(true) yeni SW'yi aktif edip sayfayı yeniler. | |
| export default function UpdatePrompt() { | |
| const { | |
| offlineReady: [offlineReady, setOfflineReady], | |
| needRefresh: [needRefresh, setNeedRefresh], | |
| updateServiceWorker, | |
| } = useRegisterSW({ | |
| onRegisteredSW(_url, registration) { | |
| // Açık kalan sekmelerde yeni sürümü daha hızlı yakalamak için periyodik kontrol | |
| if (registration) { | |
| setInterval(() => { registration.update().catch(() => {}) }, 60 * 60 * 1000) | |
| } | |
| }, | |
| }) | |
| if (!needRefresh && !offlineReady) return null | |
| const close = () => { setNeedRefresh(false); setOfflineReady(false) } | |
| return ( | |
| <div | |
| role="status" | |
| style={{ | |
| position: 'fixed', left: '50%', bottom: 20, transform: 'translateX(-50%)', | |
| zIndex: 9999, background: '#0f172a', border: '1px solid rgba(148,163,184,0.25)', | |
| borderRadius: 14, padding: '14px 16px', boxShadow: '0 10px 30px rgba(0,0,0,0.4)', | |
| display: 'flex', alignItems: 'center', gap: 12, maxWidth: '92vw', | |
| color: '#e2e8f0', fontFamily: 'sans-serif', fontSize: 14, | |
| }} | |
| > | |
| <span> | |
| {needRefresh | |
| ? 'Uygulamanın eski sürümünü kullanıyorsunuz. Yeni bir sürüm mevcut.' | |
| : 'Uygulama çevrimdışı kullanıma hazır.'} | |
| </span> | |
| {needRefresh && ( | |
| <button | |
| onClick={() => updateServiceWorker(true)} | |
| style={{ | |
| background: '#2563eb', color: '#fff', border: 'none', borderRadius: 8, | |
| padding: '8px 14px', fontWeight: 600, cursor: 'pointer', whiteSpace: 'nowrap', | |
| }} | |
| > | |
| Güncelle | |
| </button> | |
| )} | |
| <button | |
| onClick={close} | |
| aria-label="Kapat" | |
| style={{ | |
| background: 'transparent', color: '#94a3b8', border: 'none', | |
| cursor: 'pointer', fontSize: 16, lineHeight: 1, padding: 4, | |
| }} | |
| > | |
| ✕ | |
| </button> | |
| </div> | |
| ) | |
| } | |