Skip to content

Commit

Permalink
Design Picker: Update the feature categories (#97215)
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur791004 authored Dec 9, 2024
1 parent 935ae6d commit dd5c9e2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/design-picker/src/components/unified-design-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import { useCallback, useMemo, useRef, useState } from 'react';
import { useInView } from 'react-intersection-observer';
import { SHOW_ALL_SLUG } from '../constants';
import { useFilteredDesigns } from '../hooks/use-filtered-designs';
import { getAssemblerDesign, isDefaultGlobalStylesVariationSlug } from '../utils';
import { isLockedStyleVariation } from '../utils/is-locked-style-variation';
import {
getAssemblerDesign,
isDefaultGlobalStylesVariationSlug,
isFeatureCategory,
isLockedStyleVariation,
} from '../utils';
import DesignPickerCategoryFilter from './design-picker-category-filter';
import DesignPickerTierFilter from './design-picker-tier-filter';
import DesignPreviewImage from './design-preview-image';
Expand Down Expand Up @@ -227,14 +231,13 @@ const DesignPicker: React.FC< DesignPickerProps > = ( {
} ) => {
const hasCategories = !! Object.keys( categorization?.categories || {} ).length;
const filteredDesigns = useFilteredDesigns( designs, categorization );
const features = [ 'blog', 'portfolio', 'podcast', 'store' ];
const featureCategories = useMemo(
() => ( categorization?.categories || [] ).filter( ( { slug } ) => features.includes( slug ) ),
() => ( categorization?.categories || [] ).filter( ( { slug } ) => isFeatureCategory( slug ) ),
[ categorization?.categories ]
);
const subjectCategories = useMemo(
() =>
( categorization?.categories || [] ).filter( ( { slug } ) => ! features.includes( slug ) ),
( categorization?.categories || [] ).filter( ( { slug } ) => ! isFeatureCategory( slug ) ),
[ categorization?.categories ]
);

Expand Down
11 changes: 11 additions & 0 deletions packages/design-picker/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,14 @@ export const PREMIUM_THEME = 'premium';
export const DOT_ORG_THEME = 'dot-org';
export const BUNDLED_THEME = 'bundled';
export const MARKETPLACE_THEME = 'marketplace';

/**
* Categories
*/
export const FEATURE_CATEGORIES = {
BLOG: 'blog',
NEWSLETTER: 'newsletter',
PORTFOLIO: 'portfolio',
PODCAST: 'podcast',
STORE: 'store',
};
1 change: 1 addition & 0 deletions packages/design-picker/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './available-designs';
export * from './designs';
export * from './global-styles';
export * from './is-feature-category';
export * from './is-locked-style-variation';
5 changes: 5 additions & 0 deletions packages/design-picker/src/utils/is-feature-category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { FEATURE_CATEGORIES } from '../constants';

const featureCategorySet = new Set( Object.values( FEATURE_CATEGORIES ) );

export const isFeatureCategory = ( categorySlug: string ) => featureCategorySet.has( categorySlug );

0 comments on commit dd5c9e2

Please sign in to comment.