Merge pull request #753 from omnivore-app/fix/update-search-cache

Update SWR cache function to check search results
This commit is contained in:
Jackson Harper 2022-06-06 20:18:51 -07:00 committed by GitHub
commit 5223d28f6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -149,11 +149,11 @@ export const removeItemFromCache = (
try {
const mappedCache = cache as Map<string, unknown>
mappedCache.forEach((value: any, key) => {
if (typeof value == 'object' && 'articles' in value) {
const articles = value.articles as LibraryItems
const idx = articles.edges.findIndex((edge) => edge.node.id == itemId)
if (typeof value == 'object' && 'search' in value) {
const search = value.search as LibraryItems
const idx = search.edges.findIndex((edge) => edge.node.id == itemId)
if (idx > -1) {
value.articles.edges.splice(idx, 1)
value.search.edges.splice(idx, 1)
mutate(key, value, false)
}
}
@ -161,7 +161,7 @@ export const removeItemFromCache = (
mappedCache.forEach((value: any, key) => {
if (Array.isArray(value)) {
const idx = value.findIndex((item) => 'articles' in item)
const idx = value.findIndex((item) => 'search' in item)
if (idx > -1) {
mutate(key, value, false)
}