Skip to content

Commit 0e194e7

Browse files
authored
Merge pull request #531 from Codeinwp/fix/issue-508
Update stats when last image section has loaded
2 parents a004ab1 + c022edb commit 0e194e7

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

assets/vue/components/last-images.vue

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
}
8989
this.doProgressBar();
9090
this.$store.dispatch('retrieveOptimizedImages', {waitTime: this.maxTime * 1000, component: this});
91+
this.$store.dispatch('requestStatsUpdate', {waitTime: 0, component: null});
9192
},
9293
watch: {
9394
imageData: function () {

assets/vue/store/actions.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const selectOptimoleDomain = function ( {commit, state}, data ) {
4444
);
4545
}
4646

47-
const connectOptimole = function ( {commit, state}, data ) {
47+
const connectOptimole = function ( {dispatch, commit, state}, data ) {
4848
commit( 'toggleConnecting', true );
4949
commit( 'restApiNotWorking', false );
5050
Vue.http(
@@ -72,7 +72,7 @@ const connectOptimole = function ( {commit, state}, data ) {
7272
commit( 'toggleHasOptmlApp', true );
7373
}
7474

75-
sendOnboardImages();
75+
dispatch( 'sendOnboardImages', [] );
7676

7777
console.log( '%c OptiMole API connection successful.', 'color: #59B278' );
7878

@@ -89,7 +89,7 @@ const connectOptimole = function ( {commit, state}, data ) {
8989
);
9090
};
9191

92-
const registerOptimole = function ( {commit, state}, data ) {
92+
const registerOptimole = function ( {dispatch, commit, state}, data ) {
9393

9494
commit( 'restApiNotWorking', false );
9595
commit( 'toggleConnecting', true );
@@ -117,7 +117,7 @@ const registerOptimole = function ( {commit, state}, data ) {
117117
commit( 'updateApiKey', data.apiKey );
118118
commit( 'updateUserData', response.body.data );
119119
commit( 'updateAvailableApps', response.body.data );
120-
sendOnboardImages();
120+
dispatch( 'sendOnboardImages', {} );
121121
}
122122
return response.data;
123123
},
@@ -287,22 +287,26 @@ const retrieveOptimizedImages = function ( {commit, state}, data ) {
287287
);
288288
};
289289

290-
const sendOnboardImages = function( offset = 0 ) {
290+
const sendOnboardImages = function ( { dispatch }, data ) {
291+
data.offset = undefined !== data.offset ? data.offset : 0;
292+
291293
Vue.http(
292294
{
293295
url: optimoleDashboardApp.routes['upload_onboard_images'],
294296
method: 'POST',
295297
params: {
296-
offset
298+
offset: data.offset
297299
},
298300
emulateJSON: true,
299301
headers: {'X-WP-Nonce': optimoleDashboardApp.nonce},
300302
responseType: 'json'
301303
}
302304
).then(
303305
function ( response ) {
304-
if ( false === response.body.data && offset < 1000 ) {
305-
sendOnboardImages( offset + 50 );
306+
if ( false === response.body.data && data.offset < 1000 ) {
307+
dispatch( 'sendOnboardImages', {
308+
offset: data.offset + 100
309+
} );
306310
}
307311

308312
if ( response.body.code === 'success' ) {
@@ -659,6 +663,7 @@ export default {
659663
retrieveOptimizedImages,
660664
retrieveWatermarks,
661665
sampleRate,
666+
sendOnboardImages,
662667
saveSettings,
663668
callSync,
664669
getOffloadConflicts

0 commit comments

Comments
 (0)