Skip to content

Commit 415d0d6

Browse files
committed
fix spinner when fetching from cloud
1 parent 8f7f600 commit 415d0d6

File tree

4 files changed

+39
-38
lines changed

4 files changed

+39
-38
lines changed

src/components/design-library-list/design-library-list-item.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
forwardRef, useEffect, useRef, useState,
2525
} from '@wordpress/element'
2626
import { useSelect } from '@wordpress/data'
27-
import { Dashicon, Spinner } from '@wordpress/components'
27+
import { Dashicon } from '@wordpress/components'
2828
import { __ } from '@wordpress/i18n'
2929
import { serialize } from '@wordpress/blocks'
3030
import { applyFilters } from '@wordpress/hooks'
@@ -41,7 +41,6 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
4141
category = '',
4242
plan,
4343
selectedNum = false,
44-
isBusy,
4544
containerScheme,
4645
backgroundScheme,
4746
enableBackground,
@@ -68,7 +67,6 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
6867
'ugb-design-library-item',
6968
'ugb-design-library-item--toggle',
7069
], {
71-
'ugb--is-busy': isBusy,
7270
[ `ugb--is-${ plan }` ]: ! isPro && plan !== 'free',
7371
'ugb--is-toggled': selectedNum,
7472
} )
@@ -250,7 +248,6 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
250248
onClick( designId, parsedBlocks, blocksForSubstitutionRef.current )
251249
} }
252250
>
253-
{ isBusy && <span className="ugb-design-library-item__spinner" data-testid="spinner"><Spinner /></span> }
254251
{ ! isPro && plan !== 'free' && <span className="stk-pulsating-circle" role="presentation" /> }
255252
<div style={ { position: 'relative' } }>
256253
{ ! isPro && plan !== 'free' && (
@@ -267,14 +264,13 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
267264
} }
268265
>
269266

270-
<div className="stk-block-design__host" ref={ hostRef } style={ { visibility: isBusy ? 'hidden' : 'visible', opacity: isBusy ? '0' : '' } } />
267+
<div className="stk-block-design__host" ref={ hostRef } />
271268
</div>
272269
</div>
273270

274271
<footer
275272
// Add the number if isToggle is a number, signifying an order instead of just an on/off.
276273
data-selected-num={ selectedNum }
277-
style={ { visibility: isBusy ? 'hidden' : 'visible' } }
278274
>
279275
<div>
280276
<h4> { label } </h4>

src/components/design-library-list/index.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,35 +48,35 @@ const DesignLibraryList = props => {
4848
setScrollTop( e.currentTarget.scrollTop )
4949
} }
5050
>
51-
<div className={ listClasses }>
52-
{ ( designs || [] ).map( ( design, i ) => {
53-
const selectedNum = selectedDesigns.indexOf( design.designId ) + 1
54-
return (
55-
<DesignLibraryItem
56-
key={ i }
57-
template={ design.content }
58-
plan={ design.plan }
59-
designId={ design.designId }
60-
label={ design.title }
61-
category={ design.category }
62-
containerScheme={ props.containerScheme }
63-
backgroundScheme={ props.backgroundScheme }
64-
enableBackground={ props.enableBackground }
65-
selectedNum={ selectedNum }
66-
isBusy={ isBusy }
67-
forceUpdate={ forceUpdate }
68-
onClick={ ( designId, parsedBlocks, hasDisabledBlocks ) => onSelectMulti( designId, parsedBlocks, hasDisabledBlocks ) }
69-
scrollTop={ scrollTop }
70-
/>
71-
)
72-
} ) }
73-
74-
{ isBusy && <div className="ugb-design-library-search__spinner" data-testid="spinner"><Spinner /></div> }
75-
76-
{ ! isBusy && ! ( designs || [] ).length &&
77-
<p className="components-base-control__help" data-testid="nothing-found-note">{ __( 'No designs found', i18n ) }</p>
78-
}
79-
</div>
51+
{ isBusy && <Spinner style={ { display: 'block', margin: '0 auto' } } /> }
52+
{ ! isBusy && <>
53+
<div className={ listClasses }>
54+
{ ( designs || [] ).map( ( design, i ) => {
55+
const selectedNum = selectedDesigns.indexOf( design.designId ) + 1
56+
return (
57+
<DesignLibraryItem
58+
key={ i }
59+
template={ design.content }
60+
plan={ design.plan }
61+
designId={ design.designId }
62+
label={ design.title }
63+
category={ design.category }
64+
containerScheme={ props.containerScheme }
65+
backgroundScheme={ props.backgroundScheme }
66+
enableBackground={ props.enableBackground }
67+
selectedNum={ selectedNum }
68+
forceUpdate={ forceUpdate }
69+
onClick={ ( designId, parsedBlocks, hasDisabledBlocks ) => onSelectMulti( designId, parsedBlocks, hasDisabledBlocks ) }
70+
scrollTop={ scrollTop }
71+
/>
72+
)
73+
} ) }
74+
75+
{ ! ( designs || [] ).length &&
76+
<p className="components-base-control__help" data-testid="nothing-found-note">{ __( 'No designs found', i18n ) }</p>
77+
}
78+
</div>
79+
</> }
8080
</div>
8181
}
8282

src/components/modal-design-library/block-list.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import classnames from 'classnames'
1818
*/
1919
import { useEffect, useState } from '@wordpress/element'
2020
import { __ } from '@wordpress/i18n'
21+
import { Spinner } from '@wordpress/components'
2122

2223
const BlockList = props => {
2324
const [ categoryList, setCategoryList ] = useState( [] )
@@ -89,6 +90,10 @@ const BlockList = props => {
8990
setCategoryList( sortedCategories )
9091
}, [ designs, viewBy, plan ] )
9192

93+
if ( props.isBusy ) {
94+
return <Spinner style={ { display: 'block', margin: '0 auto' } } />
95+
}
96+
9297
return (
9398
<ul className="ugb-block-list">
9499
{ categoryList.reduce( ( list, itemData ) => {

src/components/modal-design-library/modal.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const ModalDesignLibrary = props => {
8181

8282
// Update the designs on the sidebar. (this will trigger the display designs update next)
8383
useEffect( () => {
84+
setIsBusy( true )
8485
if ( doReset ) {
8586
setSidebarDesigns( [] )
8687
// setDisplayDesigns( [] )
@@ -92,20 +93,18 @@ export const ModalDesignLibrary = props => {
9293
setSidebarDesigns( designs )
9394
} ).finally( () => {
9495
setDoReset( false )
96+
setIsBusy( false )
9597
} )
9698
}, [ doReset, selectedTab ] )
9799

98100
// This updates the displayed designs the user can pick.
99101
useEffect( () => {
100-
setIsBusy( true )
101102
filterDesigns( {
102103
library: sidebarDesigns,
103104
category: selectedCategory,
104105
plan: selectedPlan.key,
105106
} ).then( designs => {
106107
setDisplayDesigns( designs )
107-
} ).finally( () => {
108-
setIsBusy( false )
109108
} )
110109
}, [ sidebarDesigns, selectedPlan, selectedCategory ] )
111110

@@ -204,6 +203,7 @@ export const ModalDesignLibrary = props => {
204203
plan={ selectedPlan.key }
205204
selected={ selectedCategory }
206205
onSelect={ id => setSelectedCategory( id ) }
206+
isBusy={ isBusy }
207207
/>
208208
</div>
209209
<div className="ugb-modal-design-library__style-options">

0 commit comments

Comments
 (0)