Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix settings updates
  • Loading branch information
youknowriad committed Oct 6, 2021
commit 854e51c90e9d9671c2162e36f26a657053f5cbd2
22 changes: 14 additions & 8 deletions packages/edit-site/src/components/global-styles/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,27 @@ function mergeBaseAndUserConfigs( base, user ) {
}

function addUserOriginToSettings( settingsToAdd ) {
const newSettings = cloneDeep( settingsToAdd );
PRESET_METADATA.forEach( ( { path } ) => {
const presetData = get( settingsToAdd, path );
const presetData = get( newSettings, path );
if ( presetData ) {
set( settingsToAdd, path, {
set( newSettings, path, {
user: presetData,
} );
}
} );
return settingsToAdd;
return newSettings;
}

function removeUserOriginFromSettings( settingsToRemove ) {
const newSettings = cloneDeep( settingsToRemove );
PRESET_METADATA.forEach( ( { path } ) => {
const presetData = get( settingsToRemove, path );
const presetData = get( newSettings, path );
if ( presetData ) {
set( settingsToRemove, path, ( presetData ?? {} ).user );
set( newSettings, path, ( presetData ?? {} ).user );
}
} );
return settingsToRemove;
return newSettings;
}

function useGlobalStylesUserConfig() {
Expand Down Expand Up @@ -175,7 +177,11 @@ export function useSetting( path, blockName, source = 'all' ) {
const setSetting = ( newValue ) => {
setUserConfig( ( currentConfig ) => {
const newUserConfig = cloneDeep( currentConfig );
set( newUserConfig, fullPath, newValue );
const pathToSet = PATHS_WITH_MERGE[ path ]
? fullPath + '.user'
: fullPath;
set( newUserConfig, pathToSet, newValue );

return newUserConfig;
} );
};
Expand All @@ -188,7 +194,7 @@ export function useSetting( path, blockName, source = 'all' ) {
const getSettingValue = ( configToUse ) => {
const result = get( configToUse, currentPath );
if ( PATHS_WITH_MERGE[ path ] ) {
return result?.theme ?? result?.core;
return result?.user ?? result?.theme ?? result?.core;
}
return result;
};
Expand Down