-
Notifications
You must be signed in to change notification settings - Fork 8
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
Preserve Customize Selections in State on SiteGen Editor Page #464
Changes from 2 commits
804c4cc
4d8d880
98f92ee
398431f
f02913c
64cf19c
52f9d20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,12 @@ const DesignColorsPanel = forwardRef( | |
setSelectedPalette( null ); | ||
setCurrentOnboardingData( updatedData ); | ||
} | ||
currentData.sitegen.homepages.active.color.selectedPalette = | ||
null; | ||
currentData.sitegen.homepages.data[ | ||
slug | ||
].color.selectedPalette = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should change this to an empty object or array instead of null. Also, if we're already setting all of this to empty at the end of the function, why do all the operations above this? That code can be deleted. |
||
setCurrentOnboardingData( currentData ); | ||
} | ||
}; | ||
|
||
|
@@ -114,15 +120,25 @@ const DesignColorsPanel = forwardRef( | |
useEffect( () => { | ||
if ( ! customColors ) { | ||
const storedCustomColors = | ||
currentData.sitegen.homepages.active.color | ||
.customColors; | ||
currentData.sitegen.homepages.active.color.customColors; | ||
if ( storedCustomColors ) { | ||
setCustomColors( storedCustomColors ); | ||
} else { | ||
const defaultCustomColors = palettes[ 0 ]; | ||
setCustomColors( defaultCustomColors ); | ||
} | ||
} | ||
if ( ! selectedPalette ) { | ||
const storedSelectedPalette = | ||
currentData.sitegen.homepages.active.color.selectedPalette; | ||
if ( storedSelectedPalette ) { | ||
setSelectedPalette( storedSelectedPalette ); | ||
if ( storedSelectedPalette === 'custom' ) { | ||
setShowCustomColors( true ); | ||
setSelectedCustomColors( true ); | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have so many states like |
||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [ currentData ] ); | ||
|
||
|
@@ -188,8 +204,12 @@ const DesignColorsPanel = forwardRef( | |
currentData.sitegen.homepages.data[ slug ].color.customColors = | ||
selectedColor; | ||
currentData.sitegen.homepages.active.color.customColors = | ||
selectedColor; | ||
selectedColor; | ||
} | ||
currentData.sitegen.homepages.data[ slug ].color.selectedPalette = | ||
selectedPalette; | ||
currentData.sitegen.homepages.active.color.selectedPalette = | ||
selectedPalette; | ||
|
||
const colorPaletteIndex = | ||
selectedPalette === 'custom' ? 0 : selectedPalette; | ||
|
@@ -345,9 +365,9 @@ const DesignColorsPanel = forwardRef( | |
label={ | ||
idx === 0 | ||
? __( | ||
'Default', | ||
'wp-module-onboarding' | ||
) | ||
'Default', | ||
'wp-module-onboarding' | ||
) | ||
: '' | ||
} | ||
selectedPalette={ selectedPalette } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we invert all the
if
statements in theresetToDefaultColors
and other functions to check for negation? This will help reduce the overall nesting in the function.