@internetarchive/ia-book-actions 0.1.11-b4 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.1.11-b4",
3
+ "version": "0.1.11-b6",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -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('IN TIMEOUT OF --- setupLendingToolbarActions, firing resetTimerCountState');
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=${async event => {
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('startBrowseTimerstartBrowseTimer just cleared timer', this.browseTimer, this.lendingStatus);
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('start `this.browseTimer will fire his.browseHasExpired() - secondsLeftOnLoan', secondsLeftOnLoan);
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,11 +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((Number(this.lendingStatus.secondsLeftOnLoan)), 10);
537
- const strokeDashOffset = Number.parseInt(((secondsLeft / this.loanRenewTimeConfig.loanTotalTime) * 315) * 1.5, 10);
538
-
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;
539
559
 
540
- console.log('resetTimerCountState === ', { secondsLeft, strokeDashOffset });
560
+ console.log('resetTimerCountState === ', {
561
+ secondsLeft,
562
+ firstStrokeDashOffset,
563
+ actualStrokeDashOffset,
564
+ });
541
565
 
542
566
  // set seconds left in loan expire
543
567
  timerCountdown.style?.setProperty('--secondsLeftOnLoan', `${secondsLeft}s`);
@@ -545,7 +569,7 @@ export default class IABookActions extends LitElement {
545
569
  // set circle stroke offset left in loan expire
546
570
  timerCountdown.style?.setProperty(
547
571
  '--strokeLeftOnLoan',
548
- `${strokeDashOffset}` // the perimeter of the circle = (π * 2 * radius)
572
+ `${actualStrokeDashOffset}` // the perimeter of the circle = (π * 2 * radius)
549
573
  );
550
574
 
551
575
  const animationCircle = timerCountdown.shadowRoot.querySelector('.circle');
@@ -623,11 +647,10 @@ export default class IABookActions extends LitElement {
623
647
  secondsLeftOnLoan: Math.round(this.lendingStatus.secondsLeftOnLoan), // stale? how to fix
624
648
  });
625
649
 
626
-
627
650
  // Now, let's reset loan duration & this.lendingStatus
628
651
  const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
629
652
  const secondsLeft = (loanTime - new Date()) / 1000; // different in seconds
630
-
653
+
631
654
  const currStatus = {
632
655
  ...this.lendingStatus,
633
656
  user_has_browsed: true,
@@ -637,9 +660,9 @@ export default class IABookActions extends LitElement {
637
660
  this.lendingStatus = currStatus;
638
661
 
639
662
  console.log('~~~ handleLoanAutoRenewed - new this.lendingStatus', {
640
- secondsLeftOnLoan: this.lendingStatus.secondsLeftOnLoan
663
+ secondsLeftOnLoan: this.lendingStatus.secondsLeftOnLoan,
641
664
  });
642
-
665
+
643
666
  /**
644
667
  * reset timer countdown states
645
668
  */
@@ -674,7 +697,10 @@ export default class IABookActions extends LitElement {
674
697
  // if really updated, escape from here
675
698
  const resync = await this.reSyncTimerIfGoneOff(secondsLeft);
676
699
 
677
- console.log("*** startTimerCountdown = reSyncTimerIfGoneOff ***", { secondsLeft, resync });
700
+ console.log('*** startTimerCountdown = reSyncTimerIfGoneOff ***', {
701
+ secondsLeft,
702
+ resync,
703
+ });
678
704
 
679
705
  if (resync) {
680
706
  console.log('have resyncd, will end startTimerCountdown here - ');