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

Fix Design Colors Step #180

Merged
merged 1 commit into from
Feb 23, 2023
Merged
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
103 changes: 47 additions & 56 deletions src/OnboardingSPA/components/Drawer/DrawerPanel/DesignColors.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,62 +91,30 @@ const DesignColors = () => {
selectedGlobalStyle?.settings?.color?.palette;
if ( colorPalettesTemp && colorStyle && selectedThemeColorPalette ) {
for ( let idx = 0; idx < selectedThemeColorPalette.length; idx++ ) {
switch ( selectedThemeColorPalette[ idx ]?.slug ) {
case 'primary':
case 'secondary':
case 'tertiary':
case 'base':
case 'contrast':
/* YITH WONDER */
case 'header-background':
case 'header-foreground':
case 'header-titles':
case 'secondary-background':
case 'secondary-foreground':
const slug = selectedThemeColorPalette[ idx ]?.slug;
if (
isCustomStyle &&
selectedColorsLocalTemp?.[ slug ] != '' &&
selectedColorsLocalTemp?.[ slug ] != undefined
)
selectedThemeColorPalette[ idx ].color =
selectedColorsLocalTemp[ slug ];
/**
* Add Exception for Background.
* (perhaps scope to yith-wonder in future)
*/ else if (
colorPalettesTemp?.[ colorStyle ]?.[ slug ] &&
'base' === slug
) {
selectedThemeColorPalette[ idx ].color = '#FFFFFF';
} else if (
! isCustomStyle &&
colorPalettesTemp?.[ colorStyle ]?.[ slug ]
) {
selectedThemeColorPalette[ idx ].color =
colorPalettesTemp[ colorStyle ][ slug ];
}

if ( customColorsMap ) {
const colorVariant = customColorsMap[ slug ];
if ( colorVariant ) {
colorVariant.forEach( ( variant ) => {
if (
customColors &&
customColors[ slug ] !== undefined
) {
selectedThemeColorPalette[
findInCustomColors( variant, slug )
].color = customColors[ slug ];
}
} );
}
}

break;
const slug = selectedThemeColorPalette[ idx ]?.slug;
if (
isCustomStyle &&
selectedColorsLocalTemp?.[ slug ] != '' &&
selectedColorsLocalTemp?.[ slug ] != undefined
)
selectedThemeColorPalette[ idx ].color =
selectedColorsLocalTemp[ slug ];
/**
* Add Exception for Background.
* (perhaps scope to yith-wonder in future)
*/ else if (
colorPalettesTemp?.[ colorStyle ]?.[ slug ] &&
'base' === slug
) {
selectedThemeColorPalette[ idx ].color = '#FFFFFF';
} else if (
! isCustomStyle &&
colorPalettesTemp?.[ colorStyle ]?.[ slug ]
) {
selectedThemeColorPalette[ idx ].color =
colorPalettesTemp[ colorStyle ][ slug ];
}
}

selectedGlobalStyle.settings.color.palette =
selectedThemeColorPalette;
updatePreviewSettings(
Expand All @@ -160,9 +128,13 @@ const DesignColors = () => {
}
}

function findInCustomColors( slugName, colorPickerCalledBy ) {
function findInCustomColors(
slugName,
colorPickerCalledBy,
storedPreviewSettingsTemp = storedPreviewSettings
) {
const selectedThemeColorPalette =
storedPreviewSettings?.settings?.color?.palette;
storedPreviewSettingsTemp?.settings?.color?.palette;
const res = selectedThemeColorPalette.findIndex(
( { slug } ) => slug === slugName
);
Expand Down Expand Up @@ -220,10 +192,14 @@ const DesignColors = () => {
}

const getColorStylesAndPatterns = async () => {
const globalStyles = await getGlobalStyles();
const colorPalettes = await getThemeColors();
if ( colorPalettes?.error ) {
return updateThemeStatus( THEME_STATUS_INIT );
}
if ( globalStyles?.error ) {
return updateThemeStatus( THEME_STATUS_INIT );
}
setColorPalettes( colorPalettes?.body.tailored );
setCustomColorsMap( colorPalettes?.body[ 'custom-picker-grouping' ] );
let selectedColors;
Expand All @@ -242,6 +218,12 @@ const DesignColors = () => {
}
}
setSelectedColors( selectedColors );
saveThemeColorPalette(
currentData?.data?.palette.slug,
colorPalettes?.body.tailored,
selectedColorsLocal,
globalStyles?.body[ 0 ]
);
setIsLoaded( true );
};

Expand Down Expand Up @@ -272,6 +254,15 @@ const DesignColors = () => {
const selectedColorsLocalCopy = { ...selectedColorsLocal };
selectedColorsLocalCopy[ colorPickerCalledBy ] = color;

if ( customColorsMap ) {
const colorVariant = customColorsMap[ colorPickerCalledBy ];
if ( colorVariant ) {
colorVariant.forEach( ( variant ) => {
selectedColorsLocalCopy[ variant ] = color;
} );
}
}

saveCustomColors();
LocalToState( selectedColorsLocalCopy, 'custom' );
setSelectedColorsLocal( selectedColorsLocalCopy );
Expand Down