Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme showcase: Improve loading state #80966

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/components/theme/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$theme-info-height: 54px;

.theme {
.card.theme-card {
&.is-placeholder {
background-color: var(--color-neutral-10);
animation: loading-fade 1.6s ease-in-out infinite;
Expand Down
2 changes: 0 additions & 2 deletions client/components/themes-list/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ Other accepted props are two boolean flags and a callback, all of which are rela

## Props

- `emptyContent`: element ( optional ), element that will be displayed when the list is empty, if null or not provided default EmptyContent will be used.

For a complete list of props along with their types, please refer to the `ThemesList` component's `propTypes` member.
3 changes: 0 additions & 3 deletions client/my-sites/themes/single-site-jetpack.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const ConnectedSingleSiteJetpack = connectOptions( ( props ) => {
const {
currentPlan,
currentThemeId,
emptyContent,
filter,
getScreenshotOption,
isAtomic,
Expand Down Expand Up @@ -143,7 +142,6 @@ const ConnectedSingleSiteJetpack = connectOptions( ( props ) => {
} }
trackScrollPage={ props.trackScrollPage }
source="wpcom"
emptyContent={ emptyContent }
upsellUrl={ upsellUrl }
forceWpOrgSearch
/>
Expand All @@ -164,7 +162,6 @@ export default connect( ( state, { siteId, tier } ) => {
currentThemeId,
tier,
showWpcomThemesList,
emptyContent: null,
isAtomic: isAtomicSite( state, siteId ),
isMultisite,
isPossibleJetpackConnectionProblem: isJetpackConnectionProblem( state, siteId ),
Expand Down
10 changes: 9 additions & 1 deletion client/my-sites/themes/test/logged-out.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ describe( 'logged-out', () => {
test( 'renders without error when no themes are present', async () => {
const store = createReduxStore();
setStore( store );
store.dispatch(
receiveThemes(
[],
'wpcom',
{ ...DEFAULT_THEME_QUERY, collection: 'recommended' },
themes.length
)
);
render( <TestComponent store={ store } /> );

await waitFor( () => {
Expand Down Expand Up @@ -133,7 +141,7 @@ describe( 'logged-out', () => {
store.dispatch( {
type: THEMES_REQUEST_FAILURE,
siteId: 'wpcom',
query: {},
query: { ...DEFAULT_THEME_QUERY, collection: 'recommended' },
error: 'Error',
} );
render( <TestComponent store={ store } /> );
Expand Down
3 changes: 0 additions & 3 deletions client/my-sites/themes/theme-showcase.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class ThemeShowcase extends Component {
}

static propTypes = {
emptyContent: PropTypes.element,
tier: PropTypes.oneOf( [ '', 'free', 'premium', 'marketplace' ] ),
search: PropTypes.string,
pathName: PropTypes.string,
Expand All @@ -104,7 +103,6 @@ class ThemeShowcase extends Component {
static defaultProps = {
tier: '',
search: '',
emptyContent: null,
upsellBanner: false,
showUploadButton: true,
};
Expand Down Expand Up @@ -490,7 +488,6 @@ class ThemeShowcase extends Component {
},
getActionLabel: ( theme ) => getScreenshotOption( theme ).label,
trackScrollPage: this.props.trackScrollPage,
emptyContent: this.props.emptyContent,
scrollToSearchInput: this.scrollToSearchInput,
getOptions: ( theme ) =>
pickBy(
Expand Down
22 changes: 4 additions & 18 deletions client/my-sites/themes/themes-selection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import './themes-selection.scss';

class ThemesSelection extends Component {
static propTypes = {
emptyContent: PropTypes.element,
getOptions: PropTypes.func,
getActionLabel: PropTypes.func,
incrementPage: PropTypes.func,
Expand All @@ -62,7 +61,6 @@ class ThemesSelection extends Component {
};

static defaultProps = {
emptyContent: null,
showUploadButton: true,
forceWpOrgSearch: false,
};
Expand Down Expand Up @@ -276,7 +274,6 @@ class ThemesSelection extends Component {
getPrice={ this.props.getPremiumThemePrice }
isInstalling={ this.props.isInstallingTheme }
loading={ isRequesting }
emptyContent={ this.props.emptyContent }
placeholderCount={ this.props.placeholderCount }
bookmarkRef={ this.props.bookmarkRef }
siteId={ siteId }
Expand Down Expand Up @@ -320,18 +317,7 @@ function bindGetThemeType( state ) {
export const ConnectedThemesSelection = connect(
(
state,
{
filter,
page,
search,
tier,
vertical,
siteId,
source,
forceWpOrgSearch,
isLoading: isCustomizedThemeListLoading,
tabFilter,
}
{ filter, page, search, tier, vertical, siteId, source, forceWpOrgSearch, tabFilter }
) => {
const isJetpack = isJetpackSite( state, siteId );
const isAtomic = isSiteAutomatedTransfer( state, siteId );
Expand Down Expand Up @@ -370,7 +356,7 @@ export const ConnectedThemesSelection = connect(
...( tabFilter === 'all' && { sort: 'date' } ),
};

const themes = getThemesForQueryIgnoringPage( state, sourceSiteId, query ) || [];
const themes = getThemesForQueryIgnoringPage( state, sourceSiteId, query );

const shouldFetchWpOrgThemes =
forceWpOrgSearch &&
Expand Down Expand Up @@ -401,9 +387,9 @@ export const ConnectedThemesSelection = connect(
source: sourceSiteId,
siteId: siteId,
siteSlug: getSiteSlug( state, siteId ),
themes,
themes: themes || [],
isRequesting:
isCustomizedThemeListLoading ||
themes === null ||
isRequestingThemesForQuery( state, sourceSiteId, query ) ||
( shouldFetchWpOrgThemes && isRequestingThemesForQuery( state, 'wporg', wpOrgQuery ) ),
isLastPage: isThemesLastPageForQuery( state, sourceSiteId, query ),
Expand Down
15 changes: 15 additions & 0 deletions client/state/themes/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,21 @@ const queriesReducer = ( state = {}, action ) => {
() => new ThemeQueryManager( null, { itemKey: 'id' } )
);
}
case THEMES_REQUEST_FAILURE: {
const { siteId, query } = action;
return withQueryManager(
state,
siteId,
( m ) =>
m.receive( [], {
query,
found: 0,
patch: true,
dontShareQueryResultsWhenQueriesAreDifferent: true,
} ),
() => new ThemeQueryManager( null, { itemKey: 'id' } )
);
}
case THEME_DELETE_SUCCESS: {
const { siteId, themeId } = action;
return withQueryManager( state, siteId, ( m ) => m.removeItem( themeId ) );
Expand Down