Skip to content

Commit e6ef871

Browse files
committed
Refactor connected components to streamline media offload logic
- Removed redundant image handling from the ConnectedLayout and OffloadMedia components. - Simplified the callSync function by eliminating unnecessary image parameters. - Enhanced clarity and maintainability of the codebase by reducing complexity in state management and effect hooks.
1 parent 52ebcd9 commit e6ef871

File tree

3 files changed

+4
-43
lines changed

3 files changed

+4
-43
lines changed

assets/src/dashboard/parts/connected/index.js

-21
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,6 @@ const ConnectedLayout = ({
6464
const [ canSave, setCanSave ] = useState( false );
6565
const [ settings, setSettings ] = useState( siteSettings );
6666

67-
useEffect( () => {
68-
const urlSearchParams = new URLSearchParams( window.location.search );
69-
const params = Object.fromEntries( urlSearchParams.entries() );
70-
let images = [];
71-
72-
if ( Object.prototype.hasOwnProperty.call( params, 'optimole_action' ) ) {
73-
for ( let i = 0; 20 > i; i++ ) {
74-
if ( Object.prototype.hasOwnProperty.call( params, i ) ) {
75-
if ( ! isNaN( params[i]) ) {
76-
images[i] = parseInt( params[i], 10 );
77-
}
78-
}
79-
}
80-
81-
params.images = images;
82-
params.url = window.location.href.split( '?' )[0] + ( Object.prototype.hasOwnProperty.call( params, 'paged' ) ? '?paged=' + params.paged : '' );
83-
setQueryArgs( params );
84-
setTab( 'settings' );
85-
setMenu( 'offload_media' );
86-
}
87-
}, []);
8867

8968
useEffect( () => {
9069
if ( isConnected && hasApplication ) {

assets/src/dashboard/parts/connected/settings/OffloadMedia.js

+2-17
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,6 @@ const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
8282
const isOffloadingInProgress = 'disabled' !== settings['offloading_status'];
8383
const isRollbackInProgress = 'disabled' !== settings['rollback_status'];
8484

85-
useEffect( () => {
86-
if ( ! queryArgs?.optimole_action || ! queryArgs?.images ) {
87-
return;
88-
}
89-
90-
if ( 'offload_images' === queryArgs.optimole_action ) {
91-
onOffloadMedia( queryArgs.images );
92-
}
93-
94-
if ( 'rollback_images' === queryArgs.optimole_action ) {
95-
onRollbackdMedia( queryArgs.images );
96-
}
97-
}, []);
9885

9986
useEffect( () => {
10087
if ( isOffloadingInProgress ) {
@@ -126,8 +113,7 @@ const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
126113
setOffloadLimitReached( false );
127114

128115
callSync({
129-
action: 'offload_images',
130-
images: imageIds
116+
action: 'offload_images'
131117
});
132118

133119
setCanSave( false );
@@ -148,8 +134,7 @@ const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
148134
setProcessedImages( 0 );
149135

150136
callSync({
151-
action: 'rollback_images',
152-
images: imageIds
137+
action: 'rollback_images'
153138
});
154139

155140
setCanSave( false );

assets/src/dashboard/utils/api.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -497,15 +497,13 @@ export const callSync = ( data ) => {
497497

498498
setIsLoading( true );
499499

500-
const images_ids = undefined !== data.images ? data.images : [];
501500

502501
apiFetch({
503502
path: optimoleDashboardApp.routes['number_of_images_and_pages'],
504503
method: 'POST',
505504
data: {
506505
action: data.action,
507-
refresh: data.refresh || false,
508-
images: images_ids
506+
refresh: data.refresh || false
509507
},
510508
parse: false
511509
})
@@ -577,8 +575,7 @@ export const callSync = ( data ) => {
577575
setTimeout( () => {
578576
callSync({
579577
action: data.action,
580-
refresh: true,
581-
images: images_ids
578+
refresh: true
582579
});
583580
}, 10000 );
584581
})

0 commit comments

Comments
 (0)