@internetarchive/ia-book-actions 0.1.11-b39 → 0.1.11-b40

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,11 +131,11 @@
131
131
  iaBookActions.returnUrl = '';
132
132
  iaBookActions.localCache = localCache;
133
133
 
134
- let loanTotalTime2Min = { loanTotalTime: 65, loanRenewAtLast: 60, pageChangedInLast: 15 };
134
+ let loanTotalTime2Min = { loanTotalTime: 65, loanRenewAtLast: 60, pageChangedInLast: 30 };
135
135
  let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 180, pageChangedInLast: 15 };
136
136
  let loanTotalTime1Hour = { loanTotalTime: 3600, loanRenewAtLast: 660, pageChangedInLast: 900 };
137
137
 
138
- iaBookActions.loanRenewTimeConfig = loanTotalTime2Min;
138
+ iaBookActions.loanRenewTimeConfig = loanTotalTime5Min;
139
139
 
140
140
  let lendingStatus1 = iaBookActions.lendingStatus;
141
141
  let secondsLeftOnLoan = iaBookActions.loanRenewTimeConfig.loanTotalTime;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.1.11-b39",
3
+ "version": "0.1.11-b40",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -47,6 +47,9 @@ export default class TimerCountdown extends LitElement {
47
47
  }
48
48
 
49
49
  render() {
50
+ console.log('~~~~~~~');
51
+ console.log('render -- timer-countdown', this.secondsLeftOnLoan);
52
+ console.log('~~~~~~~');
50
53
  const viewClass = this.displayTime ? 'view' : 'hide';
51
54
  return html`
52
55
  <button
@@ -40,7 +40,7 @@ import ActionsConfig from './actions-config.js';
40
40
  * @enum {string}
41
41
  */
42
42
  export const bookTitles = {
43
- available_1hr: 'Renews automatically as long as pages are turned.',
43
+ available_1hr: 'Renews automatically with continued use.',
44
44
  available_14d: 'This book can be borrowed for 14 days.',
45
45
  available_pd: 'Book available to patrons with print disabilities.',
46
46
  available_waitlist: 'A waitlist is available.',
@@ -49,7 +49,7 @@ export const bookTitles = {
49
49
  being_borrowed: 'Another patron is using this book. Please check back later.',
50
50
  eligible_pd: 'You are eligible for print-disabled access.',
51
51
  on_waitlist: 'You are on the waitlist for this book.',
52
- session_expired: 'Renews automatically as long as pages are turned.',
52
+ session_expired: 'Renews automatically with continued use.',
53
53
  unavailable: 'This book is not available at this time.',
54
54
  };
55
55
 
@@ -121,12 +121,6 @@ export default class IABookActions extends LitElement {
121
121
  * @property {number} secondsLeft - seconds left in active loan
122
122
  */
123
123
  this.loanRenewResult = { texts: '', renewNow: false, secondsLeft: 0 };
124
-
125
- /**
126
- // * need showdowRoot opened for resetTimerCountState
127
- // * @see IABookActions::resetTimerCountState
128
- // */
129
- // this._shadowRoot = this.attachShadow({ mode: 'open' });
130
124
  }
131
125
 
132
126
  disconnectedCallback() {
@@ -274,6 +268,7 @@ export default class IABookActions extends LitElement {
274
268
  * dispatched this event from bookreader page changed
275
269
  */
276
270
  window.addEventListener('BookReader:userAction', () => {
271
+ log('IABookActions:BookReader:userAction');
277
272
  if (this.borrowType === 'browsed') {
278
273
  this.autoLoanRenewChecker(true);
279
274
  }
@@ -321,7 +316,6 @@ export default class IABookActions extends LitElement {
321
316
  // clear modal
322
317
  this.modal.customModalContent = nothing;
323
318
  this.modal?.closeModal();
324
- log('MODAL CLOSED ___ ', this.modal.customModalContent);
325
319
  this.loanRenewResult = { texts: '', renewNow: false };
326
320
 
327
321
  // if secondsLeft < 60, consider it 1 minute
@@ -368,8 +362,6 @@ export default class IABookActions extends LitElement {
368
362
 
369
363
  /** @param { 'renewBook' | 'returnBook' } buttonToDisable */
370
364
  async showWarningDisabledModal(buttonToDisable = 'renewBook') {
371
- log('****** showWarningDisabledModal ******');
372
-
373
365
  // if secondsLeft < 60, consider it 1 minute
374
366
  let { secondsLeft } = this.loanRenewResult;
375
367
  if (secondsLeft === undefined) {
@@ -435,6 +427,12 @@ export default class IABookActions extends LitElement {
435
427
  this.showWarningDisabledModal('returnBook');
436
428
  document.querySelector('ia-book-actions').disableActionGroup = true;
437
429
  this.returnNow = true;
430
+
431
+ this.lendingStatus = {
432
+ ...this.lendingStatus,
433
+ browsingExpired: true,
434
+ secondsLeftOnLoan: 0,
435
+ };
438
436
  }
439
437
 
440
438
  /**
@@ -527,7 +525,11 @@ export default class IABookActions extends LitElement {
527
525
  async browseHasExpired() {
528
526
  window?.IALendingIntervals?.clearAll();
529
527
 
530
- const currStatus = { ...this.lendingStatus, browsingExpired: true };
528
+ const currStatus = {
529
+ ...this.lendingStatus,
530
+ browsingExpired: true,
531
+ secondsLeftOnLoan: 0,
532
+ };
531
533
  this.lendingStatus = currStatus;
532
534
 
533
535
  // remove respected key:value for loan-renew
@@ -546,19 +548,24 @@ export default class IABookActions extends LitElement {
546
548
 
547
549
  async startBrowseTimer() {
548
550
  clearTimeout(this.browseTimer);
549
- log(
550
- 'startBrowseTimerstartBrowseTimer just cleared timer',
551
- this.browseTimer,
552
- this.lendingStatus
553
- );
554
-
555
551
  const {
556
552
  browsingExpired,
557
553
  user_has_browsed,
558
554
  secondsLeftOnLoan,
559
555
  } = this.lendingStatus;
556
+
557
+ log(
558
+ 'startBrowseTimerstartBrowseTimer just cleared timer',
559
+ this.browseTimer,
560
+ { browsingExpired, user_has_browsed, secondsLeftOnLoan }
561
+ );
562
+
560
563
  if (!user_has_browsed || browsingExpired) {
561
- log('user not browsed', this.lendingStatus);
564
+ log('user not browsed', {
565
+ user_has_browsed,
566
+ browsingExpired,
567
+ secondsLeftOnLoan,
568
+ });
562
569
  return;
563
570
  }
564
571
 
@@ -590,6 +597,10 @@ export default class IABookActions extends LitElement {
590
597
  ></book-title-bar>`;
591
598
  }
592
599
 
600
+ get timerCountdownEl() {
601
+ return this.shadowRoot.querySelector('timer-countdown');
602
+ }
603
+
593
604
  get bookActionBar() {
594
605
  return html`
595
606
  <collapsible-action-group
@@ -615,7 +626,9 @@ export default class IABookActions extends LitElement {
615
626
  </collapsible-action-group>
616
627
  ${this.textGroupTemplate} ${this.infoIconTemplate}
617
628
  <timer-countdown
618
- .secondsLeftOnLoan=${Number(this.lendingStatus.secondsLeftOnLoan)}
629
+ .secondsLeftOnLoan=${Math.round(
630
+ Number(this.lendingStatus.secondsLeftOnLoan)
631
+ )}
619
632
  ></timer-countdown>
620
633
  `;
621
634
  }
@@ -633,10 +646,10 @@ export default class IABookActions extends LitElement {
633
646
 
634
647
  // Now, let's reset loan duration & this.lendingStatus
635
648
  const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
636
- const secondsLeft = (loanTime - new Date()) / 1000; // different in seconds
649
+ const secondsLeft = Math.round((loanTime - new Date()) / 1000); // different in seconds
637
650
 
638
651
  // testing console....
639
- log('IABookActions: AutoRenewed:- ', {
652
+ log('~~~ IABookActions: handleLoanAutoRenewed:- ', {
640
653
  ajaxResponse: event?.detail?.data,
641
654
  loanRenewResult: this.loanRenewResult,
642
655
  secondsLeftOnLoan: secondsLeft,
@@ -650,10 +663,6 @@ export default class IABookActions extends LitElement {
650
663
  };
651
664
  this.lendingStatus = currStatus;
652
665
 
653
- log('~~~ handleLoanAutoRenewed - new this.lendingStatus', {
654
- secondsLeftOnLoan: this.lendingStatus.secondsLeftOnLoan,
655
- });
656
-
657
666
  // close the modal
658
667
  this.modal?.closeModal();
659
668
  this.modal.removeAttribute('id');
@@ -668,7 +677,6 @@ export default class IABookActions extends LitElement {
668
677
  * @memberof IABookActions
669
678
  */
670
679
  startTimerCountdown() {
671
- log('startTimerCountdown()');
672
680
  window?.IALendingIntervals?.clearTimerCountdown();
673
681
 
674
682
  let secondsLeft = Number(this.lendingStatus.secondsLeftOnLoan);
@@ -683,17 +691,18 @@ export default class IABookActions extends LitElement {
683
691
  // if really updated, escape from here
684
692
  const resync = await this.reSyncTimerIfGoneOff(secondsLeft);
685
693
 
686
- log('*** startTimerCountdown = reSyncTimerIfGoneOff ***', {
687
- secondsLeft,
688
- resync,
689
- });
690
-
691
694
  if (resync) {
692
- log('have resyncd, will end startTimerCountdown here - ');
695
+ log('timer has resyncd, abort stale startTimerCountdown - ', {
696
+ secondsLeft,
697
+ });
693
698
  return;
694
699
  }
695
700
 
696
- log('startTimerCountdown - NO RESYNC');
701
+ log('startTimerCountdown - countdown still valid. continue...', {
702
+ resync,
703
+ secondsLeft,
704
+ loanRenewAtLast: this.loanRenewTimeConfig.loanRenewAtLast,
705
+ });
697
706
 
698
707
  /**
699
708
  * execute from last 10th minute to 0th minute
@@ -721,15 +730,6 @@ export default class IABookActions extends LitElement {
721
730
  * @memberof TimerCountdown
722
731
  */
723
732
  async reSyncTimerIfGoneOff(timerSecondsLeft) {
724
- // debug info
725
- log(
726
- new Date().toLocaleTimeString(),
727
- 'timeLeftInSec',
728
- timerSecondsLeft,
729
- ' ||| timeLeftInMin',
730
- Math.ceil(timerSecondsLeft / 60)
731
- );
732
-
733
733
  const currentTime = new Date();
734
734
 
735
735
  // current time - loan time
@@ -742,19 +742,27 @@ export default class IABookActions extends LitElement {
742
742
  // convert in minutes
743
743
  const whatIsleft = Math.round(timerSecondsLeft);
744
744
  const whatShouldLeft = Math.round(secondsShouldLeft);
745
+ const timerElSeconds = this.timerCountdownEl.secondsLeftOnLoan || 0;
745
746
 
746
- if (whatIsleft !== whatShouldLeft) {
747
- // debug info
748
- log(
749
- `timer is gone off, let's re-sync, whatIsleft -> ${whatIsleft}, whatShouldLeft -> ${whatShouldLeft}`
750
- );
747
+ log(`reSyncTimerIfGoneOff?`, {
748
+ whatIsleft,
749
+ whatShouldLeft,
750
+ timerElSeconds,
751
+ timeLeftInMin: Math.ceil(timerSecondsLeft / 60),
752
+ });
751
753
 
752
- // the seconds should left in timer again
754
+ if (timerElSeconds !== whatShouldLeft || whatIsleft !== whatShouldLeft) {
755
+ // set lending status with new time to update decrementor
753
756
  const currStatus = {
754
757
  ...this.lendingStatus,
755
- secondsLeftOnLoan: secondsShouldLeft,
758
+ secondsLeftOnLoan: whatShouldLeft,
756
759
  };
757
760
  this.lendingStatus = currStatus;
761
+ }
762
+
763
+ if (whatIsleft !== whatShouldLeft) {
764
+ log(`timer is gone off, let's re-sync,`);
765
+
758
766
  return true;
759
767
  }
760
768
  return false;
@@ -189,7 +189,7 @@ describe('Borrow status actions', () => {
189
189
  ];
190
190
 
191
191
  expect(el.primaryTitle).to.equal(
192
- 'Renews automatically as long as pages are turned.'
192
+ 'Renews automatically with continued use.'
193
193
  );
194
194
  expect(el.primaryActions.length).to.equal(2);
195
195
  expect(el.primaryActions[0].text).to.equal('Log In and Borrow');