fix: restrict PWA cache and report actual offline capabilities
This commit is contained in:
@@ -10,18 +10,26 @@ export const PwaSettings = () => {
|
||||
// Gerçek Cache API sayımı — sahte "102 ihale önbellekte" yerine
|
||||
const [onbellekSayisi, setOnbellekSayisi] = useState(null);
|
||||
const [onbellekAdi, setOnbellekAdi] = useState('');
|
||||
const [cacheLoading, setCacheLoading] = useState(false);
|
||||
const [cacheError, setCacheError] = useState(null);
|
||||
const [online, setOnline] = useState(navigator.onLine);
|
||||
const refreshCacheStatus = async () => {
|
||||
setCacheLoading(true); setCacheError(null);
|
||||
try {
|
||||
if (!('caches' in window)) throw new Error('Bu tarayıcı uygulama önbelleğini desteklemiyor.');
|
||||
const adlar = (await caches.keys()).filter(name => name.startsWith('ihaleist-'));
|
||||
let toplam = 0;
|
||||
for (const ad of adlar) toplam += (await (await caches.open(ad)).keys()).length;
|
||||
setOnbellekSayisi(toplam); setOnbellekAdi(adlar.join(', '));
|
||||
} catch (error) { setCacheError(error.message); setOnbellekSayisi(null); }
|
||||
finally { setCacheLoading(false); }
|
||||
};
|
||||
useEffect(() => { refreshCacheStatus(); }, []);
|
||||
useEffect(() => {
|
||||
if (!('caches' in window)) return;
|
||||
(async () => {
|
||||
try {
|
||||
const adlar = await caches.keys();
|
||||
let toplam = 0;
|
||||
for (const ad of adlar) toplam += (await (await caches.open(ad)).keys()).length;
|
||||
setOnbellekSayisi(toplam); setOnbellekAdi(adlar[adlar.length - 1] || '');
|
||||
} catch { setOnbellekSayisi(null); }
|
||||
})();
|
||||
const changed = () => setOnline(navigator.onLine);
|
||||
window.addEventListener('online', changed); window.addEventListener('offline', changed);
|
||||
return () => { window.removeEventListener('online', changed); window.removeEventListener('offline', changed); };
|
||||
}, []);
|
||||
const [offlineMode, setOfflineMode] = useState(true);
|
||||
const [installed, setInstalled] = useState(false);
|
||||
const [permission, setPermission] = useState(typeof Notification !== 'undefined' ? Notification.permission : 'unsupported');
|
||||
|
||||
@@ -105,8 +113,8 @@ export const PwaSettings = () => {
|
||||
<Smartphone className="w-6 h-6" />
|
||||
</div>
|
||||
<div>
|
||||
<h2 className="font-extrabold text-xl">Mobil PWA & Saha Ekibi Offline Modu</h2>
|
||||
<p className="text-xs text-cyan-200 mt-0.5">Saha satış temsilcileriniz için internet bağlantısı olmadığında dahi çevrimdışı çalışma ve anlık push bildirimi.</p>
|
||||
<h2 className="font-extrabold text-xl">Mobil uygulama ve bağlantı durumu</h2>
|
||||
<p className="text-xs text-cyan-200 mt-0.5">Uygulama kabuğu önbellekten açılabilir. İhale güncelleme, belge erişimi ve hazırlık kaydı için internet bağlantısı gerekir.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -118,10 +126,10 @@ export const PwaSettings = () => {
|
||||
<div className="bg-white p-6 rounded-2xl border border-slate-200 shadow-xs space-y-4">
|
||||
<div className="flex items-center justify-between border-b border-slate-100 pb-3">
|
||||
<h3 className="font-extrabold text-sm text-slate-900 flex items-center gap-2">
|
||||
{offlineMode ? <Wifi className="w-4 h-4 text-emerald-600" /> : <WifiOff className="w-4 h-4 text-slate-400" />} Çevrimdışı (Offline) Önbellek
|
||||
{online ? <Wifi className="w-4 h-4 text-emerald-600" /> : <WifiOff className="w-4 h-4 text-slate-400" />} Çevrimdışı (Offline) Önbellek
|
||||
</h3>
|
||||
<span className="bg-emerald-100 text-emerald-800 font-extrabold text-[10px] px-2 py-0.5 rounded-full">
|
||||
Senkronize
|
||||
{online ? 'Bağlantı var' : 'Çevrimdışı'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -141,11 +149,13 @@ export const PwaSettings = () => {
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={() => setOfflineMode(!offlineMode)}
|
||||
onClick={refreshCacheStatus} disabled={cacheLoading}
|
||||
className="w-full bg-slate-100 hover:bg-slate-200 text-slate-800 font-bold text-xs py-2.5 rounded-xl border border-slate-200 transition-colors"
|
||||
>
|
||||
{offlineMode ? 'Çevrimdışı Önbelleği Yenile' : 'Çevrimdışı Modu Aktif Et'}
|
||||
{cacheLoading ? 'Kontrol ediliyor…' : 'Önbellek durumunu kontrol et'}
|
||||
</button>
|
||||
{cacheError && <p role="alert" className="text-xs text-red-700">{cacheError}</p>}
|
||||
<p className="text-xs text-slate-600">Bağlantı durumu sunucuya erişimi garanti etmez. Çevrimdışı değişiklikler otomatik gönderim kuyruğuna alınmaz; kayıt sonucunu kontrol edin.</p>
|
||||
</div>
|
||||
|
||||
{/* Gerçek Tarayıcı Bildirimleri + Sessiz Saatler */}
|
||||
|
||||
Reference in New Issue
Block a user