Skip to content

Commit

Permalink
fix: only return sections with cached data from getCachedSections
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVandivier committed Aug 23, 2021
1 parent ee2a7f5 commit f6242d1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pwa/src/offline-interface/offline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,21 @@ export class OfflineInterface {
throw new Error(
'Cannot get cached sections - PWA is not enabled in d2.config.js'
)

await navigator.serviceWorker.ready
if (this.dbPromise === undefined) {
this.dbPromise = openSectionsDB()
}
const db = await this.dbPromise
return db.getAll(SECTIONS_STORE)

const sections = await db.getAll(SECTIONS_STORE)
const cacheKeys = await caches.keys()
// Validate that each section in IDB has cached data
const validSections = sections.filter(section =>
cacheKeys.includes(section.sectionId)
)

return validSections
}

/**
Expand All @@ -198,6 +207,7 @@ export class OfflineInterface {
if (this.dbPromise === undefined) {
this.dbPromise = openSectionsDB()
}
// todo: feedback if one but not the other is removed
return Promise.all([
caches.delete(sectionId),
(await this.dbPromise).delete(SECTIONS_STORE, sectionId),
Expand Down

0 comments on commit f6242d1

Please sign in to comment.