Auto update admin page and better cached status for files

This commit is contained in:
2026-03-18 14:35:14 +01:00 Verified
parent 83de05505c
commit 99ff2f94b4
3 changed files with 54 additions and 26 deletions
+21 -8
View File
@@ -2,7 +2,7 @@
"use client";
import { BookCopy, CheckCircle, CloudDownload, Folder, Loader2, Map, MapPinned, MapPlus, WavesLadder, WifiOff } from 'lucide-react';
import { BookCopy, CheckCircle, CloudDownload, Folder, Loader2, Map, MapPinned, MapPlus, WavesLadder } from 'lucide-react';
import { useEffect, useState } from 'react';
import { DocumentCard, ExternalLinkCard, DocumentItem, LinkItem } from '../components/ui/Cards';
import { OfflineBadge } from '../components/ui/OfflineBadge';
@@ -70,15 +70,28 @@ export default function Documents() {
const handleSyncAll = async () => {
setSyncStatus('syncing');
const updatedCache = new Set(cachedFiles);
for (const doc of docs) {
try { await fetch(doc.file); } catch (error) { console.error("Kunde inte ladda ner:", doc.file); }
try {
const response = await fetch(doc.file);
if (response.ok) {
updatedCache.add(doc.file);
setCachedFiles(new Set(updatedCache));
}
} catch (error) {
console.error("Kunde inte ladda ner:", doc.file);
}
}
await checkCacheStatus();
setSyncStatus('done');
setShowNotification(true);
setTimeout(() => {
setShowNotification(false);
}, 4000);
setTimeout(async () => {
await checkCacheStatus();
setSyncStatus('done');
setShowNotification(true);
setTimeout(() => {
setShowNotification(false);
}, 4000);
}, 500);
};
if (!isHydrated) return <div className="flex justify-center py-20"><Loader2 className="animate-spin text-slate-teal" size={40} /></div>;