@internetarchive/ia-book-actions 0.0.29-alpha50 → 0.0.29-alpha51

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,13 +131,11 @@
131
131
  iaBookActions.returnUrl = 'https://openlibrary.org';
132
132
  iaBookActions.localCache = localCache;
133
133
 
134
- let isDevBox = true;
135
- iaBookActions.loanRenewTimeConfig = {
136
- loanTotalTime: isDevBox ? 15 : 3600, // 60 second = 1 min
137
- loanRenewAtLast: isDevBox ? 10 : 3540, // at last 10th minute
138
- pageChangedInLast: isDevBox ? 5 : 900, // within last 15 second/minute
139
- isDevBox: isDevBox,
140
- };
134
+ let loanTotalTime2Min = { loanTotalTime: 20, loanRenewAtLast: 15, pageChangedInLast: 15 };
135
+ let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 180, pageChangedInLast: 15 };
136
+ let loanTotalTime1Hour = { loanTotalTime: 3600, loanRenewAtLast: 600, pageChangedInLast: 900 };
137
+
138
+ iaBookActions.loanRenewTimeConfig = loanTotalTime2Min;
141
139
 
142
140
  let lendingStatus1 = iaBookActions.lendingStatus;
143
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.0.29-alpha50",
3
+ "version": "0.0.29-alpha51",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -5,8 +5,8 @@ export default class TimerCountdown extends LitElement {
5
5
  static get properties() {
6
6
  return {
7
7
  secondsLeftOnLoan: { type: Number }, // in seconds
8
+ loanTotalTime: { type: Number }, // in seconds
8
9
  loanRenewAtLast: { type: Number }, // in seconds
9
- isDevBox: { type: Boolean },
10
10
  };
11
11
  }
12
12
 
@@ -14,11 +14,17 @@ export default class TimerCountdown extends LitElement {
14
14
  super();
15
15
 
16
16
  /**
17
- * seconds left in current time
17
+ * seconds left in current loan
18
18
  * @type {number}
19
19
  */
20
20
  this.secondsLeftOnLoan = 0;
21
21
 
22
+ /**
23
+ * total seconds a loan does have
24
+ * @type {number}
25
+ */
26
+ this.loanTotalTime = 0;
27
+
22
28
  /**
23
29
  * at the remaining time, we attempt to renew current loan
24
30
  * @type {number}
@@ -26,12 +32,16 @@ export default class TimerCountdown extends LitElement {
26
32
  this.loanRenewAtLast = 0;
27
33
 
28
34
  /**
29
- * @type {boolean}
35
+ * setInterval executed interval
36
+ * @type {number}
30
37
  */
31
- this.isDevBox = false;
32
-
33
- // private props
34
38
  this.timerInterval = undefined;
39
+
40
+ /**
41
+ * delay seconds in setInterval function
42
+ * @type {number}
43
+ */
44
+ this.timerExecutionSeconds = 0;
35
45
  }
36
46
 
37
47
  disconnectedCallback() {
@@ -46,17 +56,22 @@ export default class TimerCountdown extends LitElement {
46
56
  }
47
57
 
48
58
  timerCountdown() {
49
- // in-case of isDevBox, execute timer in each second instead of 60
50
- const timerIntervalSeconds = this.isDevBox ? 1 : 60;
59
+ // Just a QA thing-
60
+ // if `this.loanTotalTime` less then 600 Seconds (10min)
61
+ // - let just execute setInterval in each second
62
+ // - otherwise execute in 60 seconds
63
+ const timerExecutionSeconds = this.loanTotalTime <= 600 ? 1 : 60;
51
64
 
52
65
  this.timerInterval = setInterval(() => {
53
- // if this.isDevBox, just reduce seconds by 1 instead of 60 (1 min)
54
- this.secondsLeftOnLoan -= timerIntervalSeconds;
66
+ this.secondsLeftOnLoan -= timerExecutionSeconds;
55
67
  const secondsLeft = Math.round(this.secondsLeftOnLoan);
56
68
 
57
- // execute from last 10th minute to 0th minute
58
- // - 10th - to check if user has viewed
59
- // - till 0th - to show warning msg with remaining time to auto expired
69
+ /**
70
+ * execute from last 10th minute to 0th minute
71
+ * - 10th - to check if user has viewed
72
+ * - till 0th - to show warning msg with remaining time to auto expired
73
+ * @see IABookActions::bindLoanRenewEvents
74
+ */
60
75
  if (secondsLeft <= this.loanRenewAtLast) {
61
76
  this.dispatchEvent(
62
77
  new CustomEvent('IABookActions:loanRenew', {
@@ -75,7 +90,7 @@ export default class TimerCountdown extends LitElement {
75
90
  clearInterval(this.timerInterval);
76
91
  window?.Sentry?.captureMessage(sentryLogs.clearOneHourTimer);
77
92
  }
78
- }, timerIntervalSeconds * 1000);
93
+ }, timerExecutionSeconds * 1000);
79
94
  }
80
95
 
81
96
  /**
@@ -88,7 +103,7 @@ export default class TimerCountdown extends LitElement {
88
103
  let unitOfTime = 'second';
89
104
  let timeLeft = Math.round(this.secondsLeftOnLoan);
90
105
 
91
- if (this.isDevBox) {
106
+ if (this.loanTotalTime <= 600) {
92
107
  return `${timeLeft} seconds`;
93
108
  }
94
109
 
@@ -78,10 +78,9 @@ export default class IABookActions extends LitElement {
78
78
  * contains one hour auto-loan-renew time configuration
79
79
  *
80
80
  * @type {object} loanRenewTimeConfig
81
- * @property {number} loanTotalTime - number of seconds a loan should last
81
+ * @property {number} loanTotalTime - total seconds a loan does have
82
82
  * @property {number} loanRenewAtLast - check for loan renew at last
83
83
  * @property {number} pageChangedInLast - consider loan renew eligible if viewed new page
84
- * @property {boolean} isDevBox - testing flag
85
84
  */
86
85
  this.loanRenewTimeConfig = {};
87
86
 
@@ -452,8 +451,8 @@ export default class IABookActions extends LitElement {
452
451
  return this.borrowType === 'browsed'
453
452
  ? html`<timer-countdown
454
453
  .secondsLeftOnLoan=${Number(this.lendingStatus.secondsLeftOnLoan)}
454
+ .loanTotalTime=${this.loanRenewTimeConfig.loanTotalTime}
455
455
  .loanRenewAtLast=${this.loanRenewTimeConfig.loanRenewAtLast}
456
- .isDevBox=${this.loanRenewTimeConfig.isDevBox}
457
456
  ></timer-countdown>`
458
457
  : nothing;
459
458
  }
@@ -16,7 +16,6 @@ describe('<timer-countdown>', () => {
16
16
  loanTotalTime: 14, // in seconds
17
17
  loanRenewAtLast: 5, // in seconds
18
18
  pageChangedInLast: 5, // in seconds
19
- isDevBox: true,
20
19
  },
21
20
  })
22
21
  );
@@ -33,7 +32,6 @@ describe('<timer-countdown>', () => {
33
32
  loanTotalTime: 14, // in seconds
34
33
  loanRenewAtLast: 5, // in seconds
35
34
  pageChangedInLast: 5, // in seconds
36
- isDevBox: true,
37
35
  },
38
36
  })
39
37
  );
@@ -8,7 +8,6 @@ const loanRenewTimeConfig = {
8
8
  loanTotalTime: 13,
9
9
  loanRenewAtLast: 10,
10
10
  pageChangedInLast: 12,
11
- isDevBox: true,
12
11
  };
13
12
 
14
13
  // localCache used for auto-loan-renew