2020-05-12 23:14:08 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-05-21 17:15:08 +00:00
|
|
|
import {
|
|
|
|
Fragment,
|
|
|
|
Suspense,
|
|
|
|
lazy,
|
|
|
|
useState,
|
|
|
|
useRef,
|
|
|
|
useEffect,
|
|
|
|
} from '@wordpress/element';
|
2020-05-12 23:14:08 +00:00
|
|
|
import { Button } from '@wordpress/components';
|
2020-05-21 17:15:08 +00:00
|
|
|
import { compose } from '@wordpress/compose';
|
2020-05-12 23:14:08 +00:00
|
|
|
import classnames from 'classnames';
|
2020-05-21 17:15:08 +00:00
|
|
|
import { get } from 'lodash';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { Spinner } from '@woocommerce/components';
|
2020-05-12 23:14:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-05-19 13:16:19 +00:00
|
|
|
import QuickLinks from '../quick-links';
|
2020-05-12 23:14:08 +00:00
|
|
|
import StatsOverview from './stats-overview';
|
|
|
|
import './style.scss';
|
2020-05-21 17:15:08 +00:00
|
|
|
import { isOnboardingEnabled } from 'dashboard/utils';
|
|
|
|
import withSelect from 'wc-api/with-select';
|
|
|
|
import TaskListPlaceholder from '../task-list/placeholder';
|
2020-05-12 23:14:08 +00:00
|
|
|
|
2020-05-21 17:15:08 +00:00
|
|
|
const TaskList = lazy( () =>
|
|
|
|
import( /* webpackChunkName: "task-list" */ '../task-list' )
|
|
|
|
);
|
|
|
|
|
|
|
|
export const Layout = ( props ) => {
|
2020-05-12 23:14:08 +00:00
|
|
|
const [ showInbox, setShowInbox ] = useState( true );
|
|
|
|
const [ isContentSticky, setIsContentSticky ] = useState( false );
|
|
|
|
const content = useRef( null );
|
|
|
|
const maybeStickContent = () => {
|
|
|
|
if ( ! content.current ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const { bottom } = content.current.getBoundingClientRect();
|
|
|
|
const shouldBeSticky = showInbox && bottom < window.innerHeight;
|
|
|
|
|
|
|
|
setIsContentSticky( shouldBeSticky );
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect( () => {
|
|
|
|
maybeStickContent();
|
|
|
|
window.addEventListener( 'resize', maybeStickContent );
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
window.removeEventListener( 'resize', maybeStickContent );
|
|
|
|
};
|
|
|
|
}, [] );
|
|
|
|
|
2020-05-21 17:15:08 +00:00
|
|
|
const { query, requestingTaskList, taskListHidden } = props;
|
|
|
|
const isTaskListEnabled = taskListHidden === false;
|
|
|
|
const isDashboardShown = ! isTaskListEnabled || ! query.task;
|
|
|
|
|
|
|
|
const renderColumns = () => {
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
{ showInbox && (
|
|
|
|
<div className="woocommerce-homepage-column is-inbox">
|
|
|
|
<div className="temp-content">
|
|
|
|
<Button
|
|
|
|
isPrimary
|
|
|
|
onClick={ () => {
|
|
|
|
setShowInbox( false );
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
Dismiss All
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
<div className="temp-content" />
|
|
|
|
<div className="temp-content" />
|
|
|
|
<div className="temp-content" />
|
|
|
|
<div className="temp-content" />
|
|
|
|
<div className="temp-content" />
|
|
|
|
<div className="temp-content" />
|
|
|
|
</div>
|
|
|
|
) }
|
|
|
|
<div
|
|
|
|
className="woocommerce-homepage-column"
|
|
|
|
ref={ content }
|
|
|
|
style={ {
|
|
|
|
position: isContentSticky ? 'sticky' : 'static',
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
{ isTaskListEnabled && renderTaskList() }
|
|
|
|
<StatsOverview />
|
|
|
|
<QuickLinks />
|
|
|
|
</div>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderTaskList = () => {
|
|
|
|
if ( requestingTaskList ) {
|
|
|
|
return <TaskListPlaceholder />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Suspense fallback={ <Spinner /> }>
|
|
|
|
<TaskList
|
|
|
|
query={ query }
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
</Suspense>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-05-12 23:14:08 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={ classnames( 'woocommerce-homepage', {
|
|
|
|
hasInbox: showInbox,
|
|
|
|
} ) }
|
|
|
|
>
|
2020-05-21 17:15:08 +00:00
|
|
|
{ isDashboardShown
|
|
|
|
? renderColumns()
|
|
|
|
: isTaskListEnabled && renderTaskList()
|
|
|
|
}
|
2020-05-12 23:14:08 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-05-21 17:15:08 +00:00
|
|
|
Layout.propTypes = {
|
|
|
|
/**
|
|
|
|
* If the task list option is being fetched.
|
|
|
|
*/
|
|
|
|
requestingTaskList: PropTypes.bool.isRequired,
|
|
|
|
/**
|
|
|
|
* If the task list is hidden.
|
|
|
|
*/
|
|
|
|
taskListHidden: PropTypes.bool,
|
|
|
|
/**
|
|
|
|
* Page query, used to determine the current task if any.
|
|
|
|
*/
|
|
|
|
query: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withSelect( ( select ) => {
|
|
|
|
const {
|
|
|
|
getOptions,
|
|
|
|
isGetOptionsRequesting,
|
|
|
|
} = select( 'wc-api' );
|
|
|
|
|
|
|
|
if ( isOnboardingEnabled() ) {
|
|
|
|
const options = getOptions( [
|
|
|
|
'woocommerce_task_list_hidden',
|
|
|
|
] );
|
|
|
|
|
|
|
|
return {
|
|
|
|
requestingTaskList: isGetOptionsRequesting( [
|
|
|
|
'woocommerce_task_list_hidden',
|
|
|
|
] ),
|
|
|
|
taskListHidden: get( options, [ 'woocommerce_task_list_hidden' ] ) === 'yes',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
requestingTaskList: false,
|
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( Layout );
|