"use client"; import React, { createContext, useContext, FC, PropsWithChildren } from "react"; import { useAccount } from "../hooks/account"; const defaultAccount = { activeSubscription: false, authed: false, email: "", jwt: "", role: 0, }; const AppContext = createContext({ account: defaultAccount, setAccountType: (_x: typeof defaultAccount) => {}, onLogout: () => {}, }); const A11yWatchProviderBase = AppContext.Provider; type A11yWatchProps = { persist?: boolean }; const A11yWatchProviderWrapper: FC> = ({ children, persist, }) => { const state = useAccount(persist); return ( {children} ); }; /** * Top level app provider. Wrap this around the entire app. * @param children children to render * @param persist persist values with restore and refresh * @example Example of using the provider * function Application(){ * return ; * } * @returns {React.FC>} Returns the top level provider for the app. */ export const A11yWatchProvider: FC> = ({ children, persist, }) => { return ( {children} ); }; /** * Top level app provider hook. * @example Example of using the hook * function App() { * const { account } = useA11yWatchContext() * * return
{account.email}
* } * function Application(){ * return ; * } * @returns {{ account: Account, setAccountType }} Returns a hook of the top level provider to manage account state. */ export function useA11yWatchContext() { return useContext(AppContext); }