woocommerce/plugins/woocommerce-admin/client/homescreen/index.tsx

65 lines
1.5 KiB
TypeScript
Raw Normal View History

/**
* External dependencies
*/
import { compose } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import {
ONBOARDING_STORE_NAME,
withOnboardingHydration,
WCDataSelector,
} from '@woocommerce/data';
import { getHistory, getNewPath, useQuery } from '@woocommerce/navigation';
/**
* Internal dependencies
*/
import Layout from './layout';
import { getAdminSetting } from '~/utils/admin-settings';
Use Route based code splitting to optimize bundle size (https://github.com/woocommerce/woocommerce-admin/pull/4094) * Use lazy loading to split up the size of the js downloaded * Use lazy loading to split up the size of the js downloaded * Add Moment Timezone plugin to reduce size of data file. * Lazy load header panels and use Dashicons for faster loading * Load assets from the correct publicPath * Load assets from the correct publicPath * PHP cs fixes * Fix missing quotes on string literal. * Fix PropType warning for lazy loaded component. * Separate the task list and dashboard chunks. * Lazy load dashboard sections. * Restore original icons and reduce size by importing only the icons needed * Lazy load alerts to save more Kb on initial load * Minify built JS in production mode. * Add preload tags for WC Admin assets. (https://github.com/woocommerce/woocommerce-admin/pull/4162) * Fix linting errors. * Add modified UnminifiedWebpackPlugin. * Produce minified and unminified bundles for all builds. * Remove unused variable from webpack config. * Run unminify after sourcemap generation. * Only hook after optimization if we're using a devtool. * Add minification suffix in Loader::get_url(). * Lazy load OBW on new home screen. * Move OBW style up a level to layout. * Hydrate ProfileWizard independently of withSelect and withDispatch * Fix order of composition and fallback function when using hydration. Co-authored-by: Jeff Stieler <jeff.m.stieler@gmail.com> Co-authored-by: Paul Sealock <psealock@gmail.com>
2020-04-29 18:01:27 +00:00
type HomescreenProps = ReturnType< typeof withSelectHandler > & {
hasFinishedResolution: boolean;
};
const Homescreen = ( {
profileItems: {
completed: profilerCompleted,
skipped: profilerSkipped,
} = {},
hasFinishedResolution,
}: HomescreenProps ) => {
useEffect( () => {
if (
hasFinishedResolution &&
! profilerCompleted &&
! profilerSkipped
) {
getHistory().push( getNewPath( {}, '/setup-wizard', {} ) );
}
}, [ hasFinishedResolution, profilerCompleted, profilerSkipped ] );
const query = useQuery();
return <Layout query={ query } />;
};
const onboardingData = getAdminSetting( 'onboarding', {} );
const withSelectHandler = ( select: WCDataSelector ) => {
const { getProfileItems, hasFinishedResolution } = select(
ONBOARDING_STORE_NAME
);
return {
profileItems: getProfileItems(),
hasFinishedResolution: hasFinishedResolution( 'getProfileItems', [] ),
};
};
export default compose(
withOnboardingHydration( {
profileItems: onboardingData.profile,
} ),
withSelect( withSelectHandler )
)( Homescreen );