@internetarchive/ia-book-actions 0.1.11-b32 → 0.1.11-b33

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-b32",
3
+ "version": "0.1.11-b33",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -2,6 +2,7 @@ import { LitElement } from 'lit';
2
2
 
3
3
  import { URLHelper } from '../../config/url-helper.js';
4
4
  import { sentryLogs } from '../../config/sentry-events.js';
5
+ import log from '../log.js';
5
6
 
6
7
  import ActionsHandlerService from './actions-handler-service.js';
7
8
  import LoanAnanlytics from '../loan-analytics.js';
@@ -142,13 +143,7 @@ export default class ActionsHandler extends LitElement {
142
143
  action,
143
144
  identifier: this.identifier,
144
145
  success: data => {
145
- console.log(
146
- 'RENEW_LOAN --- ',
147
- data,
148
- action,
149
- data.loan,
150
- this.identifier
151
- );
146
+ log('RENEW_LOAN --- ', data, action, data.loan, this.identifier);
152
147
  if (data?.success === true && data?.loan?.renewal === true) {
153
148
  this.setBrowseTimeSession();
154
149
  this.dispatchEvent(
@@ -322,7 +317,7 @@ export default class ActionsHandler extends LitElement {
322
317
  // delete pageChangedTime when book is auto renew at nth minute
323
318
  await this.localCache.delete(`${this.identifier}-pageChangedTime`);
324
319
  } catch (error) {
325
- console.log(error);
320
+ log(error);
326
321
  }
327
322
  }
328
323
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { analyticsCategories } from '../config/analytics-event-and-category.js';
4
4
  import * as Cookies from './doc-cookies.js';
5
+ import log from './log.js';
5
6
 
6
7
  /**
7
8
  * This class is used to send different GA events for loan system.
@@ -45,7 +46,7 @@ export default class LoanAnanlytics {
45
46
  '/'
46
47
  );
47
48
  } catch (error) {
48
- console.log(error);
49
+ log(error);
49
50
  this.sendEvent('Cookies-Error-Actions', error, this.identifier);
50
51
  }
51
52
  }
@@ -144,7 +145,7 @@ export default class LoanAnanlytics {
144
145
  * @memberof LoanAnanlytics
145
146
  */
146
147
  sendEvent(eventCategory, eventAction, label, extraParams) {
147
- // console.log(
148
+ // log(
148
149
  // 'eventCategory:-',
149
150
  // eventCategory,
150
151
  // '\t||\teventAction:-',
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable class-methods-use-this */
2
2
 
3
3
  import { nothing } from 'lit';
4
+ import log from './log.js';
4
5
 
5
6
  /**
6
7
  * This class is used to determine if use is eligible for auto renew loan.
@@ -32,7 +33,7 @@ export class LoanRenewHelper {
32
33
  }
33
34
  return this.autoChecker(); // auto checker at last 10th minute
34
35
  } catch (error) {
35
- console.log(error);
36
+ log(error);
36
37
  }
37
38
 
38
39
  return nothing;
@@ -0,0 +1,16 @@
1
+ /* eslint-disable no-restricted-globals */
2
+ /* eslint-disable semi */
3
+ /**
4
+ * log() utility -- production ignores 'log()' JS calls; dev invokes 'log()'
5
+ */
6
+ const log =
7
+ location.hostname === 'localhost' ||
8
+ location.host.match(/^(www|cat)-[a-z0-9]+\.archive\.org$/) ||
9
+ location.host.match(/\.code\.archive\.org$/) ||
10
+ location.host.match(/\.dev\.archive\.org$/) ||
11
+ location.host.match(/^ia-petabox-/)
12
+ ? // eslint-disable-next-line no-console
13
+ console.log.bind(console) // convenient, no? Stateless function
14
+ : () => {};
15
+
16
+ export { log as default };
@@ -19,6 +19,7 @@ import { mobileContainerWidth } from './core/config/constants.js';
19
19
  import { sentryLogs } from './core/config/sentry-events.js';
20
20
  import { LoanTokenPoller } from './core/services/loan-token-poller.js';
21
21
  import { LoanRenewHelper } from './core/services/loan-renew-helper.js';
22
+ import log from './core/services/log.js';
22
23
 
23
24
  export const events = {
24
25
  browseExpired: 'IABookReader:BrowsingHasExpired',
@@ -256,7 +257,7 @@ export default class IABookActions extends LitElement {
256
257
  // initial timer state for 1-hour loan
257
258
  if (this.borrowType === 'browsed' && !this.loanRenewResult.renewNow) {
258
259
  setTimeout(() => {
259
- console.log(
260
+ log(
260
261
  'IN TIMEOUT OF --- setupLendingToolbarActions, firing resetTimerCountState'
261
262
  );
262
263
  this.resetTimerCountState();
@@ -287,6 +288,13 @@ export default class IABookActions extends LitElement {
287
288
  this.autoLoanRenewChecker(true);
288
289
  }
289
290
  });
291
+
292
+ window.focus(() => {
293
+ log('WINDOW FOCUS', this.borrowType);
294
+ if (this.borrowType === 'browsed') {
295
+ this.autoLoanRenewChecker(true);
296
+ }
297
+ });
290
298
  }
291
299
 
292
300
  /**
@@ -319,11 +327,11 @@ export default class IABookActions extends LitElement {
319
327
  * Show the waring modal to ask user if they are still reading
320
328
  */
321
329
  async showWarningModal() {
322
- console.log('****** showWarningModal ******');
330
+ log('****** showWarningModal ******');
323
331
  // clear modal
324
332
  this.modal.customModalContent = nothing;
325
333
  this.modal?.closeModal();
326
- console.log('MODAL CLOSED ___ ', this.modal.customModalContent);
334
+ log('MODAL CLOSED ___ ', this.modal.customModalContent);
327
335
  this.loanRenewResult = { texts: '', renewNow: false };
328
336
 
329
337
  // if secondsLeft < 60, consider it 1 minute
@@ -366,11 +374,12 @@ export default class IABookActions extends LitElement {
366
374
  </button>
367
375
  </div> `;
368
376
 
377
+ this.modal.setAttribute('aria-live', 'assertive');
369
378
  await this.modal?.showModal({ config, customModalContent });
370
379
  }
371
380
 
372
381
  async showWarningDisabledModal() {
373
- console.log('****** showWarningDisabledModal ******');
382
+ log('****** showWarningDisabledModal ******');
374
383
 
375
384
  // if secondsLeft < 60, consider it 1 minute
376
385
  let { secondsLeft } = this.loanRenewResult;
@@ -390,21 +399,6 @@ export default class IABookActions extends LitElement {
390
399
  ),
391
400
  });
392
401
 
393
- // this doesn't really work? shows empty button
394
-
395
- // if (event.target === undefined) return;
396
-
397
- // const button = event.target;
398
- // button.disabled = true;
399
- // button.innerHTML = `<ia-activity-indicator
400
- // mode="processing"
401
- // style=${modalButtonStyle.loaderIcon}
402
- // ></ia-activity-indicator>`;
403
-
404
- // const parentElement = event.target.parentNode;
405
- // parentElement.style.pointerEvents = 'none';
406
- // parentElement.style.opacity = 0.8;
407
-
408
402
  const customModalContent = html`<br />
409
403
  <div
410
404
  id="disabled-book-action-bar-custom-buttons"
@@ -419,6 +413,7 @@ export default class IABookActions extends LitElement {
419
413
  style=${modalButtonStyle.loaderIcon}
420
414
  ></ia-activity-indicator>
421
415
  </button>
416
+ <span style="visibility: none; height: 1px; width: 1px;">Renewing loan, one moment please.</span>
422
417
  <button
423
418
  disabled
424
419
  style="${modalButtonStyle.iaButton} ${modalButtonStyle.return}"
@@ -440,7 +435,7 @@ export default class IABookActions extends LitElement {
440
435
  * Show modal when book is auto returned
441
436
  */
442
437
  async showExpiredModal() {
443
- console.log('showExpiredModal()');
438
+ log('showExpiredModal()');
444
439
 
445
440
  const config = new ModalConfig({
446
441
  headline: '',
@@ -544,7 +539,7 @@ export default class IABookActions extends LitElement {
544
539
 
545
540
  async startBrowseTimer() {
546
541
  clearTimeout(this.browseTimer);
547
- console.log(
542
+ log(
548
543
  'startBrowseTimerstartBrowseTimer just cleared timer',
549
544
  this.browseTimer,
550
545
  this.lendingStatus
@@ -556,12 +551,12 @@ export default class IABookActions extends LitElement {
556
551
  secondsLeftOnLoan,
557
552
  } = this.lendingStatus;
558
553
  if (!user_has_browsed || browsingExpired) {
559
- console.log('user not browsed', this.lendingStatus);
554
+ log('user not browsed', this.lendingStatus);
560
555
  return;
561
556
  }
562
557
 
563
558
  this.browseTimer = setTimeout(() => {
564
- console.log(
559
+ log(
565
560
  'start `this.browseTimer will fire his.browseHasExpired() - secondsLeftOnLoan',
566
561
  secondsLeftOnLoan
567
562
  );
@@ -587,7 +582,7 @@ export default class IABookActions extends LitElement {
587
582
  const actualStrokeDashOffset =
588
583
  firstStrokeDashOffset > 315 ? 315 : firstStrokeDashOffset;
589
584
 
590
- console.log('resetTimerCountState === ', {
585
+ log('resetTimerCountState === ', {
591
586
  secondsLeft,
592
587
  firstStrokeDashOffset,
593
588
  actualStrokeDashOffset,
@@ -671,7 +666,7 @@ export default class IABookActions extends LitElement {
671
666
  window?.IALendingIntervals?.clearAll();
672
667
 
673
668
  // testing console....
674
- console.log('IABookActions: AutoRenewed:- ', {
669
+ log('IABookActions: AutoRenewed:- ', {
675
670
  ajaxResponse: event?.detail?.data,
676
671
  loanRenewResult: this.loanRenewResult,
677
672
  secondsLeftOnLoan: Math.round(this.lendingStatus.secondsLeftOnLoan), // stale? how to fix
@@ -689,25 +684,17 @@ export default class IABookActions extends LitElement {
689
684
  };
690
685
  this.lendingStatus = currStatus;
691
686
 
692
- console.log('~~~ handleLoanAutoRenewed - new this.lendingStatus', {
687
+ log('~~~ handleLoanAutoRenewed - new this.lendingStatus', {
693
688
  secondsLeftOnLoan: this.lendingStatus.secondsLeftOnLoan,
694
689
  });
695
690
 
696
- /**
697
- * reset timer countdown states
698
- */
691
+ /** reset timer */
699
692
  await this.resetTimerCountState();
700
693
 
701
694
  // close the modal
695
+ this.modal?.closeModal();
702
696
  this.modal.removeAttribute('id');
703
- // const editedActionButtons = this.modal.shadowRoot.querySelector('#book-action-bar-custom-buttons');
704
- // if (editedActionButtons) {
705
- // editedActionButtons.parentElement.removeChild(editedActionButtons);
706
- // }
707
697
  this.modal.customModalContent = nothing;
708
- this.modal?.closeModal();
709
- console.log('MODAL CLOSED ___ ', this.modal.customModalContent);
710
-
711
698
  window?.Sentry?.captureMessage(sentryLogs.bookHasRenewed);
712
699
  }
713
700
  }
@@ -718,7 +705,7 @@ export default class IABookActions extends LitElement {
718
705
  * @memberof IABookActions
719
706
  */
720
707
  startTimerCountdown() {
721
- console.log('startTimerCountdown()');
708
+ log('startTimerCountdown()');
722
709
  window?.IALendingIntervals?.clearTimerCountdown();
723
710
 
724
711
  let secondsLeft = Number(this.lendingStatus.secondsLeftOnLoan);
@@ -733,17 +720,17 @@ export default class IABookActions extends LitElement {
733
720
  // if really updated, escape from here
734
721
  const resync = await this.reSyncTimerIfGoneOff(secondsLeft);
735
722
 
736
- console.log('*** startTimerCountdown = reSyncTimerIfGoneOff ***', {
723
+ log('*** startTimerCountdown = reSyncTimerIfGoneOff ***', {
737
724
  secondsLeft,
738
725
  resync,
739
726
  });
740
727
 
741
728
  if (resync) {
742
- console.log('have resyncd, will end startTimerCountdown here - ');
729
+ log('have resyncd, will end startTimerCountdown here - ');
743
730
  return;
744
731
  }
745
732
 
746
- console.log('startTimerCountdown - NO RESYNC');
733
+ log('startTimerCountdown - NO RESYNC');
747
734
 
748
735
  /**
749
736
  * execute from last 10th minute to 0th minute
@@ -772,7 +759,7 @@ export default class IABookActions extends LitElement {
772
759
  */
773
760
  async reSyncTimerIfGoneOff(timerSecondsLeft) {
774
761
  // debug info
775
- console.log(
762
+ log(
776
763
  new Date().toLocaleTimeString(),
777
764
  'timeLeftInSec',
778
765
  timerSecondsLeft,
@@ -795,7 +782,7 @@ export default class IABookActions extends LitElement {
795
782
 
796
783
  if (whatIsleft !== whatShouldLeft) {
797
784
  // debug info
798
- console.log(
785
+ log(
799
786
  `timer is gone off, let's re-sync, whatIsleft -> ${whatIsleft}, whatShouldLeft -> ${whatShouldLeft}`
800
787
  );
801
788
 
@@ -819,7 +806,7 @@ export default class IABookActions extends LitElement {
819
806
  * @memberof IABookActions
820
807
  */
821
808
  async loanRenewAttempt(secondsLeft) {
822
- console.log('loanRenewAttempt()', secondsLeft, this.loanRenewResult);
809
+ log('loanRenewAttempt()', secondsLeft, this.loanRenewResult);
823
810
  let loanSecondsLeft = secondsLeft;
824
811
  /**
825
812
  * auto-renew is not possible in last seconds (let say 50 second) because,
@@ -829,7 +816,7 @@ export default class IABookActions extends LitElement {
829
816
  * so if seconds left is < 50, just expire the loan
830
817
  */
831
818
  if (loanSecondsLeft < 50) {
832
- console.log('if (loanSecondsLeft < 50) {');
819
+ log('if (loanSecondsLeft < 50) {');
833
820
  await this.browseHasExpired();
834
821
  return;
835
822
  }