@internetarchive/ia-book-actions 1.1.0-alpha6 → 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
|
|
|
@@ -390,7 +390,6 @@
|
|
|
390
390
|
</div>
|
|
391
391
|
<div>
|
|
392
392
|
<button id="show_expired_modal">While Browsing (`user_has_browsed`), Expire book & show its modal</button>
|
|
393
|
-
how_expired_modal
|
|
394
393
|
</div>
|
|
395
394
|
</td>
|
|
396
395
|
<td class="availableToBorrow">
|
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
|
/**
|
|
@@ -315,7 +326,7 @@ export default class IABookActions extends LitElement {
|
|
|
315
326
|
}
|
|
316
327
|
|
|
317
328
|
/**
|
|
318
|
-
* Show the
|
|
329
|
+
* Show the waring modal to ask user if they are still reading
|
|
319
330
|
*/
|
|
320
331
|
async showWarningModal() {
|
|
321
332
|
log('****** showWarningModal ******');
|
|
@@ -494,29 +505,28 @@ export default class IABookActions extends LitElement {
|
|
|
494
505
|
* - show message when book is expired
|
|
495
506
|
* - show message having remaining time when book is about to auto returned
|
|
496
507
|
*/
|
|
497
|
-
async showToastMessage() {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
}
|
|
508
|
+
// async showToastMessage() {
|
|
509
|
+
// await this.useToastManager();
|
|
510
|
+
|
|
511
|
+
// // if secondsLeft < 60, consider it 1 minute
|
|
512
|
+
// let { secondsLeft } = this.loanRenewResult;
|
|
513
|
+
// if (secondsLeft === undefined) {
|
|
514
|
+
// secondsLeft = this.lendingStatus.secondsLeftOnLoan;
|
|
515
|
+
// } else {
|
|
516
|
+
// secondsLeft = secondsLeft > 60 ? secondsLeft : 60;
|
|
517
|
+
// }
|
|
518
|
+
|
|
519
|
+
// const config = new ToastConfig();
|
|
520
|
+
// config.dismisOnClick = true;
|
|
521
|
+
// config.texts = this.loanRenewHelper?.getMessageTexts(
|
|
522
|
+
// this.loanRenewResult.texts,
|
|
523
|
+
// secondsLeft
|
|
524
|
+
// );
|
|
525
|
+
|
|
526
|
+
// this.toast?.showToast({
|
|
527
|
+
// config,
|
|
528
|
+
// });
|
|
529
|
+
// }
|
|
520
530
|
|
|
521
531
|
/**
|
|
522
532
|
* Execute when loan is expired
|
|
@@ -688,20 +698,21 @@ export default class IABookActions extends LitElement {
|
|
|
688
698
|
// re-sync timer if gone off because of background window
|
|
689
699
|
// side effect: updates this.lendingStatus & kicks off lifecycle,
|
|
690
700
|
// if really updated, escape from here
|
|
691
|
-
const
|
|
701
|
+
const resyncd = this.reSyncTimerIfGoneOff(secondsLeft);
|
|
702
|
+
|
|
703
|
+
if (resyncd.hasSynced) {
|
|
704
|
+
secondsLeft = resyncd.whatShouldLeft;
|
|
692
705
|
|
|
693
|
-
if (resync) {
|
|
694
706
|
log('startTimerCountdown --- stale, timer has resyncd', {
|
|
695
707
|
secondsLeft,
|
|
696
708
|
});
|
|
697
|
-
return;
|
|
698
709
|
}
|
|
699
710
|
|
|
700
711
|
log('startTimerCountdown --- countdown still valid. continue...', {
|
|
701
|
-
|
|
712
|
+
resyncd,
|
|
702
713
|
secondsLeft,
|
|
703
714
|
loanRenewAtLast: this.loanRenewTimeConfig.loanRenewAtLast,
|
|
704
|
-
});
|
|
715
|
+
}, new Date().getMinutes(), new Date().getSeconds());
|
|
705
716
|
|
|
706
717
|
/**
|
|
707
718
|
* execute from last 10th minute to 0th minute
|
|
@@ -762,9 +773,9 @@ export default class IABookActions extends LitElement {
|
|
|
762
773
|
if (whatIsleft !== whatShouldLeft) {
|
|
763
774
|
log(`reSyncTimerIfGoneOff --- let's re-sync.`);
|
|
764
775
|
|
|
765
|
-
return true;
|
|
776
|
+
return { hasSynced: true, whatShouldLeft };
|
|
766
777
|
}
|
|
767
|
-
return false;
|
|
778
|
+
return { hasSynced: false, whatShouldLeft };
|
|
768
779
|
}
|
|
769
780
|
|
|
770
781
|
/**
|