From ac557e1271175a9f8d48b9af4100d5d162426034 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Fri, 6 Jan 2023 21:29:16 +0800 Subject: [PATCH] Delete cache in SW before reloading status page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Seems kinda hacky… probably might cause new side effects --- src/pages/status.jsx | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/pages/status.jsx b/src/pages/status.jsx index ef0b868b..d6d065ed 100644 --- a/src/pages/status.jsx +++ b/src/pages/status.jsx @@ -55,7 +55,7 @@ function StatusPage({ id }) { }; }, [id]); - useEffect(() => { + const initContext = () => { setUIState('loading'); let heroTimer; @@ -174,7 +174,30 @@ function StatusPage({ id }) { return () => { clearTimeout(heroTimer); }; - }, [id, snapStates.reloadStatusPage]); + }; + + useEffect(initContext, [id]); + + useEffect(() => { + // Delete the cache for the context + (async () => { + try { + const accounts = store.local.getJSON('accounts') || []; + const currentAccount = store.session.get('currentAccount'); + const account = + accounts.find((a) => a.info.id === currentAccount) || accounts[0]; + const instanceURL = account.instanceURL; + const contextURL = `https://${instanceURL}/api/v1/statuses/${id}/context`; + console.log('Clear cache', contextURL); + const apiCache = await caches.open('api'); + await apiCache.delete(contextURL, { ignoreVary: true }); + + return initContext(); + } catch (e) { + console.error(e); + } + })(); + }, [snapStates.reloadStatusPage]); const firstLoad = useRef(true);