import React , { createContext , useContext } from 'react' ; import { ApiService } from '../../../../lib/api' ; import { useReindexStatus , ReindexState } from './use_reindex_state' ; export interface ReindexStateContext { reindexState : ReindexState ; startReindex : ( ) => Promise < void > ; cancelReindex : ( ) => Promise < void > ; } const ReindexContext = createContext < ReindexStateContext | undefined > ( undefined ) ; export const useReindexContext = ( ) => { const context = useContext ( ReindexContext ) ; if ( context === undefined ) { throw new Error ( 'useReindexContext must be used within a <ReindexStatusProvider />' ) ; } return context ; } ; interface Props { api : ApiService ; children : React . ReactNode ; indexName : string ; } export const ReindexStatusProvider = ( { api , indexName , children , } ) => { const { reindexState , startReindex , cancelReindex } = useReindexStatus ( { indexName , api , } ) ; return ( < ReindexContext . Provider value = { { reindexState , startReindex , cancelReindex , } } > { children } < /ReindexContext.Provider>); } ;