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:
parent
264d97bbe5
commit
d22eb70cc6
1 changed files with 15 additions and 8 deletions
|
@ -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")
|
||||
|
||||
|
|
Loading…
Reference in a new issue