@internetarchive/ia-book-actions 0.1.11-b5 → 0.1.11-b6
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 +1 -1
- package/src/ia-book-actions.js +43 -18
package/package.json
CHANGED
package/src/ia-book-actions.js
CHANGED
|
@@ -105,7 +105,7 @@ export default class IABookActions extends LitElement {
|
|
|
105
105
|
* loanTotalTime: number, - total seconds a loan does have
|
|
106
106
|
* loanRenewAtLast: number, - check for loan renew at last
|
|
107
107
|
* pageChangedInLast: number, - consider loan renew eligible if viewed new page
|
|
108
|
-
|
|
108
|
+
*/
|
|
109
109
|
this.loanRenewTimeConfig = {
|
|
110
110
|
loanTotalTime: 3600, // 1 hour
|
|
111
111
|
loanRenewAtLast: 660, // 11 minutes
|
|
@@ -257,7 +257,9 @@ export default class IABookActions extends LitElement {
|
|
|
257
257
|
// initial timer state for 1-hour loan
|
|
258
258
|
if (this.borrowType === 'browsed' && !this.loanRenewResult.renewNow) {
|
|
259
259
|
setTimeout(() => {
|
|
260
|
-
console.log(
|
|
260
|
+
console.log(
|
|
261
|
+
'IN TIMEOUT OF --- setupLendingToolbarActions, firing resetTimerCountState'
|
|
262
|
+
);
|
|
261
263
|
this.resetTimerCountState();
|
|
262
264
|
}, 100);
|
|
263
265
|
}
|
|
@@ -349,10 +351,7 @@ export default class IABookActions extends LitElement {
|
|
|
349
351
|
<div id="custom-buttons" style="display:flex;justify-content:center;">
|
|
350
352
|
<button
|
|
351
353
|
style="${modalButtonStyle.iaButton} ${modalButtonStyle.renew}"
|
|
352
|
-
@click=${
|
|
353
|
-
await this.changeModalState(event);
|
|
354
|
-
this.loanRenewResult = { texts: '', renewNow: true };
|
|
355
|
-
}}
|
|
354
|
+
@click=${event => this.patronWantsToRenewBook(event)}
|
|
356
355
|
>
|
|
357
356
|
Keep reading
|
|
358
357
|
</button>
|
|
@@ -371,6 +370,11 @@ export default class IABookActions extends LitElement {
|
|
|
371
370
|
this.modal?.showModal({ config, customModalContent: customContent });
|
|
372
371
|
}
|
|
373
372
|
|
|
373
|
+
async patronWantsToRenewBook(event) {
|
|
374
|
+
await this.changeModalState(event);
|
|
375
|
+
this.loanRenewResult = { texts: '', renewNow: true };
|
|
376
|
+
}
|
|
377
|
+
|
|
374
378
|
/**
|
|
375
379
|
* helper function to change button click states on modal-manager
|
|
376
380
|
* - add loader on button click
|
|
@@ -379,9 +383,11 @@ export default class IABookActions extends LitElement {
|
|
|
379
383
|
* @param {Event} event
|
|
380
384
|
*/
|
|
381
385
|
changeModalState(event) {
|
|
386
|
+
// this doesn't really work? shows empty button
|
|
382
387
|
if (event.target === undefined) return;
|
|
383
388
|
|
|
384
389
|
const button = event.target;
|
|
390
|
+
button.disabled = true;
|
|
385
391
|
button.innerHTML = `<ia-activity-indicator
|
|
386
392
|
mode="processing"
|
|
387
393
|
style=${modalButtonStyle.loaderIcon}
|
|
@@ -508,7 +514,11 @@ export default class IABookActions extends LitElement {
|
|
|
508
514
|
|
|
509
515
|
async startBrowseTimer() {
|
|
510
516
|
clearTimeout(this.browseTimer);
|
|
511
|
-
console.log(
|
|
517
|
+
console.log(
|
|
518
|
+
'startBrowseTimerstartBrowseTimer just cleared timer',
|
|
519
|
+
this.browseTimer,
|
|
520
|
+
this.lendingStatus
|
|
521
|
+
);
|
|
512
522
|
|
|
513
523
|
const {
|
|
514
524
|
browsingExpired,
|
|
@@ -521,7 +531,10 @@ export default class IABookActions extends LitElement {
|
|
|
521
531
|
}
|
|
522
532
|
|
|
523
533
|
this.browseTimer = setTimeout(() => {
|
|
524
|
-
console.log(
|
|
534
|
+
console.log(
|
|
535
|
+
'start `this.browseTimer will fire his.browseHasExpired() - secondsLeftOnLoan',
|
|
536
|
+
secondsLeftOnLoan
|
|
537
|
+
);
|
|
525
538
|
this.browseHasExpired();
|
|
526
539
|
}, secondsLeftOnLoan * 1000);
|
|
527
540
|
}
|
|
@@ -533,12 +546,22 @@ export default class IABookActions extends LitElement {
|
|
|
533
546
|
const timerCountdown = this._shadowRoot.querySelector('timer-countdown');
|
|
534
547
|
if (!timerCountdown) return;
|
|
535
548
|
|
|
536
|
-
const secondsLeft = Number.parseInt(
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
549
|
+
const secondsLeft = Number.parseInt(
|
|
550
|
+
Number(this.lendingStatus.secondsLeftOnLoan),
|
|
551
|
+
10
|
|
552
|
+
);
|
|
553
|
+
const firstStrokeDashOffset = Number.parseInt(
|
|
554
|
+
(secondsLeft / this.loanRenewTimeConfig.loanTotalTime) * 315 * 1.5,
|
|
555
|
+
10
|
|
556
|
+
);
|
|
557
|
+
const actualStrokeDashOffset =
|
|
558
|
+
firstStrokeDashOffset > 315 ? 315 : firstStrokeDashOffset;
|
|
540
559
|
|
|
541
|
-
console.log('resetTimerCountState === ', {
|
|
560
|
+
console.log('resetTimerCountState === ', {
|
|
561
|
+
secondsLeft,
|
|
562
|
+
firstStrokeDashOffset,
|
|
563
|
+
actualStrokeDashOffset,
|
|
564
|
+
});
|
|
542
565
|
|
|
543
566
|
// set seconds left in loan expire
|
|
544
567
|
timerCountdown.style?.setProperty('--secondsLeftOnLoan', `${secondsLeft}s`);
|
|
@@ -624,11 +647,10 @@ export default class IABookActions extends LitElement {
|
|
|
624
647
|
secondsLeftOnLoan: Math.round(this.lendingStatus.secondsLeftOnLoan), // stale? how to fix
|
|
625
648
|
});
|
|
626
649
|
|
|
627
|
-
|
|
628
650
|
// Now, let's reset loan duration & this.lendingStatus
|
|
629
651
|
const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
|
|
630
652
|
const secondsLeft = (loanTime - new Date()) / 1000; // different in seconds
|
|
631
|
-
|
|
653
|
+
|
|
632
654
|
const currStatus = {
|
|
633
655
|
...this.lendingStatus,
|
|
634
656
|
user_has_browsed: true,
|
|
@@ -638,9 +660,9 @@ export default class IABookActions extends LitElement {
|
|
|
638
660
|
this.lendingStatus = currStatus;
|
|
639
661
|
|
|
640
662
|
console.log('~~~ handleLoanAutoRenewed - new this.lendingStatus', {
|
|
641
|
-
secondsLeftOnLoan: this.lendingStatus.secondsLeftOnLoan
|
|
663
|
+
secondsLeftOnLoan: this.lendingStatus.secondsLeftOnLoan,
|
|
642
664
|
});
|
|
643
|
-
|
|
665
|
+
|
|
644
666
|
/**
|
|
645
667
|
* reset timer countdown states
|
|
646
668
|
*/
|
|
@@ -675,7 +697,10 @@ export default class IABookActions extends LitElement {
|
|
|
675
697
|
// if really updated, escape from here
|
|
676
698
|
const resync = await this.reSyncTimerIfGoneOff(secondsLeft);
|
|
677
699
|
|
|
678
|
-
console.log(
|
|
700
|
+
console.log('*** startTimerCountdown = reSyncTimerIfGoneOff ***', {
|
|
701
|
+
secondsLeft,
|
|
702
|
+
resync,
|
|
703
|
+
});
|
|
679
704
|
|
|
680
705
|
if (resync) {
|
|
681
706
|
console.log('have resyncd, will end startTimerCountdown here - ');
|