2024-03-18 07:44:32 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { useMachine } from '@xstate5/react';
|
2024-05-22 22:05:01 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2024-05-31 03:49:36 +00:00
|
|
|
import clsx from 'clsx';
|
2024-03-26 02:28:51 +00:00
|
|
|
|
2024-03-18 07:44:32 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { useFullScreen } from '~/utils';
|
|
|
|
import { useComponentFromXStateService } from '~/utils/xstate/useComponentFromService';
|
|
|
|
|
|
|
|
import './styles.scss';
|
|
|
|
import {
|
|
|
|
SidebarMachineEvents,
|
|
|
|
sidebarMachine,
|
|
|
|
SidebarComponentProps,
|
|
|
|
SidebarContainer,
|
|
|
|
} from './sidebar/xstate';
|
|
|
|
import {
|
|
|
|
MainContentMachineEvents,
|
|
|
|
mainContentMachine,
|
|
|
|
MainContentComponentProps,
|
|
|
|
MainContentContainer,
|
|
|
|
} from './main-content/xstate';
|
2024-03-26 02:28:51 +00:00
|
|
|
import { useXStateInspect } from '~/xstate';
|
2024-03-18 07:44:32 +00:00
|
|
|
|
|
|
|
export type LaunchYourStoreComponentProps = {
|
|
|
|
sendEventToSidebar: ( arg0: SidebarMachineEvents ) => void;
|
|
|
|
sendEventToMainContent: ( arg0: MainContentMachineEvents ) => void;
|
|
|
|
className?: string;
|
|
|
|
};
|
2024-03-26 02:28:51 +00:00
|
|
|
|
2024-03-18 07:44:32 +00:00
|
|
|
const LaunchStoreController = () => {
|
|
|
|
useFullScreen( [ 'woocommerce-launch-your-store' ] );
|
2024-05-22 22:05:01 +00:00
|
|
|
useEffect( () => {
|
|
|
|
window.sessionStorage.setItem( 'lysWaiting', 'no' );
|
|
|
|
}, [] );
|
2024-03-26 02:28:51 +00:00
|
|
|
const { xstateV5Inspector: inspect } = useXStateInspect( 'V5' );
|
2024-03-18 07:44:32 +00:00
|
|
|
|
|
|
|
const [ mainContentState, sendToMainContent, mainContentMachineService ] =
|
2024-03-26 02:28:51 +00:00
|
|
|
useMachine( mainContentMachine, {
|
|
|
|
inspect,
|
|
|
|
} );
|
2024-03-18 07:44:32 +00:00
|
|
|
|
|
|
|
const [ sidebarState, sendToSidebar, sidebarMachineService ] = useMachine(
|
|
|
|
sidebarMachine,
|
|
|
|
{
|
2024-03-26 02:28:51 +00:00
|
|
|
inspect,
|
2024-03-18 07:44:32 +00:00
|
|
|
input: {
|
|
|
|
mainContentMachineRef: mainContentMachineService,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const isSidebarVisible = ! sidebarState.hasTag( 'fullscreen' );
|
|
|
|
|
|
|
|
const [ CurrentSidebarComponent ] =
|
|
|
|
useComponentFromXStateService< SidebarComponentProps >(
|
|
|
|
sidebarMachineService
|
|
|
|
);
|
|
|
|
|
|
|
|
const [ CurrentMainContentComponent ] =
|
|
|
|
useComponentFromXStateService< MainContentComponentProps >(
|
|
|
|
mainContentMachineService
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={ 'launch-your-store-layout__container' }>
|
|
|
|
<SidebarContainer
|
2024-05-31 03:49:36 +00:00
|
|
|
className={ clsx( {
|
2024-03-18 07:44:32 +00:00
|
|
|
'is-sidebar-hidden': ! isSidebarVisible,
|
|
|
|
} ) }
|
|
|
|
>
|
|
|
|
{ CurrentSidebarComponent && (
|
|
|
|
<CurrentSidebarComponent
|
|
|
|
sendEventToSidebar={ sendToSidebar }
|
|
|
|
sendEventToMainContent={ sendToMainContent }
|
|
|
|
context={ sidebarState.context }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
</SidebarContainer>
|
|
|
|
<MainContentContainer>
|
|
|
|
{ CurrentMainContentComponent && (
|
|
|
|
<CurrentMainContentComponent
|
|
|
|
sendEventToSidebar={ sendToSidebar }
|
|
|
|
sendEventToMainContent={ sendToMainContent }
|
|
|
|
context={ mainContentState.context }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
</MainContentContainer>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
export default LaunchStoreController;
|