import { useRef, createElement, Component } from '@wordpress/element' import DashboardContext, { Provider, getDefaultValue } from './context' import Heading from './Heading' import { Router, Link, Match, Location, LocationProvider, navigate, createHistory, } from '@reach/router' import ctEvents from 'ct-events' import { Transition, animated } from 'react-spring' window.ctDashboardLocalizations.DashboardContext = DashboardContext import Navigation from './Navigation' import Home from './screens/Home' import RecommendedPlugins from './screens/RecommendedPlugins' import Changelog from './screens/Changelog' import windowHashSource from './window-hash-source' let history = createHistory(windowHashSource()) let previousLocation = { pathname: location.hash.replace('#', '') || '/', } history.listen(({ location }) => { setTimeout(() => { previousLocation = location }, 10) }) const SpringRouter = ({ children }) => { const transitionRef = useRef() return ( {({ location, navigate, ...rest }) => { const nonAnimatedChildren = (location) => ( {children} ) return ( location.pathname} from={{ opacity: 0 }} enter={[{ opacity: 1 }]} leave={[{ opacity: 0 }]} config={(key, phase) => { const isImmediate = previousLocation && previousLocation.pathname.indexOf( 'extensions' ) > -1 && location.pathname.indexOf('extensions') > -1 return phase === 'leave' ? { duration: isImmediate ? 0 : 300, } : { delay: isImmediate ? 0 : 300, duration: isImmediate ? 0 : 300, } }}> {(props, location) => { return ( {nonAnimatedChildren(location)} ) }} ) }} ) } const FadeTransitionRouter = (props) => ( {({ location }) => ( {/* the only difference between a router animation and any other animation is that you have to pass the location to the router so the old screen renders the "old location" */} {props.children} )} ) export default class Dashboard extends Component { render() { const userRoutes = [] ctEvents.trigger('ct:dashboard:routes', userRoutes) return (
{userRoutes.map( ({ Component, key, path, ...props }) => ( ) )}
) } }