-
Notifications
You must be signed in to change notification settings - Fork 801
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
Social: Refactor feature option storing #34113
Changes from all commits
f37dd1a
d00d07e
012eb2c
b36d720
5896416
b6952a2
b5de327
2b51295
8fbd642
aa4ee16
659e0a1
77e27ee
e809f08
b9ac65c
9c0234d
6bec608
d4b52c6
484f96f
0ba898a
f91feb3
a89e7b5
d7949bf
b7c2568
9b6020a
c169499
df78925
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: major | ||
Type: changed | ||
|
||
Social: Refactored storing of feature options to use core functions |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useDispatch } from '@wordpress/data'; | ||
import { SOCIAL_STORE_ID } from '../../social-store'; | ||
|
||
/** | ||
* HOC that refreshes all of the Jetpack Social settings in the store, to be used in class components. | ||
* | ||
* @param {object} props - The component props. | ||
* @param {boolean} props.shouldRefresh - Whether or not to refresh the settings. | ||
* @param {object} props.children - The children to render. | ||
* @returns { object } The refreshJetpackSocialSettings function. | ||
*/ | ||
export default function RefreshJetpackSocialSettingsWrapper( { shouldRefresh, children } ) { | ||
const refreshOptions = useDispatch( SOCIAL_STORE_ID ).refreshJetpackSocialSettings; | ||
|
||
if ( shouldRefresh ) { | ||
refreshOptions(); | ||
} | ||
|
||
return children; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { fetchJetpackSocialSettings } from '../controls'; | ||
import { | ||
setAutoConversionSettings, | ||
setUpdatingAutoConversionSettings, | ||
setUpdatingAutoConversionSettingsDone, | ||
} from './auto-conversion-settings'; | ||
import { | ||
setSocialImageGeneratorSettings, | ||
setUpdatingSocialImageGeneratorSettings, | ||
setUpdatingSocialImageGeneratorSettingsDone, | ||
} from './social-image-generator-settings'; | ||
|
||
/** | ||
* Yield actions to refresh all of the Jetpack Social registered settings. | ||
* | ||
* @yields {object} - an action object. | ||
* @returns {object} - an action object. | ||
*/ | ||
export function* refreshJetpackSocialSettings() { | ||
try { | ||
yield setUpdatingAutoConversionSettings(); | ||
yield setUpdatingSocialImageGeneratorSettings(); | ||
const updatedSettings = yield fetchJetpackSocialSettings(); | ||
yield setAutoConversionSettings( updatedSettings.jetpack_social_autoconvert_images ); | ||
yield setSocialImageGeneratorSettings( | ||
updatedSettings.jetpack_social_image_generator_settings | ||
); | ||
return true; | ||
} catch ( e ) { | ||
return false; | ||
} finally { | ||
yield setUpdatingAutoConversionSettingsDone(); | ||
yield setUpdatingSocialImageGeneratorSettingsDone(); | ||
} | ||
} | ||
|
||
export default { | ||
refreshJetpackSocialSettings, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ export const UPDATE_SOCIAL_IMAGE_GENERATOR_SETTINGS = 'UPDATE_SOCIAL_IMAGE_GENER | |
|
||
export const FETCH_AUTO_CONVERSION_SETTINGS = 'FETCH_AUTO_CONVERSION_SETTINGS'; | ||
export const UPDATE_AUTO_CONVERSION_SETTINGS = 'UPDATE_AUTO_CONVERSION_SETTINGS'; | ||
export const FETCH_JETPACK_SOCIAL_SETTINGS = 'FETCH_JETPACK_SOCIAL_SETTINGS'; | ||
|
||
/** | ||
* fetchJetpackSettings action | ||
|
@@ -67,6 +68,17 @@ export const fetchAutoConversionSettings = () => { | |
}; | ||
}; | ||
|
||
/** | ||
* fetchJetpackSocialSettings action | ||
* | ||
* @returns {object} - an action object. | ||
*/ | ||
export const fetchJetpackSocialSettings = () => { | ||
return { | ||
type: FETCH_JETPACK_SOCIAL_SETTINGS, | ||
}; | ||
}; | ||
|
||
/** | ||
* updateAutoConversionSettings action | ||
* | ||
|
@@ -92,23 +104,36 @@ export default { | |
} ); | ||
}, | ||
[ FETCH_SOCIAL_IMAGE_GENERATOR_SETTINGS ]: function () { | ||
return apiFetch( { path: '/jetpack/v4/social-image-generator/settings' } ); | ||
return apiFetch( { | ||
path: '/wp/v2/settings?_fields=jetpack_social_image_generator_settings', | ||
} ); | ||
}, | ||
[ UPDATE_SOCIAL_IMAGE_GENERATOR_SETTINGS ]: function ( action ) { | ||
return apiFetch( { | ||
path: '/jetpack/v4/social-image-generator/settings', | ||
path: '/wp/v2/settings', | ||
method: 'POST', | ||
data: action.settings, | ||
data: { | ||
jetpack_social_image_generator_settings: action.settings, | ||
}, | ||
} ); | ||
}, | ||
[ FETCH_AUTO_CONVERSION_SETTINGS ]: function () { | ||
return apiFetch( { path: '/jetpack/v4/auto-conversion/settings' } ); | ||
return apiFetch( { | ||
path: '/wp/v2/settings?_fields=jetpack_social_autoconvert_images', | ||
} ); | ||
}, | ||
[ UPDATE_AUTO_CONVERSION_SETTINGS ]: function ( action ) { | ||
return apiFetch( { | ||
path: '/jetpack/v4/auto-conversion/settings', | ||
path: '/wp/v2/settings', | ||
method: 'POST', | ||
data: action.settings, | ||
Comment on lines
112
to
-111
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 need multiple API calls? Can we make a single API call to get all the settings at once? 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 can add the settings fields separated by comma
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. Yes, to fetch the settings we can just have one call. 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. Yeah, I'll do that. 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. |
||
data: { | ||
jetpack_social_autoconvert_images: action.settings, | ||
}, | ||
} ); | ||
}, | ||
[ FETCH_JETPACK_SOCIAL_SETTINGS ]: function () { | ||
return apiFetch( { | ||
path: '/wp/v2/settings?_fields=jetpack_social_autoconvert_images,jetpack_social_image_generator_settings', | ||
} ); | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: major | ||
Type: changed | ||
|
||
Social: Refactored storing of feature options to use core functions |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: removed | ||
|
||
Social: Removed deprecated files because of refactore |
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.
TIL that
finally
block is executed before thereturn
statement insidetry/catch
.