@internetarchive/ia-book-actions 0.0.29-alpha30 → 0.0.29-alpha32

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
@@ -129,7 +129,7 @@
129
129
  iaBookActions.loanRenewConfig = {
130
130
  totalTime: 70, // 60 second = 1 min
131
131
  autoCheckAt: 65, // totalTime - 10th minute
132
- pageChangedInLast: 5, // within last 15 second/minute
132
+ pageChangedInLast: 15, // within last 15 second/minute
133
133
  env: 'dev', // dev/prod
134
134
  };
135
135
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.29-alpha30",
3
+ "version": "0.0.29-alpha32",
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() {
@@ -126,16 +126,18 @@ export class LoanRenewHelper {
126
126
  getMessageTexts(texts, time) {
127
127
  let unitOfTime = 'second';
128
128
 
129
+ let toastTexts = texts;
129
130
  let timeLeft = time;
130
- let toastTexts = time;
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
+ // replace remaining time
137
138
  toastTexts = toastTexts?.replace(/#time/, timeLeft);
138
139
 
140
+ // replace unitsOfTime eg second vs seconds / minute vs /minutes
139
141
  return toastTexts?.replace(
140
142
  /#unitsOfTime/,
141
143
  timeLeft !== 1 ? `${unitOfTime}s` : unitOfTime
@@ -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
  );
@@ -462,6 +462,7 @@ export default class IABookActions extends LitElement {
462
462
  await this.showToastMessage();
463
463
  await this.browseHasRenew();
464
464
  await this.resetTimerCountState();
465
+ this.startLoanTokenPoller();
465
466
  }
466
467
  }
467
468