@internetarchive/ia-book-actions 0.1.9-alpha4 → 0.1.9-alpha5

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.9-alpha4",
3
+ "version": "0.1.9-alpha5",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -144,14 +144,14 @@ export default class LoanAnanlytics {
144
144
  * @memberof LoanAnanlytics
145
145
  */
146
146
  sendEvent(eventCategory, eventAction, label, extraParams) {
147
- console.log(
148
- 'eventCategory:-',
149
- eventCategory,
150
- '\t||\teventAction:-',
151
- eventAction,
152
- '\t||\tlabel:-',
153
- label
154
- );
147
+ // console.log(
148
+ // 'eventCategory:-',
149
+ // eventCategory,
150
+ // '\t||\teventAction:-',
151
+ // eventAction,
152
+ // '\t||\tlabel:-',
153
+ // label
154
+ // );
155
155
 
156
156
  window?.archive_analytics?.send_event_no_sampling(
157
157
  eventCategory,
@@ -243,8 +243,9 @@ export default class IABookActions extends LitElement {
243
243
  }
244
244
 
245
245
  if (this.borrowType === 'browsed') {
246
+ console.log('this.borrowType', this.borrowType);
246
247
  // start timer for browsed.
247
- this.startBrowseTimer();
248
+ await this.startBrowseTimer();
248
249
  }
249
250
 
250
251
  // early return if not borrowed or no action-bar
@@ -280,13 +281,6 @@ export default class IABookActions extends LitElement {
280
281
  * dispatched this event from bookreader page changed
281
282
  */
282
283
  window.addEventListener('BookReader:userAction', () => {
283
- this.suppressToast = true;
284
- this.closeToastManager();
285
-
286
- if (this.suppressAutoRenew) {
287
- return;
288
- }
289
-
290
284
  if (this.borrowType === 'browsed') {
291
285
  this.autoLoanRenewChecker(true);
292
286
  }
@@ -365,6 +359,7 @@ export default class IABookActions extends LitElement {
365
359
  * Show the waring modal to ask user if they are still reading
366
360
  */
367
361
  async showWarningModal() {
362
+ console.log('****** showWarningModal ******');
368
363
  await this.useModalManager();
369
364
 
370
365
  // if secondsLeft < 60, consider it 1 minute
@@ -388,7 +383,7 @@ export default class IABookActions extends LitElement {
388
383
  <div id="custom-buttons" style="display:flex;justify-content:center;">
389
384
  <button
390
385
  style="${modalButtonStyle.iaButton} ${modalButtonStyle.renew}"
391
- @click=${async event => {
386
+ @click=${event => {
392
387
  this.changeModalState(event);
393
388
  this.autoLoanRenewChecker(true);
394
389
  }}
@@ -397,7 +392,7 @@ export default class IABookActions extends LitElement {
397
392
  </button>
398
393
  <button
399
394
  style="${modalButtonStyle.iaButton} ${modalButtonStyle.return}"
400
- @click=${async event => {
395
+ @click=${event => {
401
396
  this.changeModalState(event);
402
397
  document.querySelector('ia-book-actions').disableActionGroup = true;
403
398
  this.returnNow = true;
@@ -462,11 +457,8 @@ export default class IABookActions extends LitElement {
462
457
  * close/hide modal-manager
463
458
  */
464
459
  async closeModalManager() {
465
- console.log('** closeModalManager');
466
460
  this.modal = document.querySelector('modal-manager');
467
- if (this.modal) {
468
- this.modal?.closeModal();
469
- }
461
+ this.modal?.closeModal();
470
462
  }
471
463
 
472
464
  /**
@@ -490,11 +482,8 @@ export default class IABookActions extends LitElement {
490
482
  * close/hide toast message
491
483
  */
492
484
  async closeToastManager() {
493
- console.log('** closeToastManager');
494
485
  this.toast = this.shadowRoot.querySelector('toast-template');
495
- if (this.toast) {
496
- this.toast?.remove();
497
- }
486
+ this.toast?.remove();
498
487
  }
499
488
 
500
489
  /**
@@ -534,6 +523,9 @@ export default class IABookActions extends LitElement {
534
523
  }
535
524
 
536
525
  async browseHasRenew() {
526
+ console.log('****** browseHasRenew ******');
527
+ window?.IALendingIntervals?.clearAll();
528
+
537
529
  const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
538
530
  const secondsLeft = (loanTime - new Date()) / 1000; // different in seconds
539
531
 
@@ -544,24 +536,6 @@ export default class IABookActions extends LitElement {
544
536
  secondsLeftOnLoan: secondsLeft,
545
537
  };
546
538
  this.lendingStatus = currStatus;
547
-
548
- this.startBrowseTimer();
549
- }
550
-
551
- startBrowseTimer() {
552
- clearTimeout(this.browseTimer);
553
- const {
554
- browsingExpired,
555
- user_has_browsed,
556
- secondsLeftOnLoan,
557
- } = this.lendingStatus;
558
- if (!user_has_browsed || browsingExpired) {
559
- return;
560
- }
561
-
562
- this.browseTimer = setTimeout(() => {
563
- this.browseHasExpired();
564
- }, secondsLeftOnLoan * 1000);
565
539
  }
566
540
 
567
541
  /**
@@ -587,6 +561,26 @@ export default class IABookActions extends LitElement {
587
561
  window?.Sentry?.captureMessage(sentryLogs.browseHasExpired);
588
562
  }
589
563
 
564
+ async startBrowseTimer() {
565
+ clearTimeout(this.browseTimer);
566
+
567
+ const {
568
+ browsingExpired,
569
+ user_has_browsed,
570
+ secondsLeftOnLoan,
571
+ } = this.lendingStatus;
572
+ if (!user_has_browsed || browsingExpired) {
573
+ console.log('user not browsed', this.lendingStatus);
574
+ return;
575
+ }
576
+
577
+ console.log('user browsed', this.lendingStatus);
578
+
579
+ this.browseTimer = setTimeout(() => {
580
+ this.browseHasExpired();
581
+ }, secondsLeftOnLoan * 1000);
582
+ }
583
+
590
584
  /**
591
585
  * Reset timer animation state after book renewed
592
586
  */
@@ -682,7 +676,13 @@ export default class IABookActions extends LitElement {
682
676
  if (this.loanRenewResult.renewNow) {
683
677
  window?.IALendingIntervals?.clearAll();
684
678
 
685
- this.suppressToast = false;
679
+ // testing console....
680
+ console.log('IABookActions: AutoRenewed:- ', {
681
+ ajaxResponse: event?.detail?.data,
682
+ loanRenewResult: this.loanRenewResult,
683
+ secondsLeftOnLoan: Math.round(this.lendingStatus.secondsLeftOnLoan),
684
+ });
685
+
686
686
  await this.browseHasRenew();
687
687
  await this.resetTimerCountState();
688
688
 
@@ -691,13 +691,6 @@ export default class IABookActions extends LitElement {
691
691
  this.modal?.showModal({ config: {}, customModalContent: `` });
692
692
 
693
693
  window?.Sentry?.captureMessage(sentryLogs.bookHasRenewed);
694
-
695
- // testing console....
696
- console.log('IABookActions: AutoRenewed:- ', {
697
- ajaxResponse: event?.detail?.data,
698
- loanRenewResult: this.loanRenewResult,
699
- secondsLeftOnLoan: Math.round(this.lendingStatus.secondsLeftOnLoan),
700
- });
701
694
  }
702
695
  }
703
696
 
@@ -349,7 +349,7 @@ describe('Auto renew one hour loan', () => {
349
349
  });
350
350
  el.dispatchEvent(myEvent);
351
351
 
352
- await aTimeout(1500); // wait for 1.5 second
352
+ await aTimeout(1900); // wait for 1.9 second
353
353
  await el.updateComplete;
354
354
 
355
355
  expect(el.loanRenewResult.texts).to.equal(