Skip to content

Commit 9671e9e

Browse files
authored
Merge pull request #909 from Codeinwp/feat/single-image-move
Refactor media offload functionality and enhance REST API integration
2 parents a3c513f + 84e92c8 commit 9671e9e

File tree

12 files changed

+675
-367
lines changed

12 files changed

+675
-367
lines changed

assets/js/media.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
jQuery(document).ready(function($) {
2+
jQuery('.move-image-optml').click(function() {
3+
//get the id and send a jquery rest request to the server
4+
var id = jQuery(this).data('id');
5+
var action = jQuery(this).data('action');
6+
moveImage(id, action, jQuery(this));
7+
});
8+
});
9+
10+
function moveImage(id, action, element, is_retry = false) {
11+
//add a loading indicator
12+
element.parent().find('.spinner').addClass('is-active');
13+
element.parent().addClass('is-loading');
14+
jQuery.ajax({
15+
url: optimoleMediaListing.rest_url,
16+
type: 'POST',
17+
headers: {
18+
'X-WP-Nonce': optimoleMediaListing.nonce
19+
},
20+
data: {
21+
action: action,
22+
status: is_retry ? 'check' : 'start',
23+
id: id
24+
},
25+
success: function(response) {
26+
if(response.code === 'moved') {
27+
element.parent().find('.spinner').removeClass('is-active');
28+
element.parent().removeClass('is-loading');
29+
element.parent().find('.move-image-optml').toggleClass('hidden');
30+
31+
}else if(response.code === 'error'){
32+
element.parent().find('.spinner').removeClass('is-active');
33+
element.parent().removeClass('is-loading');
34+
element.parent().text(response.data);
35+
}else{
36+
setTimeout(function() {
37+
moveImage(id, action, element, true);
38+
}, 1000);
39+
}
40+
}
41+
});
42+
}

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

Lines changed: 0 additions & 21 deletions
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 ) {

0 commit comments

Comments
 (0)