Skip to content

Commit 1df862c

Browse files
feat: enhance category selection and update filters for onboarding
1 parent 9756ab6 commit 1df862c

File tree

6 files changed

+22
-13
lines changed

6 files changed

+22
-13
lines changed

onboarding/src/Components/CategoryButtons.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { useSelect, useDispatch } from '@wordpress/data';
33
import classnames from 'classnames';
44
import { track } from '../utils/rest';
5+
import { useMemo } from '@wordpress/element';
56

67
const CategoryButtons = ( { categories, style } ) => {
78
const data = useSelect( ( select ) => ( {
@@ -13,6 +14,13 @@ const CategoryButtons = ( { categories, style } ) => {
1314

1415
const { setOnboardingStep, setCategory } = useDispatch( 'ti-onboarding' );
1516

17+
// Show "All" and "Free" categories after user selection. Marketing trick.
18+
const availableCategories = useMemo(() => {
19+
return Object.keys(categories).filter((key) =>
20+
data.category || (key !== 'all' && key !== 'free')
21+
);
22+
}, [categories, data.category]);
23+
1624
const onClick = ( newCategory ) => {
1725
setCategory( newCategory );
1826

@@ -38,20 +46,20 @@ const CategoryButtons = ( { categories, style } ) => {
3846

3947
return (
4048
<div className="ob-cat-wrap" style={ style }>
41-
{ Object.keys( categories ).map( ( key, index ) => {
49+
{ availableCategories.map( ( catSlug ) => {
4250
const classes = classnames( {
4351
cat: true,
44-
[ key ]: true,
45-
active: key === data.category,
52+
[ catSlug ]: true,
53+
active: catSlug === data.category,
4654
} );
4755

4856
return (
4957
<button
5058
className={ classes }
51-
key={ index }
52-
onClick={ () => onClick( key ) }
59+
key={ catSlug }
60+
onClick={ () => onClick( catSlug ) }
5361
>
54-
{ categories[ key ] }
62+
{ categories[ catSlug ] }
5563
</button>
5664
);
5765
} ) }

onboarding/src/Components/Filters.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ONBOARDING_CAT } from '../utils/common';
66
const Filters = () => {
77
const categories = {
88
all: __( 'All', 'templates-patterns-collection' ),
9+
free: __( 'Free', 'templates-patterns-collection' ),
910
...ONBOARDING_CAT,
1011
};
1112

onboarding/src/Components/Search.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export default compose(
7878
deleteQuery: () => setSearchQuery( '' ),
7979
handleSubmit: ( e ) => {
8080
e.preventDefault();
81-
setCategory( 'all' );
8281
if ( step === 1 ) {
8382
setOnboardingStep( 2 );
8483
const data = {

onboarding/src/Components/Sites.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const Sites = ( { getSites, editor, category, searchQuery } ) => {
5050
return items.filter( ( item ) => ! item.upsell );
5151
}
5252

53-
if ( 'all' !== cat ) {
53+
if ( cat && 'all' !== cat ) {
5454
return items.filter( ( item ) => item.keywords.includes( cat ) );
5555
}
5656

onboarding/src/store/reducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const initialLicense = licenseTIOB || {
1919
const initialState = {
2020
sites: onboarding.sites || {},
2121
editor: selectedEditor,
22-
category: 'all',
22+
category: '',
2323
currentSite: null,
2424
fetching: false,
2525
searchQuery: '',

onboarding/src/utils/common.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ const trailingSlashIt = ( str ) => untrailingSlashIt( str ) + '/';
55

66
const ONBOARDING_CAT = {
77
business: __( 'Business', 'templates-patterns-collection' ),
8-
personal: __( 'Personal', 'templates-patterns-collection' ),
9-
blog: __( 'Blogging', 'templates-patterns-collection' ),
10-
portfolio: __( 'Portfolio', 'templates-patterns-collection' ),
11-
woocommerce: __( 'E-Shop', 'templates-patterns-collection' ),
8+
education: __( 'Education', 'templates-patterns-collection' ),
9+
woocommerce: __( 'eCommerce', 'templates-patterns-collection' ),
10+
news: __( 'News', 'templates-patterns-collection' ),
11+
nonprofit: __( 'Non-Profit', 'templates-patterns-collection' ),
12+
health: __( 'Health', 'templates-patterns-collection' ),
1213
};
1314

1415
const EDITOR_MAP = {

0 commit comments

Comments
 (0)