diff options
Diffstat (limited to 'packages/demobank-ui/src/hooks/backend.ts')
-rw-r--r-- | packages/demobank-ui/src/hooks/backend.ts | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/packages/demobank-ui/src/hooks/backend.ts b/packages/demobank-ui/src/hooks/backend.ts index 863b47bf3..46918ac10 100644 --- a/packages/demobank-ui/src/hooks/backend.ts +++ b/packages/demobank-ui/src/hooks/backend.ts @@ -19,16 +19,15 @@ import { Codec, buildCodecForObject, buildCodecForUnion, - canonicalizeBaseUrl, codecForBoolean, codecForConstString, - codecForString, + codecForString } from "@gnu-taler/taler-util"; import { buildStorageKey, useLocalStorage } from "@gnu-taler/web-util/browser"; -import { useSWRConfig } from "swr"; +import { mutate } from "swr"; /** * Has the information to reach and @@ -105,7 +104,6 @@ export function useBackendState(): BackendStateHandler { BACKEND_STATE_KEY, defaultState, ); - const mutateAll = useMatchMutate(); return { state, @@ -129,29 +127,11 @@ export function useBackendState(): BackendStateHandler { isUserAdministrator: info.username === "admin", }; update(nextState); - mutateAll(/.*/) + cleanAllCache() }, }; } -export function useMatchMutate(): ( - re: RegExp, - value?: unknown, -) => Promise<any> { - const { cache, mutate } = useSWRConfig(); - - if (!(cache instanceof Map)) { - throw new Error( - "matchMutate requires the cache provider to be a Map instance", - ); - } - - return function matchRegexMutate(re: RegExp, value?: unknown) { - const allKeys = Array.from(cache.keys()); - const keys = allKeys.filter((key) => re.test(key)); - const mutations = keys.map((key) => { - return mutate(key, value, true); - }); - return Promise.all(mutations); - }; +function cleanAllCache(): void { + mutate(() => true, undefined, { revalidate: false }) } |