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 custom color selections not reflecting in the accordion #241

Merged
merged 1 commit into from
May 22, 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
45 changes: 27 additions & 18 deletions src/OnboardingSPA/components/Drawer/DrawerPanel/DesignColors.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,11 @@ const DesignColors = () => {
isCustomStyle &&
selectedColorsLocalTemp?.[ slug ] !== '' &&
selectedColorsLocalTemp?.[ slug ] !== undefined
)
) {
selectedThemeColorPalette[ idx ].color =
selectedColorsLocalTemp[ slug ];
/**
* Add Exception for Background.
* (perhaps scope to yith-wonder in future)
*/ else if (
} else if (
// Add Exception for Background.(perhaps scope to yith-wonder in future)
colorPalettesTemp?.[ colorStyle ]?.[ slug ] &&
'base' === slug
) {
Expand Down Expand Up @@ -137,10 +135,11 @@ const DesignColors = () => {
const res = selectedThemeColorPalette.findIndex(
( { slug } ) => slug === slugName
);
if ( res === -1 )
if ( res === -1 ) {
return selectedThemeColorPalette.findIndex(
( { slug } ) => slug === colorPickerCalledBy
);
}
return res;
}

Expand All @@ -156,9 +155,10 @@ const DesignColors = () => {
colorPickerCalledBy === slug &&
customColors &&
customColors[ slug ] !== undefined
)
) {
selectedThemeColorPalette[ idx ].color =
customColors[ slug ];
}
}
if ( customColorsMap ) {
const colorVariant = customColorsMap[ colorPickerCalledBy ];
Expand Down Expand Up @@ -205,15 +205,15 @@ const DesignColors = () => {
let selectedColorsLocalTemp;
if ( ! currentData?.data?.palette?.slug === '' ) {
selectedColorsTemp = currentData.data.palette;
selectedColorsLocalTemp = stateToLocal( selectedColors );
setCustomColors( selectedColorsLocal );
selectedColorsLocalTemp = stateToLocal( selectedColorsTemp );
setCustomColors( selectedColorsLocalTemp );
setCurrentOnboardingData( currentData );
} else {
selectedColorsTemp = currentData.data.palette;
selectedColorsLocalTemp = stateToLocal( selectedColors );
selectedColorsLocalTemp = stateToLocal( selectedColorsTemp );

if ( selectedColorsTemp.slug === 'custom' ) {
setCustomColors( selectedColorsLocal );
setCustomColors( selectedColorsLocalTemp );
}
}
setSelectedColors( selectedColorsTemp );
Expand All @@ -227,8 +227,9 @@ const DesignColors = () => {
};

useEffect( () => {
if ( ! isLoaded && THEME_STATUS_ACTIVE === themeStatus )
if ( ! isLoaded && THEME_STATUS_ACTIVE === themeStatus ) {
getColorStylesAndPatterns();
}
if ( isCustomColorActive() ) {
setIsAccordionClosed( false );
customColorsResetRef.current.scrollIntoView( {
Expand All @@ -240,8 +241,9 @@ const DesignColors = () => {

const handleClick = ( colorStyle ) => {
const customColorsTemp = customColors;
for ( const custom in customColorsTemp )
for ( const custom in customColorsTemp ) {
customColorsTemp[ custom ] = '';
}

setCustomColors( customColorsTemp );
saveThemeColorPalette( colorStyle );
Expand Down Expand Up @@ -271,8 +273,11 @@ const DesignColors = () => {
const selectCustomColor = ( colorType ) => {
setShowColorPicker( ! showColorPicker );

if ( ! showColorPicker ) setColorPickerCalledBy( colorType );
else setColorPickerCalledBy( '' );
if ( ! showColorPicker ) {
setColorPickerCalledBy( colorType );
} else {
setColorPickerCalledBy( '' );
}
};

async function resetColors() {
Expand All @@ -292,8 +297,9 @@ const DesignColors = () => {
);
selectedColors.slug = '';
selectedColors.name = '';
for ( const colorVal in selectedColors?.color )
for ( const colorVal in selectedColors?.color ) {
selectedColors.color[ colorVal ].color = '';
}
setCustomColors( stateToLocal( selectedColors ) );
currentData.data.palette = selectedColors;

Expand Down Expand Up @@ -346,8 +352,11 @@ const DesignColors = () => {
}

function isCustomColorActive() {
for ( const custom in customColors )
if ( customColors[ custom ] !== '' ) return true;
for ( const custom in customColors ) {
if ( customColors[ custom ] !== '' ) {
return true;
}
}

return false;
}
Expand Down