import { createContext, useContext } from 'react' import { NextPage, PaginationData, usePagination } from 'hooks/usePagination' import { useAuthentication } from 'utils/authentication' export interface Guild { id: number name: string description: string icon: string isPublic: boolean createdAt: string updatedAt: string } interface PaginationGuild { id: number isOwner: boolean lastVisitedChannelId: number userId: number guildId: number createdAt: string updatedAt: string guild: Guild } export type Guilds = PaginationData export interface GuildsValue { guilds: Guilds nextPage: NextPage } export interface GuildsProviderProps { guilds: Guilds } const defaultGuildsContext: GuildsValue = {} as any const GuildsContext = createContext(defaultGuildsContext) export const GuildsProvider: React.FC = (props) => { const { authentication } = useAuthentication() const { data: guilds, nextPage } = usePagination({ api: authentication.api, url: '/guilds', defaultPaginationData: props.guilds }) return ( {props.children} ) } export const useGuilds = (): GuildsValue => { return useContext(GuildsContext) }