@internetarchive/ia-book-actions 1.1.0-alpha7 → 1.1.0-alpha8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/demo/index.html
CHANGED
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
iaBookActions.returnUrl = '';
|
|
132
132
|
iaBookActions.localCache = localCache;
|
|
133
133
|
|
|
134
|
-
let loanTotalTime2Min = { loanTotalTime:
|
|
134
|
+
let loanTotalTime2Min = { loanTotalTime: 170, loanRenewAtLast: 80, pageChangedInLast: 15 };
|
|
135
135
|
let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 180, pageChangedInLast: 15 };
|
|
136
136
|
let loanTotalTime1Hour = { loanTotalTime: 3600, loanRenewAtLast: 660, pageChangedInLast: 900 };
|
|
137
137
|
|
package/package.json
CHANGED
|
@@ -118,7 +118,7 @@ export const canBrowseAndBorrow = {
|
|
|
118
118
|
loanStartDate: '2021-07-30 09:57:40',
|
|
119
119
|
loansUrl: '/details/@neeraj-archive?tab=loans#loans-on-loan',
|
|
120
120
|
maxLoans: 10,
|
|
121
|
-
secondsLeftOnLoan:
|
|
121
|
+
secondsLeftOnLoan: 170,
|
|
122
122
|
shouldProtectImages: true,
|
|
123
123
|
totalWaitlistCount: 0,
|
|
124
124
|
userHasBorrowed: false,
|
package/src/ia-book-actions.js
CHANGED
|
@@ -90,7 +90,7 @@ export default class IABookActions extends LitElement {
|
|
|
90
90
|
this.lendingOptions = {};
|
|
91
91
|
this.borrowType = null; // 'browsed'|'borrowed'
|
|
92
92
|
this.browseTimer = undefined; // timeout
|
|
93
|
-
this.timerExecutionSeconds =
|
|
93
|
+
this.timerExecutionSeconds = 5;
|
|
94
94
|
|
|
95
95
|
/** @deprecated */
|
|
96
96
|
this.toast = undefined;
|
|
@@ -283,6 +283,17 @@ export default class IABookActions extends LitElement {
|
|
|
283
283
|
this.autoLoanRenewChecker(true);
|
|
284
284
|
}
|
|
285
285
|
});
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* auto-renew interval may stale when tab is in background,
|
|
289
|
+
* so [visibilitychange] event can trigger to check timer to show relavent messages
|
|
290
|
+
*/
|
|
291
|
+
document.addEventListener("visibilitychange", () => {
|
|
292
|
+
log('visibilitychange');
|
|
293
|
+
if (!document.hidden) {
|
|
294
|
+
this.startTimerCountdown();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
286
297
|
}
|
|
287
298
|
|
|
288
299
|
/**
|
|
@@ -687,17 +698,21 @@ export default class IABookActions extends LitElement {
|
|
|
687
698
|
// re-sync timer if gone off because of background window
|
|
688
699
|
// side effect: updates this.lendingStatus & kicks off lifecycle,
|
|
689
700
|
// if really updated, escape from here
|
|
690
|
-
const
|
|
701
|
+
const resyncd = this.reSyncTimerIfGoneOff(secondsLeft);
|
|
702
|
+
|
|
703
|
+
if (resyncd.hasSynced) {
|
|
704
|
+
secondsLeft = resyncd.whatShouldLeft;
|
|
691
705
|
|
|
692
|
-
|
|
693
|
-
|
|
706
|
+
log('startTimerCountdown --- stale, timer has resyncd', {
|
|
707
|
+
secondsLeft,
|
|
708
|
+
});
|
|
694
709
|
}
|
|
695
710
|
|
|
696
711
|
log('startTimerCountdown --- countdown still valid. continue...', {
|
|
697
|
-
|
|
712
|
+
resyncd,
|
|
698
713
|
secondsLeft,
|
|
699
714
|
loanRenewAtLast: this.loanRenewTimeConfig.loanRenewAtLast,
|
|
700
|
-
});
|
|
715
|
+
}, new Date().getMinutes(), new Date().getSeconds());
|
|
701
716
|
|
|
702
717
|
/**
|
|
703
718
|
* execute from last 10th minute to 0th minute
|
|
@@ -739,26 +754,28 @@ export default class IABookActions extends LitElement {
|
|
|
739
754
|
const whatShouldLeft = Math.round(secondsShouldLeft);
|
|
740
755
|
const timerElSeconds = this.timerCountdownEl.secondsLeftOnLoan || 0;
|
|
741
756
|
|
|
742
|
-
|
|
757
|
+
log(`reSyncTimerIfGoneOff?`, {
|
|
758
|
+
whatIsleft,
|
|
759
|
+
whatShouldLeft,
|
|
760
|
+
timerElSeconds,
|
|
761
|
+
timeLeftInMin: Math.ceil(timerSecondsLeft / 60),
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
if (timerElSeconds !== whatShouldLeft || whatIsleft !== whatShouldLeft) {
|
|
743
765
|
// set lending status with new time to update decrementor
|
|
744
766
|
const currStatus = {
|
|
745
767
|
...this.lendingStatus,
|
|
746
768
|
secondsLeftOnLoan: whatShouldLeft,
|
|
747
769
|
};
|
|
748
770
|
this.lendingStatus = currStatus;
|
|
771
|
+
}
|
|
749
772
|
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
whatShouldLeft,
|
|
753
|
-
timerElSeconds,
|
|
754
|
-
timeLeftInMin: Math.ceil(timerSecondsLeft / 60),
|
|
755
|
-
}, '\ntimer resyncd --- ', {
|
|
756
|
-
whatShouldLeft,
|
|
757
|
-
});
|
|
773
|
+
if (whatIsleft !== whatShouldLeft) {
|
|
774
|
+
log(`reSyncTimerIfGoneOff --- let's re-sync.`);
|
|
758
775
|
|
|
759
|
-
return {
|
|
776
|
+
return { hasSynced: true, whatShouldLeft };
|
|
760
777
|
}
|
|
761
|
-
return {
|
|
778
|
+
return { hasSynced: false, whatShouldLeft };
|
|
762
779
|
}
|
|
763
780
|
|
|
764
781
|
/**
|