MCPcopy Create free account
hub / github.com/Botloader/botloader / GuildsProvider

Function GuildsProvider

frontend/src/modules/guilds/GuildsProvider.tsx:8–32  ·  view source on GitHub ↗
({ children }: { children: React.ReactNode })

Source from the content-addressed store, hash-verified

6export const GuildsContext = createFetchDataContext<LoadedGuilds>();
7
8export function GuildsProvider({ children }: { children: React.ReactNode }) {
9 const session = useSession();
10
11 const fetch = useCallback(async () => {
12 if (!session.user) {
13 return undefined
14 }
15
16 const resp = await session.apiClient.getCurrentUserGuilds();
17 if (isErrorResponse(resp)) {
18 return resp
19 }
20
21 const adminGuilds = resp.guilds.filter((g) => userGuildHasAdmin(g.guild));
22
23 return {
24 all: resp.guilds,
25 hasAdmin: adminGuilds,
26 }
27 }, [session])
28
29 return <FetchData loader={fetch} context={GuildsContext} debugName="guilds">
30 {children}
31 </FetchData>
32}
33
34export function GuildsGuard({ children }: { children: React.ReactNode }) {
35 return <FetchDataGuard context={GuildsContext}>{children}</FetchDataGuard>

Callers

nothing calls this directly

Calls 4

useSessionFunction · 0.90
isErrorResponseFunction · 0.85
userGuildHasAdminFunction · 0.85
getCurrentUserGuildsMethod · 0.80

Tested by

no test coverage detected