@internetarchive/ia-book-actions 0.1.11-b1 → 0.1.11-b3
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/package.json
CHANGED
|
@@ -300,6 +300,7 @@ export default class ActionsHandler extends LitElement {
|
|
|
300
300
|
* set browse time in indexedDB
|
|
301
301
|
*/
|
|
302
302
|
async setBrowseTimeSession() {
|
|
303
|
+
// TODO: USE loan info to determine what we have left
|
|
303
304
|
try {
|
|
304
305
|
const expireDate = new Date(
|
|
305
306
|
new Date().getTime() + this.loanTotalTime * 1000
|
package/src/ia-book-actions.js
CHANGED
|
@@ -100,13 +100,17 @@ export default class IABookActions extends LitElement {
|
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* contains one hour auto-loan-renew time configuration
|
|
103
|
-
*
|
|
104
|
-
* @type {
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
|
|
109
|
-
this.loanRenewTimeConfig = {
|
|
103
|
+
* defaults to 1 hour config
|
|
104
|
+
* @type {{
|
|
105
|
+
* loanTotalTime: number, - total seconds a loan does have
|
|
106
|
+
* loanRenewAtLast: number, - check for loan renew at last
|
|
107
|
+
* pageChangedInLast: number, - consider loan renew eligible if viewed new page
|
|
108
|
+
*/
|
|
109
|
+
this.loanRenewTimeConfig = {
|
|
110
|
+
loanTotalTime: 3600, // 1 hour
|
|
111
|
+
loanRenewAtLast: 660, // 11 minutes
|
|
112
|
+
pageChangedInLast: 900, // 15 minutes
|
|
113
|
+
};
|
|
110
114
|
|
|
111
115
|
/**
|
|
112
116
|
* contains one hour auto-loan-renew response
|
|
@@ -253,6 +257,7 @@ export default class IABookActions extends LitElement {
|
|
|
253
257
|
// initial timer state for 1-hour loan
|
|
254
258
|
if (this.borrowType === 'browsed' && !this.loanRenewResult.renewNow) {
|
|
255
259
|
setTimeout(() => {
|
|
260
|
+
console.log('IN TIMEOUT OF --- setupLendingToolbarActions, firing resetTimerCountState');
|
|
256
261
|
this.resetTimerCountState();
|
|
257
262
|
}, 100);
|
|
258
263
|
}
|
|
@@ -478,21 +483,6 @@ export default class IABookActions extends LitElement {
|
|
|
478
483
|
});
|
|
479
484
|
}
|
|
480
485
|
|
|
481
|
-
async browseHasRenew() {
|
|
482
|
-
window?.IALendingIntervals?.clearAll();
|
|
483
|
-
|
|
484
|
-
const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
|
|
485
|
-
const secondsLeft = (loanTime - new Date()) / 1000; // different in seconds
|
|
486
|
-
|
|
487
|
-
const currStatus = {
|
|
488
|
-
...this.lendingStatus,
|
|
489
|
-
user_has_browsed: true,
|
|
490
|
-
browsingExpired: false,
|
|
491
|
-
secondsLeftOnLoan: secondsLeft,
|
|
492
|
-
};
|
|
493
|
-
this.lendingStatus = currStatus;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
486
|
/**
|
|
497
487
|
* Execute when loan is expired
|
|
498
488
|
*/
|
|
@@ -518,6 +508,7 @@ export default class IABookActions extends LitElement {
|
|
|
518
508
|
|
|
519
509
|
async startBrowseTimer() {
|
|
520
510
|
clearTimeout(this.browseTimer);
|
|
511
|
+
console.log('startBrowseTimerstartBrowseTimer just cleared timer', this.browseTimer, this.lendingStatus);
|
|
521
512
|
|
|
522
513
|
const {
|
|
523
514
|
browsingExpired,
|
|
@@ -530,6 +521,7 @@ export default class IABookActions extends LitElement {
|
|
|
530
521
|
}
|
|
531
522
|
|
|
532
523
|
this.browseTimer = setTimeout(() => {
|
|
524
|
+
console.log('start `this.browseTimer will fire his.browseHasExpired() - secondsLeftOnLoan', secondsLeftOnLoan);
|
|
533
525
|
this.browseHasExpired();
|
|
534
526
|
}, secondsLeftOnLoan * 1000);
|
|
535
527
|
}
|
|
@@ -541,10 +533,12 @@ export default class IABookActions extends LitElement {
|
|
|
541
533
|
const timerCountdown = this._shadowRoot.querySelector('timer-countdown');
|
|
542
534
|
if (!timerCountdown) return;
|
|
543
535
|
|
|
544
|
-
const secondsLeft = Number(this.lendingStatus.secondsLeftOnLoan);
|
|
536
|
+
const secondsLeft = Number.parseInt((Number(this.lendingStatus.secondsLeftOnLoan)), 10);
|
|
545
537
|
const strokeDashOffset =
|
|
546
538
|
(secondsLeft / this.loanRenewTimeConfig.loanTotalTime) * 315;
|
|
547
539
|
|
|
540
|
+
console.log('resetTimerCountState === ', { secondsLeft, strokeDashOffset});
|
|
541
|
+
|
|
548
542
|
// set seconds left in loan expire
|
|
549
543
|
timerCountdown.style?.setProperty('--secondsLeftOnLoan', `${secondsLeft}s`);
|
|
550
544
|
|
|
@@ -631,14 +625,26 @@ export default class IABookActions extends LitElement {
|
|
|
631
625
|
console.log('IABookActions: AutoRenewed:- ', {
|
|
632
626
|
ajaxResponse: event?.detail?.data,
|
|
633
627
|
loanRenewResult: this.loanRenewResult,
|
|
634
|
-
secondsLeftOnLoan: Math.round(this.lendingStatus.secondsLeftOnLoan),
|
|
628
|
+
secondsLeftOnLoan: Math.round(this.lendingStatus.secondsLeftOnLoan), // stale? how to fix
|
|
635
629
|
});
|
|
636
630
|
|
|
637
|
-
/**
|
|
638
|
-
* update the lendingStatus property
|
|
639
|
-
*/
|
|
640
|
-
await this.browseHasRenew();
|
|
641
631
|
|
|
632
|
+
// Now, let's reset loan duration & this.lendingStatus
|
|
633
|
+
const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
|
|
634
|
+
const secondsLeft = (loanTime - new Date()) / 1000; // different in seconds
|
|
635
|
+
|
|
636
|
+
const currStatus = {
|
|
637
|
+
...this.lendingStatus,
|
|
638
|
+
user_has_browsed: true,
|
|
639
|
+
browsingExpired: false,
|
|
640
|
+
secondsLeftOnLoan: secondsLeft,
|
|
641
|
+
};
|
|
642
|
+
this.lendingStatus = currStatus;
|
|
643
|
+
|
|
644
|
+
console.log('~~~ handleLoanAutoRenewed - new this.lendingStatus', {
|
|
645
|
+
secondsLeftOnLoan: this.lendingStatus.secondsLeftOnLoan
|
|
646
|
+
});
|
|
647
|
+
|
|
642
648
|
/**
|
|
643
649
|
* reset timer countdown states
|
|
644
650
|
*/
|
|
@@ -669,9 +675,11 @@ export default class IABookActions extends LitElement {
|
|
|
669
675
|
secondsLeft = Math.round(secondsLeft); // round number
|
|
670
676
|
|
|
671
677
|
// re-sync timer if gone off because of background window
|
|
678
|
+
// side effect: updates this.lendingStatus & kicks off lifecycle,
|
|
679
|
+
// if really updated, escape from here
|
|
672
680
|
const resync = await this.reSyncTimerIfGoneOff(secondsLeft);
|
|
673
681
|
|
|
674
|
-
console.log("*** startTimerCountdown ***", secondsLeft, resync);
|
|
682
|
+
console.log("*** startTimerCountdown = reSyncTimerIfGoneOff ***", { secondsLeft, resync });
|
|
675
683
|
|
|
676
684
|
if (resync) {
|
|
677
685
|
console.log('have resyncd, will end startTimerCountdown here - ');
|