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

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-b40",
3
+ "version": "0.1.11-b41",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -47,9 +47,6 @@ 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('~~~~~~~');
53
50
  const viewClass = this.displayTime ? 'view' : 'hide';
54
51
  return html`
55
52
  <button
@@ -6,4 +6,4 @@ export const mobileContainerWidth = 700;
6
6
  /**
7
7
  * shift the actions buttons in dropdown
8
8
  */
9
- export const tabletContainerWidth = 895;
9
+ export const tabletContainerWidth = 800;
@@ -1,3 +1,4 @@
1
+ /* global: window */
1
2
  /**
2
3
  * Collection of methods for managing intervals for lending system
3
4
  *
@@ -18,16 +19,19 @@ window.IALendingIntervals = {
18
19
  tokenPoller: 0,
19
20
 
20
21
  /**
21
- * store timer-countdown interval
22
- * @see TimerCountdown::timerCountdown
22
+ * renewal check interval
23
23
  */
24
24
  timerCountdown: 0,
25
25
 
26
+ /** expiration timer */
27
+ browseExpireTimeout: 0,
28
+
26
29
  /**
27
30
  * clear interval for create_token api
28
31
  */
29
32
  clearTokenPoller: () => {
30
- window.clearInterval(window?.IALendingIntervals?.tokenPoller);
33
+ window.clearInterval(window.IALendingIntervals.tokenPoller);
34
+ window.IALendingIntervals.tokenPoller = 0;
31
35
  },
32
36
 
33
37
  /**
@@ -35,13 +39,23 @@ window.IALendingIntervals = {
35
39
  */
36
40
  clearTimerCountdown: () => {
37
41
  window.clearInterval(window.IALendingIntervals.timerCountdown);
42
+ window.IALendingIntervals.timerCountdown = 0;
43
+ },
44
+
45
+ /**
46
+ * clear interval for graphic timer for one-hour loan renew
47
+ */
48
+ clearBrowseExpireTimeout: () => {
49
+ window.clearTimeout(window.IALendingIntervals.browseExpireTimeout);
50
+ window.IALendingIntervals.browseExpireTimeout = 0;
38
51
  },
39
52
 
40
53
  /**
41
54
  * clear all intervals being used acros lending system
42
55
  */
43
56
  clearAll: () => {
44
- window.clearInterval(window?.IALendingIntervals?.tokenPoller);
45
- window.clearInterval(window?.IALendingIntervals?.timerCountdown);
57
+ window?.IALendingIntervals?.clearTokenPoller();
58
+ window?.IALendingIntervals?.clearTimerCountdown();
59
+ window.IALendingIntervals.clearBrowseExpireTimeout();
46
60
  },
47
61
  };
@@ -7,6 +7,10 @@ import log from '../log.js';
7
7
  import ActionsHandlerService from './actions-handler-service.js';
8
8
  import LoanAnanlytics from '../loan-analytics.js';
9
9
  import * as Cookies from '../doc-cookies.js';
10
+ import {
11
+ analyticsCategories,
12
+ analyticsActions,
13
+ } from '../../config/analytics-event-and-category.js';
10
14
 
11
15
  /**
12
16
  * These are callback functions calling from actions-config.js file.
@@ -39,24 +43,53 @@ export default class ActionsHandler extends LitElement {
39
43
  }
40
44
 
41
45
  bindEvents() {
42
- this.addEventListener('browseBook', () => {
46
+ this.addEventListener('browseBook', async () => {
43
47
  this.handleBrowseIt();
44
- this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'browse');
48
+ await this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'browse');
49
+ this.loanAnanlytics?.sendEvent(
50
+ analyticsCategories.browse,
51
+ analyticsActions.browse
52
+ );
45
53
  });
46
54
 
47
- this.addEventListener('browseBookAgain', () => {
55
+ this.addEventListener('browseBookAgain', async () => {
48
56
  this.handleBrowseIt();
49
- this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'browseagain');
57
+ await this.loanAnanlytics?.storeLoanStatsCount(
58
+ this.identifier,
59
+ 'browseagain'
60
+ );
61
+ this.loanAnanlytics?.sendEvent(
62
+ analyticsCategories.browse,
63
+ analyticsActions.browseBookAgain
64
+ );
50
65
  });
51
66
 
52
- this.addEventListener('autoRenew', () => {
67
+ this.addEventListener('autoRenew', async () => {
53
68
  this.handleLoanRenewNow();
54
- this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'autorenew');
69
+ await this.loanAnanlytics?.storeLoanStatsCount(
70
+ this.identifier,
71
+ 'autorenew'
72
+ );
73
+ this.loanAnanlytics?.sendEvent(
74
+ analyticsCategories.browse,
75
+ analyticsActions.browseAutoRenew
76
+ );
55
77
  });
56
78
 
57
- this.addEventListener('autoReturn', () => {
79
+ this.addEventListener('autoReturn', async () => {
58
80
  this.handleReturnIt();
59
- this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'autoreturn');
81
+ await this.loanAnanlytics?.storeLoanStatsCount(
82
+ this.identifier,
83
+ 'autoreturn'
84
+ );
85
+ await this.loanAnanlytics?.storeLoanStatsCount(
86
+ this.identifier,
87
+ 'autorenew'
88
+ );
89
+ this.loanAnanlytics?.sendEvent(
90
+ analyticsCategories.browse,
91
+ analyticsActions.browseAutoReturn
92
+ );
60
93
  });
61
94
 
62
95
  this.addEventListener('returnNow', ({ detail }) => {
@@ -71,7 +71,7 @@ export default class IABookActions extends LitElement {
71
71
  this.identifier = '';
72
72
  this.bookTitle = '';
73
73
  this.returnUrl = '';
74
- this.lendingStatus = {};
74
+ this.lendingStatus = {}; // very important as components feed from this
75
75
  this.width = 0;
76
76
  this.bwbPurchaseUrl = '';
77
77
  this.lendingBarPostInit = () => {};
@@ -86,8 +86,8 @@ export default class IABookActions extends LitElement {
86
86
  this.primaryColor = 'primary';
87
87
  this.secondaryActions = [];
88
88
  this.lendingOptions = {};
89
- this.borrowType = null; // (browsed|borrowed)
90
- this.browseTimer = undefined;
89
+ this.borrowType = null; // 'browsed'|'borrowed'
90
+ this.browseTimer = undefined; // timeout
91
91
  this.timerExecutionSeconds = 30;
92
92
 
93
93
  /** @deprecated */
@@ -149,7 +149,6 @@ export default class IABookActions extends LitElement {
149
149
  updated(changed) {
150
150
  if (changed.has('lendingStatus') || changed.has('bwbPurchaseUrl')) {
151
151
  this.setupLendingToolbarActions();
152
- this.update();
153
152
  }
154
153
 
155
154
  if (changed.has('sharedObserver')) {
@@ -255,6 +254,8 @@ export default class IABookActions extends LitElement {
255
254
  setTimeout(() => {
256
255
  if (!hasExpired) this.startLoanTokenPoller();
257
256
  }, 100);
257
+
258
+ this.requestUpdate();
258
259
  }
259
260
 
260
261
  /**
@@ -547,18 +548,19 @@ export default class IABookActions extends LitElement {
547
548
  }
548
549
 
549
550
  async startBrowseTimer() {
550
- clearTimeout(this.browseTimer);
551
+ window.IALendingIntervals.clearBrowseExpireTimeout();
552
+
551
553
  const {
552
554
  browsingExpired,
553
555
  user_has_browsed,
554
556
  secondsLeftOnLoan,
555
557
  } = this.lendingStatus;
556
558
 
557
- log(
558
- 'startBrowseTimerstartBrowseTimer just cleared timer',
559
- this.browseTimer,
560
- { browsingExpired, user_has_browsed, secondsLeftOnLoan }
561
- );
559
+ log('startBrowseTimerstartBrowseTimer just cleared timer', {
560
+ browsingExpired,
561
+ user_has_browsed,
562
+ secondsLeftOnLoan,
563
+ });
562
564
 
563
565
  if (!user_has_browsed || browsingExpired) {
564
566
  log('user not browsed', {
@@ -569,7 +571,7 @@ export default class IABookActions extends LitElement {
569
571
  return;
570
572
  }
571
573
 
572
- this.browseTimer = setTimeout(() => {
574
+ window.IALendingIntervals.browseExpireTimeout = setTimeout(() => {
573
575
  log(
574
576
  'start `this.browseTimer will fire his.browseHasExpired() - secondsLeftOnLoan',
575
577
  secondsLeftOnLoan