Skip to content

Commit b3b9663

Browse files
ineaguclaude
andcommitted
fix(onboarding): sync card screenshot to the selected color filter
When a color is selected in the global filter, each matching starter-site card now switches its screenshot to that color's palette (screenshots_by_color), restoring the intended filter behavior (the card previously stayed on its default palette). All in StarterSiteCard: - subscribe to getSelectedColors via withSelect; - derive `filterColor` = the first selected color the card actually has (case-insensitive match, returns the raw colorOptions slug); - seed activeColor from filterColor (falling back to the first palette) in an effect keyed on [colorOptions, filterColor], so manual swatch clicks survive until the filter changes and a cleared filter reverts to the default. Falls back to the base screenshot when screenshots_by_color lacks the selected color. Builds on the single-palette swatch gate (colorOptions.length > 1). Verified in a local wp-env Neve onboarding instance: selecting "green" switched the matching cards to their -green screenshots. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QrGf4K9upxDKhRPVCztoLs
1 parent 92c0468 commit b3b9663

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

onboarding/src/Components/StarterSiteCard.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ const StarterSiteCard = ( {
4747
setSite,
4848
handleNextStep,
4949
trackingId,
50-
editor
50+
editor,
51+
selectedColors = []
5152
} ) => {
5253
const {
5354
upsell,
@@ -93,6 +94,32 @@ const StarterSiteCard = ( {
9394
screenshot: screenshotMap[ color ] || screenshot,
9495
} ) );
9596
}, [ data?.colors, data?.screenshots_by_color, screenshot ] );
97+
// First globally-selected color this card actually has, returned as the
98+
// canonical RAW colorOptions slug so option.slug === activeColor still hits.
99+
// selectedColors are normalized lowercase (Filters.js) while colorOptions
100+
// slugs / screenshots_by_color keys are raw, so match case-insensitively.
101+
const filterColor = useMemo( () => {
102+
if (
103+
! Array.isArray( selectedColors ) ||
104+
! selectedColors.length ||
105+
! colorOptions.length
106+
) {
107+
return '';
108+
}
109+
110+
const normalizedToSlug = new Map(
111+
colorOptions.map( ( option ) => [
112+
String( option.slug || '' ).trim().toLowerCase(),
113+
option.slug,
114+
] )
115+
);
116+
117+
const matched = selectedColors.find( ( color ) =>
118+
normalizedToSlug.has( color )
119+
);
120+
121+
return matched ? normalizedToSlug.get( matched ) : '';
122+
}, [ selectedColors, colorOptions ] );
96123
const previewColors = colorOptions.slice( 0, 2 );
97124
const [ activePage, setActivePage ] = useState( pageShots[0]?.key || 'home' );
98125
const [ activeColor, setActiveColor ] = useState( colorOptions[0]?.slug || '' );
@@ -102,9 +129,12 @@ const StarterSiteCard = ( {
102129
setActivePage( pageShots[0]?.key || 'home' );
103130
}, [ pageShots ] );
104131

132+
// Seed the displayed color from the global filter when this card matches a
133+
// selected color; otherwise fall back to the first palette. Re-runs only on
134+
// filter/colorOptions changes, so manual swatch clicks survive until then.
105135
useEffect( () => {
106-
setActiveColor( colorOptions[0]?.slug || '' );
107-
}, [ colorOptions ] );
136+
setActiveColor( filterColor || colorOptions[0]?.slug || '' );
137+
}, [ colorOptions, filterColor ] );
108138

109139
const activePageShot =
110140
pageShots.find( ( shot ) => shot.key === activePage ) || pageShots[0] || null;
@@ -290,12 +320,14 @@ export default compose(
290320
getCurrentEditor,
291321
getCurrentCategory,
292322
getSearchQuery,
323+
getSelectedColors,
293324
} = select( 'ti-onboarding' );
294325
return {
295326
trackingId: getTrackingId(),
296327
editor: getCurrentEditor(),
297328
category: getCurrentCategory(),
298329
query: getSearchQuery(),
330+
selectedColors: getSelectedColors() || [],
299331
};
300332
} ),
301333
withDispatch( ( dispatch, { data } ) => {

0 commit comments

Comments
 (0)