1
Fork 0
mirror of https://github.com/Steffo99/sophon.git synced 2024-12-23 07:14:21 +00:00

📔 Document context/cache

This commit is contained in:
Steffo 2021-10-12 04:16:13 +02:00
parent 264d97bbe5
commit d22eb70cc6
Signed by: steffo
GPG key ID: 6965406171929D01

View file

@ -3,28 +3,35 @@ 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<SophonUser>,
}
// Actions
const cacheContext = React.createContext<Cache>({})
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<SophonUser>("/api/core/users/", "id")