@internetarchive/ia-book-actions 0.0.29-alpha31 → 0.0.29-alpha33

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
@@ -123,14 +123,16 @@
123
123
  iaBookActions.bwbPurchaseUrl = '';
124
124
  iaBookActions.modalConfig = modalConfig;
125
125
  iaBookActions.lendingBarPostInit = lendingBarPostInit;
126
- iaBookActions.tokenDelay = 2000; // 2 seconds
126
+ iaBookActions.tokenDelay = 2; // 2 seconds
127
127
  iaBookActions.returnUrl = 'https://openlibrary.org';
128
128
  iaBookActions.localCache = localCache;
129
+
130
+ let isDevBox = true;
129
131
  iaBookActions.loanRenewConfig = {
130
- totalTime: 70, // 60 second = 1 min
131
- autoCheckAt: 65, // totalTime - 10th minute
132
- pageChangedInLast: 5, // within last 15 second/minute
133
- env: 'dev', // dev/prod
132
+ totalTime: isDevBox ? 120 : 3600, // 60 second = 1 min
133
+ autoCheckAt: isDevBox ? 115 : 3540, // at last 10th minute
134
+ pageChangedInLast: isDevBox ? 80 : 900, // within last 15 second/minute
135
+ env: isDevBox ? 'dev' : 'prod',
134
136
  };
135
137
 
136
138
  let lendingStatus1 = iaBookActions.lendingStatus;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.29-alpha31",
3
+ "version": "0.0.29-alpha33",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -11,7 +11,7 @@ export default class TimerCountdown extends LitElement {
11
11
  constructor() {
12
12
  super();
13
13
  this.timeLeftOnLoan = 0;
14
- this.loanRenewConfig = 0;
14
+ this.loanRenewConfig = {};
15
15
 
16
16
  // private props
17
17
  this.timerInterval = undefined;
@@ -29,30 +29,36 @@ export default class TimerCountdown extends LitElement {
29
29
  }
30
30
 
31
31
  timerCountdown() {
32
- this.timerInterval = setInterval(() => {
33
- this.timeLeftOnLoan -= 1;
32
+ // execute interval in each second in-case of dev environment
33
+ this.timerInterval = setInterval(
34
+ () => {
35
+ this.timeLeftOnLoan -= this.loanRenewConfig.env === 'dev' ? 1 : 60;
34
36
 
35
- // execute from last 10th minute to 0th minute
36
- // - 10th - to check if user has viewed
37
- // - till 0th - to show warning msg with remaining time to auto returned
38
- if (Math.round(this.timeLeftOnLoan) <= this.loanRenewConfig.autoCheckAt) {
39
- this.dispatchEvent(
40
- new CustomEvent('IABookActions:loanRenew', {
41
- detail: {
42
- hasPageChanged: false,
43
- timeLeft: Math.round(this.timeLeftOnLoan),
44
- },
45
- bubbles: true,
46
- composed: true,
47
- })
48
- );
49
- }
37
+ // execute from last 10th minute to 0th minute
38
+ // - 10th - to check if user has viewed
39
+ // - till 0th - to show warning msg with remaining time to auto returned
40
+ if (
41
+ Math.round(this.timeLeftOnLoan) <= this.loanRenewConfig.autoCheckAt
42
+ ) {
43
+ this.dispatchEvent(
44
+ new CustomEvent('IABookActions:loanRenew', {
45
+ detail: {
46
+ hasPageChanged: false,
47
+ timeLeft: Math.round(this.timeLeftOnLoan),
48
+ },
49
+ bubbles: true,
50
+ composed: true,
51
+ })
52
+ );
53
+ }
50
54
 
51
- // clear interval if timer is < this.loanRenewConfig.autoCheckAt
52
- if (this.timeLeftOnLoan < this.loanRenewConfig.autoCheckAt) {
53
- clearInterval(this.timerInterval);
54
- }
55
- }, 1000);
55
+ // clear interval if timer is < this.loanRenewConfig.autoCheckAt
56
+ if (this.timeLeftOnLoan < this.loanRenewConfig.autoCheckAt) {
57
+ clearInterval(this.timerInterval);
58
+ }
59
+ },
60
+ this.loanRenewConfig.env === 'dev' ? 1000 : 60000
61
+ );
56
62
  }
57
63
 
58
64
  render() {
@@ -15,7 +15,7 @@ import * as Cookies from '../doc-cookies.js';
15
15
  export default class ActionsHandler extends LitElement {
16
16
  constructor() {
17
17
  super();
18
- this.ajaxTimeout = 6000;
18
+ this.ajaxTimeout = 6; // in seconds
19
19
 
20
20
  this.bindEvents();
21
21
  }
@@ -262,7 +262,7 @@ export default class ActionsHandler extends LitElement {
262
262
  // redirection on details page after 5 seconds because borrowing book takes time to create item creation.
263
263
  setTimeout(() => {
264
264
  URLHelper.goToUrl(redirectTo, true);
265
- }, this.ajaxTimeout);
265
+ }, this.ajaxTimeout * 1000);
266
266
  }
267
267
 
268
268
  // save consecutive loan count for borrow
@@ -131,7 +131,7 @@ export class LoanRenewHelper {
131
131
 
132
132
  if (timeLeft > 60) {
133
133
  unitOfTime = 'minute';
134
- timeLeft = 1;
134
+ timeLeft = Math.floor(timeLeft / 60);
135
135
  }
136
136
 
137
137
  // replace remaining time
@@ -60,7 +60,7 @@ export default class IABookActions extends LitElement {
60
60
  this.sharedObserver = undefined;
61
61
  this.disableActionGroup = false;
62
62
  this.modal = undefined;
63
- this.tokenDelay = 120000; // 2 minutes
63
+ this.tokenDelay = 120; // in seconds
64
64
 
65
65
  // private props
66
66
  this.primaryActions = [];
@@ -225,7 +225,7 @@ export default class IABookActions extends LitElement {
225
225
  this.resetTimerCountState();
226
226
  }
227
227
  },
228
- this.loanRenewResult.renewNow ? this.tokenDelay : 100
228
+ this.loanRenewResult.renewNow ? this.tokenDelay * 1000 : 100
229
229
  );
230
230
  }
231
231
 
@@ -304,7 +304,7 @@ export default class IABookActions extends LitElement {
304
304
  await iaBookActions.appendChild(toastTemplate);
305
305
 
306
306
  const config = new ToastConfig();
307
- config.texts = this.loanRenewHelper.getMessageTexts(
307
+ config.texts = this.loanRenewHelper?.getMessageTexts(
308
308
  this.loanRenewResult.texts,
309
309
  this.loanRenewResult.timeLeft
310
310
  );
@@ -341,10 +341,9 @@ export default class IABookActions extends LitElement {
341
341
  return;
342
342
  }
343
343
 
344
- const timeLeft = secondsLeftOnLoan * 1000;
345
344
  this.browserTimer = setTimeout(() => {
346
345
  this.browseHasExpired();
347
- }, timeLeft);
346
+ }, secondsLeftOnLoan * 1000);
348
347
  }
349
348
 
350
349
  /**
@@ -462,6 +461,7 @@ export default class IABookActions extends LitElement {
462
461
  await this.showToastMessage();
463
462
  await this.browseHasRenew();
464
463
  await this.resetTimerCountState();
464
+ this.startLoanTokenPoller();
465
465
  }
466
466
  }
467
467
 
@@ -496,7 +496,7 @@ export default class IABookActions extends LitElement {
496
496
  this.borrowType,
497
497
  successCallback,
498
498
  errorCallback,
499
- this.tokenDelay // 1000 ms = 1 sec
499
+ this.tokenDelay // in seconds
500
500
  );
501
501
  }
502
502