@internetarchive/ia-book-actions 0.1.11-b2 → 0.1.11-b4
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
|
*/
|
|
@@ -543,11 +533,11 @@ export default class IABookActions extends LitElement {
|
|
|
543
533
|
const timerCountdown = this._shadowRoot.querySelector('timer-countdown');
|
|
544
534
|
if (!timerCountdown) return;
|
|
545
535
|
|
|
546
|
-
const secondsLeft = Number(this.lendingStatus.secondsLeftOnLoan);
|
|
547
|
-
const strokeDashOffset =
|
|
548
|
-
|
|
536
|
+
const secondsLeft = Number.parseInt((Number(this.lendingStatus.secondsLeftOnLoan)), 10);
|
|
537
|
+
const strokeDashOffset = Number.parseInt(((secondsLeft / this.loanRenewTimeConfig.loanTotalTime) * 315) * 1.5, 10);
|
|
538
|
+
|
|
549
539
|
|
|
550
|
-
|
|
540
|
+
console.log('resetTimerCountState === ', { secondsLeft, strokeDashOffset });
|
|
551
541
|
|
|
552
542
|
// set seconds left in loan expire
|
|
553
543
|
timerCountdown.style?.setProperty('--secondsLeftOnLoan', `${secondsLeft}s`);
|
|
@@ -555,7 +545,7 @@ export default class IABookActions extends LitElement {
|
|
|
555
545
|
// set circle stroke offset left in loan expire
|
|
556
546
|
timerCountdown.style?.setProperty(
|
|
557
547
|
'--strokeLeftOnLoan',
|
|
558
|
-
`${
|
|
548
|
+
`${strokeDashOffset}` // the perimeter of the circle = (π * 2 * radius)
|
|
559
549
|
);
|
|
560
550
|
|
|
561
551
|
const animationCircle = timerCountdown.shadowRoot.querySelector('.circle');
|
|
@@ -584,14 +574,6 @@ export default class IABookActions extends LitElement {
|
|
|
584
574
|
></book-title-bar>`;
|
|
585
575
|
}
|
|
586
576
|
|
|
587
|
-
get timerCountdownTemplate() {
|
|
588
|
-
return this.borrowType === 'browsed'
|
|
589
|
-
? html`<timer-countdown
|
|
590
|
-
.secondsLeftOnLoan=${Number(this.lendingStatus.secondsLeftOnLoan)}
|
|
591
|
-
></timer-countdown>`
|
|
592
|
-
: nothing;
|
|
593
|
-
}
|
|
594
|
-
|
|
595
577
|
get bookActionBar() {
|
|
596
578
|
return html`
|
|
597
579
|
<collapsible-action-group
|
|
@@ -616,7 +598,10 @@ export default class IABookActions extends LitElement {
|
|
|
616
598
|
>
|
|
617
599
|
</collapsible-action-group>
|
|
618
600
|
${this.textGroupTemplate} ${this.infoIconTemplate}
|
|
619
|
-
|
|
601
|
+
<timer-countdown
|
|
602
|
+
.secondsLeftOnLoan=${Number(this.lendingStatus.secondsLeftOnLoan)}
|
|
603
|
+
class=${this.borrowType === 'browsed' ? '' : 'hide'}
|
|
604
|
+
></timer-countdown>
|
|
620
605
|
`;
|
|
621
606
|
}
|
|
622
607
|
|
|
@@ -635,14 +620,26 @@ export default class IABookActions extends LitElement {
|
|
|
635
620
|
console.log('IABookActions: AutoRenewed:- ', {
|
|
636
621
|
ajaxResponse: event?.detail?.data,
|
|
637
622
|
loanRenewResult: this.loanRenewResult,
|
|
638
|
-
secondsLeftOnLoan: Math.round(this.lendingStatus.secondsLeftOnLoan),
|
|
623
|
+
secondsLeftOnLoan: Math.round(this.lendingStatus.secondsLeftOnLoan), // stale? how to fix
|
|
639
624
|
});
|
|
640
625
|
|
|
641
|
-
/**
|
|
642
|
-
* update the lendingStatus property
|
|
643
|
-
*/
|
|
644
|
-
await this.browseHasRenew();
|
|
645
626
|
|
|
627
|
+
// Now, let's reset loan duration & this.lendingStatus
|
|
628
|
+
const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
|
|
629
|
+
const secondsLeft = (loanTime - new Date()) / 1000; // different in seconds
|
|
630
|
+
|
|
631
|
+
const currStatus = {
|
|
632
|
+
...this.lendingStatus,
|
|
633
|
+
user_has_browsed: true,
|
|
634
|
+
browsingExpired: false,
|
|
635
|
+
secondsLeftOnLoan: secondsLeft,
|
|
636
|
+
};
|
|
637
|
+
this.lendingStatus = currStatus;
|
|
638
|
+
|
|
639
|
+
console.log('~~~ handleLoanAutoRenewed - new this.lendingStatus', {
|
|
640
|
+
secondsLeftOnLoan: this.lendingStatus.secondsLeftOnLoan
|
|
641
|
+
});
|
|
642
|
+
|
|
646
643
|
/**
|
|
647
644
|
* reset timer countdown states
|
|
648
645
|
*/
|
|
@@ -673,9 +670,11 @@ export default class IABookActions extends LitElement {
|
|
|
673
670
|
secondsLeft = Math.round(secondsLeft); // round number
|
|
674
671
|
|
|
675
672
|
// re-sync timer if gone off because of background window
|
|
673
|
+
// side effect: updates this.lendingStatus & kicks off lifecycle,
|
|
674
|
+
// if really updated, escape from here
|
|
676
675
|
const resync = await this.reSyncTimerIfGoneOff(secondsLeft);
|
|
677
676
|
|
|
678
|
-
console.log("*** startTimerCountdown ***", secondsLeft, resync);
|
|
677
|
+
console.log("*** startTimerCountdown = reSyncTimerIfGoneOff ***", { secondsLeft, resync });
|
|
679
678
|
|
|
680
679
|
if (resync) {
|
|
681
680
|
console.log('have resyncd, will end startTimerCountdown here - ');
|
|
@@ -948,6 +947,10 @@ export default class IABookActions extends LitElement {
|
|
|
948
947
|
display: block;
|
|
949
948
|
}
|
|
950
949
|
|
|
950
|
+
.hide {
|
|
951
|
+
display: none;
|
|
952
|
+
}
|
|
953
|
+
|
|
951
954
|
.lending-wrapper {
|
|
952
955
|
width: 100%;
|
|
953
956
|
margin: 0 auto;
|