import { Config , Pjax } from 'pjax-api' ; import { platform } from 'platforms' ; import * as React from 'react' ; import { useEvent } from 'react-use' ; const config = { areas : [ '.repository-content' , '#git-project-content' , '.repository > .ui.container' , ] , update : { css : false , } , fetch : { cache ( path ) { return path ; } , } , link : 'a:not(a)' , form : 'form:not(form)' , fallback ( target , reason ) { } , } ; export function usePJAX ( ) { React . useEffect ( ( ) => { new Pjax ( { ... config , filter ( ) { return false ; } , } ) ; } , [ ] ) ; useRedirectedEvents ( window , 'pjax:fetch' , 'pjax:start' , document ) ; useRedirectedEvents ( document , 'pjax:ready' , 'pjax:end' ) ; } export const loadWithPJAX = ( url , element ) => { if ( platform . loadWithPJAX ) platform . loadWithPJAX ( url , element ) ; else Pjax . assign ( url , config ) ; } ; export function useOnPJAXDone ( callback ) { useEvent ( 'pjax:end' , callback , document ) ; } export function useRedirectedEvents ( originalTarget , originalEvent , redirectedEvent , redirectToTarget = originalTarget ) { useEvent ( originalEvent , ( ) => { redirectToTarget . dispatchEvent ( new Event ( redirectedEvent ) ) ; } , originalTarget ) ; }