diff --git a/app/documents/page.tsx b/app/documents/page.tsx index d83b404..b48ee07 100644 --- a/app/documents/page.tsx +++ b/app/documents/page.tsx @@ -1,15 +1,23 @@ // app/documents/page.tsx -import { BookCopy, Download, ExternalLink, Folder, Map, MapPinned, MapPlus, WavesLadder } from 'lucide-react'; +"use client"; + +import { BookCopy, CheckCircle, CloudDownload, Download, ExternalLink, Folder, Loader2, Map, MapPinned, MapPlus, WavesLadder, WifiOff, Archive } from 'lucide-react'; +import { useEffect, useState } from 'react'; export default function Documents() { + const [isHydrated, setIsHydrated] = useState(false); + const [isOffline, setIsOffline] = useState(false); + const [syncStatus, setSyncStatus] = useState<'idle' | 'syncing' | 'done'>('idle'); + const [cachedFiles, setCachedFiles] = useState>(new Set()); + const docs = [ { title: 'Turistkarta', icon: , file: '/files/Turistkarta - Kullaberg.pdf', size: '2.51 MB' }, - { title: 'Orienteringskarta', icon: , file: '/files/Orienteringskarta - Kullaberg.pdf', size: '7.23 MB' }, - { title: 'Badplatser att besöka', icon: , file: '/files/Badplatser på Kullaberg.pdf', size: '7.07 MB' }, + { title: 'Orienteringskarta', icon: , file: '/files/Orienteringskarta - Kullaberg.pdf', size: '3.74 MB' }, + { title: 'Badplatser att besöka', icon: , file: '/files/Badplatser på Kullaberg.pdf', size: '1.88 MB' }, { title: 'Vandringsrutter', icon: , file: '/files/Vandringsrutter.pdf', size: '4.42 MB' }, - { title: 'Underlag för guidediplomering', icon: , file: '/files/Underlag för guidediplomering.pptx', size: '3.83 MB' }, - { title: 'Destinationskunskap Kullahalvön', icon: , file: '/files/Destinationskunskap 2026.pptx', size: '24.2 MB' } + { title: 'Underlag för guidediplomering', icon: , file: '/files/Underlag för guidediplomering.pdf', size: '3.18 MB' }, + { title: 'Destinationskunskap Kullahalvön', icon: , file: '/files/Destinationskunskap.pdf', size: '1.97 MB' } ]; const links = [ @@ -20,50 +28,155 @@ export default function Documents() { { title: 'Väderprognos Mölle', url: 'https://www.smhi.se/vader/prognoser-och-varningar/vaderprognos/q/H%C3%B6gan%C3%A4s/M%C3%B6lle/2691501' } ]; + const checkCacheStatus = async () => { + if (!('caches' in window)) return; + const cached = new Set(); + try { + for (const doc of docs) { + const response = await caches.match(doc.file); + if (response) cached.add(doc.file); + } + setCachedFiles(cached); + if (cached.size === docs.length) setSyncStatus('done'); + } catch (error) { + console.error("Cache check failed", error); + } + }; + + useEffect(() => { + setIsHydrated(true); + setIsOffline(!navigator.onLine); + + const handleStatus = () => setIsOffline(!navigator.onLine); + window.addEventListener('online', handleStatus); + window.addEventListener('offline', handleStatus); + + checkCacheStatus(); + + const conn = (navigator as any).connection; + if (conn && (conn.type === 'wifi' || conn.type === 'ethernet') && !conn.saveData) { + handleSyncAll(); + } + + return () => { + window.removeEventListener('online', handleStatus); + window.removeEventListener('offline', handleStatus); + }; + }, []); + + const handleSyncAll = async () => { + setSyncStatus('syncing'); + for (const doc of docs) { + try { + await fetch(doc.file); + } catch (error) { + console.error("Kunde inte ladda ner:", doc.file); + } + } + await checkCacheStatus(); + setSyncStatus('done'); + }; + + if (!isHydrated) { + return ( +
+ +
+ ); + } + return (
-
-

- - Info & Dokument -

-

Allt du behöver för att guida besökarna.

+
+
+

+ + Info & Dokument +

+

Allt du behöver för att guida besökarna.

+
+ +
+ {isOffline && ( +
+ Offline-läge +
+ )} + + {!isOffline && syncStatus !== 'done' && ( + + )} + + {syncStatus === 'done' && ( +
+ Redo för offline +
+ )} +

Nedladdningar

-

Användbara Länkar

+

+ {isOffline ? "Användbara Länkar (Kräver anslutning)" : "Användbara Länkar"} +

{links.map((link, idx) => ( - {link.title} -
- +
+
))} @@ -71,4 +184,4 @@ export default function Documents() {
); -}; \ No newline at end of file +} \ No newline at end of file diff --git a/app/sw.ts b/app/sw.ts index c404a02..3093812 100644 --- a/app/sw.ts +++ b/app/sw.ts @@ -21,19 +21,10 @@ const serwist = new Serwist({ runtimeCaching: [ { matcher: ({ url }) => url.pathname.startsWith("/files/"), - handler: async ({ request, event }) => { - const conn = navigator.connection; - const isStrictWifi = conn && (conn.type === 'wifi' || conn.type === 'ethernet'); - const shouldCache = isStrictWifi && !conn?.saveData; - if (shouldCache) { - const cacheStrategy = new CacheFirst({ - cacheName: "kullaberg-files-cache", - plugins: [new ExpirationPlugin({ maxEntries: 20, maxAgeSeconds: 2592000 })], - }); - return cacheStrategy.handle({ request, event }); - } - return fetch(request); - } + handler: new CacheFirst({ + cacheName: "kullaberg-files-cache", + plugins: [new ExpirationPlugin({ maxEntries: 20, maxAgeSeconds: 2592000 })], + }) }, ...defaultCache, ], diff --git a/next.config.ts b/next.config.ts index 4a8acec..fa95487 100644 --- a/next.config.ts +++ b/next.config.ts @@ -12,8 +12,10 @@ const withSerwist = withSerwistInit({ cacheOnNavigation: true, additionalPrecacheEntries: [ { url: "/", revision: manualRevision }, - { url: "/emergency", revision: manualRevision }, + { url: "/schedule", revision: manualRevision }, { url: "/faq", revision: manualRevision }, + { url: "/info", revision: manualRevision }, + { url: "/emergency", revision: manualRevision }, ], }); diff --git a/public/files/Badplatser på Kullaberg.pdf b/public/files/Badplatser på Kullaberg.pdf deleted file mode 100644 index 5f431aa..0000000 Binary files a/public/files/Badplatser på Kullaberg.pdf and /dev/null differ diff --git a/public/files/Badplatser på Kullaberge.pdf b/public/files/Badplatser på Kullaberge.pdf new file mode 100644 index 0000000..feada97 Binary files /dev/null and b/public/files/Badplatser på Kullaberge.pdf differ diff --git a/public/files/Destinationskunskap 2026.pptx b/public/files/Destinationskunskap 2026.pptx deleted file mode 100644 index cbcc397..0000000 Binary files a/public/files/Destinationskunskap 2026.pptx and /dev/null differ diff --git a/public/files/Destinationskunskap.pdf b/public/files/Destinationskunskap.pdf new file mode 100644 index 0000000..3edc6c5 Binary files /dev/null and b/public/files/Destinationskunskap.pdf differ diff --git a/public/files/Orienteringskarta - Kullaberg.pdf b/public/files/Orienteringskarta - Kullaberg.pdf index c906afa..732ac7e 100644 Binary files a/public/files/Orienteringskarta - Kullaberg.pdf and b/public/files/Orienteringskarta - Kullaberg.pdf differ diff --git a/public/files/Underlag för guidediplomering.pdf b/public/files/Underlag för guidediplomering.pdf new file mode 100644 index 0000000..26cbb5d Binary files /dev/null and b/public/files/Underlag för guidediplomering.pdf differ diff --git a/public/files/Underlag för guidediplomering.pptx b/public/files/Underlag för guidediplomering.pptx deleted file mode 100644 index e773609..0000000 Binary files a/public/files/Underlag för guidediplomering.pptx and /dev/null differ