2023-09-12 02:30:54 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { Loader } from '@woocommerce/onboarding';
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2023-11-08 08:50:15 +00:00
|
|
|
import { useEffect, useState } from '@wordpress/element';
|
2023-09-12 02:30:54 +00:00
|
|
|
|
2023-08-29 06:00:54 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2023-09-12 02:30:54 +00:00
|
|
|
import analyzingYourResponses from '../../assets/images/loader-analyzing-your-responses.svg';
|
|
|
|
import designingTheBestLook from '../../assets/images/loader-designing-the-best-look.svg';
|
|
|
|
import comparingTheTopPerformingStores from '../../assets/images/loader-comparing-top-performing-stores.svg';
|
|
|
|
import assemblingAiOptimizedStore from '../../assets/images/loader-assembling-ai-optimized-store.svg';
|
|
|
|
import applyingFinishingTouches from '../../assets/images/loader-applying-the-finishing-touches.svg';
|
2023-11-01 07:42:36 +00:00
|
|
|
import generatingContent from '../../assets/images/loader-generating-content.svg';
|
|
|
|
import openingTheDoors from '../../assets/images/loader-opening-the-doors.svg';
|
2024-01-19 11:03:19 +00:00
|
|
|
import { createAugmentedSteps } from '~/customize-store/utils';
|
2023-09-12 02:30:54 +00:00
|
|
|
|
|
|
|
const loaderSteps = [
|
|
|
|
{
|
|
|
|
title: __( 'Analyzing your responses', 'woocommerce' ),
|
|
|
|
image: (
|
|
|
|
<img
|
|
|
|
src={ analyzingYourResponses }
|
|
|
|
alt={ __( 'Analyzing your responses', 'woocommerce' ) }
|
|
|
|
/>
|
|
|
|
),
|
2023-11-01 07:42:36 +00:00
|
|
|
progress: 14,
|
2023-09-12 02:30:54 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Comparing the top performing stores', 'woocommerce' ),
|
|
|
|
image: (
|
|
|
|
<img
|
|
|
|
src={ comparingTheTopPerformingStores }
|
|
|
|
alt={ __(
|
|
|
|
'Comparing the top performing stores',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
),
|
2023-11-01 07:42:36 +00:00
|
|
|
progress: 28,
|
2023-09-12 02:30:54 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Designing the best look for your business', 'woocommerce' ),
|
|
|
|
image: (
|
|
|
|
<img
|
|
|
|
src={ designingTheBestLook }
|
|
|
|
alt={ __(
|
|
|
|
'Designing the best look for your business',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
),
|
2023-11-01 07:42:36 +00:00
|
|
|
progress: 42,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Generating content', 'woocommerce' ),
|
|
|
|
image: (
|
|
|
|
<img
|
|
|
|
src={ generatingContent }
|
|
|
|
alt={ __( 'Generating content', 'woocommerce' ) }
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
progress: 56,
|
2023-09-12 02:30:54 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Assembling your AI-optimized store', 'woocommerce' ),
|
|
|
|
image: (
|
|
|
|
<img
|
|
|
|
src={ assemblingAiOptimizedStore }
|
|
|
|
alt={ __(
|
|
|
|
'Assembling your AI-optimized store',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
),
|
2023-11-01 07:42:36 +00:00
|
|
|
progress: 70,
|
2023-09-12 02:30:54 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Applying the finishing touches', 'woocommerce' ),
|
|
|
|
image: (
|
|
|
|
<img
|
|
|
|
src={ applyingFinishingTouches }
|
|
|
|
alt={ __( 'Applying the finishing touches', 'woocommerce' ) }
|
|
|
|
/>
|
|
|
|
),
|
2023-11-01 07:42:36 +00:00
|
|
|
progress: 84,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: __( 'Opening the doors', 'woocommerce' ),
|
|
|
|
image: (
|
|
|
|
<img
|
|
|
|
src={ openingTheDoors }
|
|
|
|
alt={ __( 'Opening the doors', 'woocommerce' ) }
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
progress: 100,
|
2023-09-12 02:30:54 +00:00
|
|
|
},
|
|
|
|
];
|
2023-08-29 06:00:54 +00:00
|
|
|
|
2023-10-31 13:09:21 +00:00
|
|
|
// Loader for the API call without the last frame.
|
2023-09-12 02:30:54 +00:00
|
|
|
export const ApiCallLoader = () => {
|
2023-11-08 08:50:15 +00:00
|
|
|
const [ progress, setProgress ] = useState( 5 );
|
|
|
|
|
2023-10-12 06:12:24 +00:00
|
|
|
useEffect( () => {
|
|
|
|
const preload = ( src: string ) => {
|
|
|
|
const img = new Image();
|
|
|
|
|
|
|
|
img.src = src;
|
|
|
|
img.onload = () => {};
|
|
|
|
};
|
|
|
|
|
2023-11-01 07:42:36 +00:00
|
|
|
// We preload the these images to avoid flickering. We only need to preload them because the others are small enough to be inlined in base64.
|
2023-10-12 06:12:24 +00:00
|
|
|
preload( assemblingAiOptimizedStore );
|
2023-11-01 07:42:36 +00:00
|
|
|
preload( openingTheDoors );
|
2023-10-12 06:12:24 +00:00
|
|
|
}, [] );
|
|
|
|
|
2023-12-07 04:14:57 +00:00
|
|
|
const augmentedSteps = createAugmentedSteps(
|
|
|
|
loaderSteps.slice( 0, -1 ),
|
|
|
|
10
|
|
|
|
);
|
2023-11-08 08:50:15 +00:00
|
|
|
|
2023-08-29 06:00:54 +00:00
|
|
|
return (
|
2023-09-12 02:30:54 +00:00
|
|
|
<Loader>
|
2023-10-31 13:09:21 +00:00
|
|
|
<Loader.Sequence
|
2023-11-08 08:50:15 +00:00
|
|
|
interval={ ( 40 * 1000 ) / ( augmentedSteps.length - 1 ) }
|
2023-10-31 13:09:21 +00:00
|
|
|
shouldLoop={ false }
|
2023-11-08 08:50:15 +00:00
|
|
|
onChange={ ( index ) => {
|
|
|
|
// to get around bad set state timing issue
|
|
|
|
setTimeout( () => {
|
|
|
|
setProgress( augmentedSteps[ index ].progress );
|
|
|
|
}, 0 );
|
|
|
|
} }
|
2023-10-31 13:09:21 +00:00
|
|
|
>
|
2023-11-08 08:50:15 +00:00
|
|
|
{ augmentedSteps.map( ( step, index ) => (
|
2023-10-31 13:09:21 +00:00
|
|
|
<Loader.Layout key={ index }>
|
|
|
|
<Loader.Illustration>
|
|
|
|
{ step.image }
|
|
|
|
</Loader.Illustration>
|
|
|
|
<Loader.Title>{ step.title }</Loader.Title>
|
|
|
|
</Loader.Layout>
|
|
|
|
) ) }
|
|
|
|
</Loader.Sequence>
|
2023-11-08 08:50:15 +00:00
|
|
|
<Loader.ProgressBar
|
|
|
|
className="smooth-transition"
|
|
|
|
progress={ progress || 0 }
|
|
|
|
/>
|
2023-10-31 13:09:21 +00:00
|
|
|
</Loader>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const AssembleHubLoader = () => {
|
|
|
|
// Show the last two steps of the loader so that the last frame is the shortest time possible
|
2023-12-07 04:14:57 +00:00
|
|
|
const augmentedSteps = createAugmentedSteps( loaderSteps.slice( -2 ), 10 );
|
2023-11-08 08:50:15 +00:00
|
|
|
|
|
|
|
const [ progress, setProgress ] = useState( augmentedSteps[ 0 ].progress );
|
2023-10-31 13:09:21 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Loader>
|
2023-11-08 08:50:15 +00:00
|
|
|
<Loader.Sequence
|
|
|
|
interval={ ( 10 * 1000 ) / ( augmentedSteps.length - 1 ) }
|
|
|
|
shouldLoop={ false }
|
|
|
|
onChange={ ( index ) => {
|
|
|
|
// to get around bad set state timing issue
|
|
|
|
setTimeout( () => {
|
|
|
|
setProgress( augmentedSteps[ index ].progress );
|
|
|
|
}, 0 );
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
{ augmentedSteps.map( ( step, index ) => (
|
2023-09-12 02:30:54 +00:00
|
|
|
<Loader.Layout key={ index }>
|
|
|
|
<Loader.Illustration>
|
|
|
|
{ step.image }
|
|
|
|
</Loader.Illustration>
|
|
|
|
<Loader.Title>{ step.title }</Loader.Title>
|
|
|
|
</Loader.Layout>
|
|
|
|
) ) }
|
|
|
|
</Loader.Sequence>
|
2023-11-08 08:50:15 +00:00
|
|
|
<Loader.ProgressBar
|
|
|
|
className="smooth-transition"
|
|
|
|
progress={ progress || 0 }
|
|
|
|
/>
|
2023-09-12 02:30:54 +00:00
|
|
|
</Loader>
|
2023-08-29 06:00:54 +00:00
|
|
|
);
|
|
|
|
};
|