diff --git a/packages/js/onboarding/changelog/add-loader-component-shouldloop-prop b/packages/js/onboarding/changelog/add-loader-component-shouldloop-prop new file mode 100644 index 00000000000..68b45e0b8c7 --- /dev/null +++ b/packages/js/onboarding/changelog/add-loader-component-shouldloop-prop @@ -0,0 +1,4 @@ +Significance: minor +Type: update + +Added shouldLoop prop for the Loader component to determine if looping should happen diff --git a/packages/js/onboarding/src/components/Loader/Loader.tsx b/packages/js/onboarding/src/components/Loader/Loader.tsx index 62237f1b105..a76298ee9ec 100644 --- a/packages/js/onboarding/src/components/Loader/Loader.tsx +++ b/packages/js/onboarding/src/components/Loader/Loader.tsx @@ -118,19 +118,30 @@ Loader.Subtext = ( { const LoaderSequence = ( { interval, + shouldLoop = true, children, -}: { interval: number } & withReactChildren ) => { +}: { interval: number; shouldLoop?: boolean } & withReactChildren ) => { const [ index, setIndex ] = useState( 0 ); + const childCount = Children.count( children ); useEffect( () => { const rotateInterval = setInterval( () => { - setIndex( - ( prevIndex ) => ( prevIndex + 1 ) % Children.count( children ) - ); + setIndex( ( prevIndex ) => { + const nextIndex = prevIndex + 1; + + if ( shouldLoop ) { + return nextIndex % childCount; + } + if ( nextIndex < childCount ) { + return nextIndex; + } + clearInterval( rotateInterval ); + return prevIndex; + } ); }, interval ); return () => clearInterval( rotateInterval ); - }, [ interval, children ] ); + }, [ interval, children, shouldLoop, childCount ] ); const childToDisplay = Children.toArray( children )[ index ]; return <>{ childToDisplay }; diff --git a/packages/js/onboarding/src/components/Loader/stories/index.tsx b/packages/js/onboarding/src/components/Loader/stories/index.tsx index 1e480f15ed8..c5972edbe14 100644 --- a/packages/js/onboarding/src/components/Loader/stories/index.tsx +++ b/packages/js/onboarding/src/components/Loader/stories/index.tsx @@ -29,8 +29,28 @@ export const ExampleSimpleLoader = () => ( ); +export const ExampleNonLoopingLoader = () => ( + + + + a cute kitteh + + Very Impressive Title + + + Message 1 + Message 2 + Message 3 + + + +); + /** component story with controls */ -const Template = ( { progress, title, messages } ) => ( +const Template = ( { progress, title, messages, shouldLoop } ) => ( @@ -41,7 +61,7 @@ const Template = ( { progress, title, messages } ) => ( { title } - + { messages.map( ( message, index ) => ( { message } ) ) } @@ -54,6 +74,7 @@ export const ExampleLoaderWithControls = Template.bind( {} ); ExampleLoaderWithControls.args = { title: 'Very Impressive Title', progress: 30, + shouldLoop: true, messages: [ 'Message 1', 'Message 2', 'Message 3' ], }; @@ -71,6 +92,9 @@ export default { max: 100, }, }, + shouldLoop: { + control: 'boolean', + }, messages: { control: 'object', }, diff --git a/plugins/woocommerce-admin/client/customize-store/design-with-ai/pages/ApiCallLoader.tsx b/plugins/woocommerce-admin/client/customize-store/design-with-ai/pages/ApiCallLoader.tsx index 32dfb15b1cd..89095f36d6b 100644 --- a/plugins/woocommerce-admin/client/customize-store/design-with-ai/pages/ApiCallLoader.tsx +++ b/plugins/woocommerce-admin/client/customize-store/design-with-ai/pages/ApiCallLoader.tsx @@ -91,7 +91,7 @@ export const ApiCallLoader = () => { return ( - + { loaderSteps.map( ( step, index ) => ( diff --git a/plugins/woocommerce/changelog/fix-cys-design-with-ai-loader-loop b/plugins/woocommerce/changelog/fix-cys-design-with-ai-loader-loop new file mode 100644 index 00000000000..ca73c914700 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-cys-design-with-ai-loader-loop @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix cys loading screep should not be looping