Skip to content

Commit

Permalink
Update UI + store functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gmjuhasz committed Nov 14, 2023
1 parent d00d07e commit 012eb2c
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const AutoConversionToggle: React.FC< AutoConversionToggleProps > = ( {

const toggleStatus = useCallback( () => {
const newOption = {
image: ! isEnabled,
enabled: ! isEnabled,
};
updateOptions( newOption );
}, [ isEnabled, updateOptions ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const TemplatePickerButton: React.FC = () => {

useEffect( () => {
if ( currentTemplate ) {
const newOption = { defaults: { template: currentTemplate } };
const newOption = { template: currentTemplate };
updateOptions( newOption );
}
}, [ currentTemplate, updateOptions ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function* updateAutoConversionSettings( settings ) {
yield setAutoConversionSettings( settings );
yield updateAutoConversionSettingsControl( settings );
const updatedSettings = yield fetchAutoConversionSettings();
yield setAutoConversionSettings( updatedSettings );
yield setAutoConversionSettings( updatedSettings.jetpack_social_autoconvert_images );
return true;
} catch ( e ) {
const oldSettings = select( SOCIAL_STORE_ID ).getAutoConversionSettings();
Expand All @@ -41,7 +41,7 @@ export function* refreshAutoConversionSettings() {
try {
yield setUpdatingAutoConversionSettings();
const updatedSettings = yield fetchAutoConversionSettings();
yield setAutoConversionSettings( updatedSettings );
yield setAutoConversionSettings( updatedSettings.jetpack_social_autoconvert_images );
return true;
} catch ( e ) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export function* updateSocialImageGeneratorSettings( settings ) {
yield setSocialImageGeneratorSettings( settings );
yield updateSocialImageGeneratorSettingsControl( settings );
const updatedSettings = yield fetchSocialImageGeneratorSettings();
yield setSocialImageGeneratorSettings( updatedSettings );
yield setSocialImageGeneratorSettings(
updatedSettings.jetpack_social_image_generator_settings
);
return true;
} catch ( e ) {
const oldSettings = select( SOCIAL_STORE_ID ).getSocialImageGeneratorSettings();
Expand Down Expand Up @@ -69,7 +71,9 @@ export function* refreshSocialImageGeneratorSettings() {
try {
yield setUpdatingSocialImageGeneratorSettings();
const updatedSettings = yield fetchSocialImageGeneratorSettings();
yield setSocialImageGeneratorSettings( updatedSettings );
yield setSocialImageGeneratorSettings(
updatedSettings.jetpack_social_image_generator_settings
);
return true;
} catch ( e ) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,31 @@ 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,
data: {
jetpack_social_autoconvert_images: action.settings,
},
} );
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function* getSocialImageGeneratorSettings() {
try {
const settings = yield fetchSocialImageGeneratorSettings();
if ( settings ) {
return setSocialImageGeneratorSettings( settings );
return setSocialImageGeneratorSettings( settings.jetpack_social_image_generator_settings );
}
} catch ( e ) {
// TODO: Add proper error handling here
Expand All @@ -56,7 +56,7 @@ export function* getAutoConversionSettings() {
try {
const settings = yield fetchAutoConversionSettings();
if ( settings ) {
return setAutoConversionSettings( settings );
return setAutoConversionSettings( settings.jetpack_social_autoconvert_images );
}
} catch ( e ) {
// TODO: Add proper error handling here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const autoConversionSettingsSelectors = {
getAutoConversionSettings: state => state.autoConversionSettings,
isAutoConversionAvailable: state => state.autoConversionSettings.available,
isAutoConversionEnabled: state => state.autoConversionSettings.image,
isAutoConversionEnabled: state => state.autoConversionSettings.enabled,
isAutoConversionSettingsUpdating: state => state.autoConversionSettings.isUpdating,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const socialImageGeneratorSettingsSelectors = {
isSocialImageGeneratorAvailable: state => state.socialImageGeneratorSettings.available,
isSocialImageGeneratorEnabled: state => state.socialImageGeneratorSettings.enabled,
isUpdatingSocialImageGeneratorSettings: state => state.socialImageGeneratorSettings.isUpdating,
getSocialImageGeneratorDefaultTemplate: state =>
state.socialImageGeneratorSettings.defaultTemplate,
getSocialImageGeneratorDefaultTemplate: state => state.socialImageGeneratorSettings.template,
};

export default socialImageGeneratorSettingsSelectors;
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const AutoConversionToggle: React.FC< AutoConversionToggleProps > = ( {

const toggleStatus = useCallback( () => {
const newOption = {
image: ! isEnabled,
enabled: ! isEnabled,
};
updateOptions( newOption );
}, [ isEnabled, updateOptions ] );
Expand Down

0 comments on commit 012eb2c

Please sign in to comment.