From 38584446f76f5c26c617d67384d66c15c40952ef Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 3 Jun 2022 14:54:52 -0700 Subject: [PATCH] Update SWR cache function to check search results Since switching from the articles API to the search API we haven't been correctly removing items from the cache when archived/unarchived. --- .../web/lib/networking/queries/useGetArticleQuery.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/web/lib/networking/queries/useGetArticleQuery.tsx b/packages/web/lib/networking/queries/useGetArticleQuery.tsx index 3c318ba15..3aab97174 100644 --- a/packages/web/lib/networking/queries/useGetArticleQuery.tsx +++ b/packages/web/lib/networking/queries/useGetArticleQuery.tsx @@ -149,11 +149,11 @@ export const removeItemFromCache = ( try { const mappedCache = cache as Map 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) }