/**
* External dependencies
*/
import {
Suspense,
lazy,
useCallback,
useLayoutEffect,
useRef,
useState,
} from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { withDispatch, withSelect } from '@wordpress/data';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import {
useUserPreferences,
NOTES_STORE_NAME,
OPTIONS_STORE_NAME,
} from '@woocommerce/data';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import StatsOverview from './stats-overview';
import TaskListPlaceholder from '../task-list/placeholder';
import InboxPanel from '../inbox-panel';
import { WelcomeModal } from './welcome-modal';
import ActivityHeader from '../header/activity-panel/activity-header';
import { ActivityPanel } from './activity-panel';
import './style.scss';
import '../dashboard/style.scss';
import { StoreManagementLinks } from '../store-management-links';
import { Column } from './column';
const TaskList = lazy( () =>
import( /* webpackChunkName: "task-list" */ '../task-list' )
);
export const Layout = ( {
defaultHomescreenLayout,
isBatchUpdating,
query,
requestingTaskList,
taskListHidden,
shouldShowWelcomeModal,
updateOptions,
} ) => {
const userPrefs = useUserPreferences();
const twoColumns =
( userPrefs.homepage_layout || defaultHomescreenLayout ) ===
'two_columns';
const [ showInbox, setShowInbox ] = useState( true );
const isTaskListEnabled = taskListHidden === false;
const isDashboardShown = ! isTaskListEnabled || ! query.task;
if ( isBatchUpdating && ! showInbox ) {
setShowInbox( true );
}
const isWideViewport = useRef( true );
const maybeToggleColumns = useCallback( () => {
isWideViewport.current = window.innerWidth >= 782;
}, [] );
useLayoutEffect( () => {
maybeToggleColumns();
window.addEventListener( 'resize', maybeToggleColumns );
return () => {
window.removeEventListener( 'resize', maybeToggleColumns );
};
}, [ maybeToggleColumns ] );
const shouldStickColumns = isWideViewport.current && twoColumns;
const renderColumns = () => {
return (
<>