Skip to content

Commit fe5fdb0

Browse files
Merge pull request #154 from wp-slimstat/fix/153-refresh-button-timer
Fix refresh button not resetting countdown timer (#153)
2 parents 85274be + 38f4ca5 commit fe5fdb0

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

admin/assets/js/admin.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,7 @@ jQuery(function () {
13831383
// ----- BEGIN: SLIMSTATADMIN HELPER FUNCTIONS ---------------------------------------
13841384
var SlimStatAdmin = {
13851385
refresh_handle: null,
1386+
_lastManualRefreshTime: 0,
13861387

13871388
refresh_report: function (id) {
13881389
return function () {
@@ -1393,7 +1394,7 @@ var SlimStatAdmin = {
13931394

13941395
// Clear the autorefresh timer, if set
13951396
if (SlimStatAdmin.refresh_handle != null) {
1396-
clearTimeout(SlimStatAdmin.refresh_handle);
1397+
clearInterval(SlimStatAdmin.refresh_handle);
13971398
}
13981399

13991400
data = {
@@ -1446,7 +1447,7 @@ var SlimStatAdmin = {
14461447
});
14471448

14481449
if (id == "slim_p7_02") {
1449-
SlimStatAdmin._refresh_timer = SlimStatAdminParams.refresh_interval;
1450+
SlimStatAdmin._lastManualRefreshTime = Date.now();
14501451
}
14511452
}
14521453
})
@@ -1466,6 +1467,15 @@ var SlimStatAdmin = {
14661467
var currentSeconds = now.getSeconds();
14671468
var currentMinute = now.getMinutes();
14681469

1470+
// Check if a manual refresh happened recently (within 2 seconds)
1471+
var timeSinceManualRefresh = Date.now() - SlimStatAdmin._lastManualRefreshTime;
1472+
if (timeSinceManualRefresh < 2000) {
1473+
jQuery(".refresh-timer").html("0:00");
1474+
// Reset the trigger minute to sync with the wall clock after manual refresh
1475+
lastTriggerMinute = -1;
1476+
return;
1477+
}
1478+
14691479
// Trigger pulse at exactly :00 of a new minute
14701480
if (currentSeconds === 0 && lastTriggerMinute !== currentMinute) {
14711481
lastTriggerMinute = currentMinute;

0 commit comments

Comments
 (0)