From d22eb70cc69bcb252c405703dfdea3db79c31cdc Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 12 Oct 2021 04:16:13 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=94=20Document=20`context/cache`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/contexts/cache.tsx | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/frontend/src/contexts/cache.tsx b/frontend/src/contexts/cache.tsx index f24c826..8d9e77b 100644 --- a/frontend/src/contexts/cache.tsx +++ b/frontend/src/contexts/cache.tsx @@ -3,30 +3,37 @@ import {ManagedViewSet, useManagedViewSet} from "../hooks/useManagedViewSet" import {WithChildren} from "../types/ExtraTypes" import {SophonUser} from "../types/SophonTypes" -// States +/** + * The contents of the {@link cacheContext}. + */ type Cache = { users?: ManagedViewSet, } -// Actions - const cacheContext = React.createContext({}) const CacheContext = cacheContext -// Hooks - +/** + * Hook to access the {@link cacheContext}. + */ export function useCacheContext(): Cache { return React.useContext(cacheContext) } -// Components - +/** + * A provider for {@link cacheContext} which fetches some resources from the Sophon instance and caches them for future use. + * + * For example, one of the stored resources is the list of all users, which is later used to map user ids to usernames. + * + * @param children + * @constructor + */ export function CacheProvider({children}: WithChildren): JSX.Element { const users = useManagedViewSet("/api/core/users/", "id") return -} \ No newline at end of file +}