@internetarchive/ia-book-actions 0.1.4-alpha3 → 0.1.4-alpha4

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,7 +131,7 @@
131
131
  iaBookActions.returnUrl = 'https://openlibrary.org';
132
132
  iaBookActions.localCache = localCache;
133
133
 
134
- let loanTotalTime2Min = { loanTotalTime: 20, loanRenewAtLast: 15, pageChangedInLast: 8 };
134
+ let loanTotalTime2Min = { loanTotalTime: 300, loanRenewAtLast: 120, pageChangedInLast: 60 };
135
135
  let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 180, pageChangedInLast: 15 };
136
136
  let loanTotalTime1Hour = { loanTotalTime: 3600, loanRenewAtLast: 600, pageChangedInLast: 900 };
137
137
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.1.4-alpha3",
3
+ "version": "0.1.4-alpha4",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -33,9 +33,9 @@ export default class TimerCountdown extends LitElement {
33
33
 
34
34
  /**
35
35
  * timer which is not reduced along with timer
36
- * @type {date}
36
+ * @type {string}
37
37
  */
38
- this.timeWhenTimerStart = '';
38
+ this.timeWhenTimerStart = undefined;
39
39
 
40
40
  /**
41
41
  * delay seconds in setInterval function
@@ -62,7 +62,7 @@ export default class TimerCountdown extends LitElement {
62
62
  this.disconnectedCallback();
63
63
 
64
64
  // - let just execute setInterval in every 1 minute
65
- this.timerExecutionSeconds = 1;
65
+ this.timerExecutionSeconds = 60;
66
66
  let secondsLeft = this.secondsLeftOnLoan;
67
67
 
68
68
  // store current time
@@ -76,14 +76,6 @@ export default class TimerCountdown extends LitElement {
76
76
  secondsLeft -= this.timerExecutionSeconds;
77
77
  secondsLeft = Math.round(secondsLeft); // round number
78
78
 
79
- console.log(
80
- new Date().toLocaleTimeString(),
81
- 'timeLeftInSec',
82
- secondsLeft,
83
- ' ||| timeLeftInMin',
84
- Math.ceil(secondsLeft / 60)
85
- );
86
-
87
79
  // re-sync timer is gone off
88
80
  await this.reSyncTimerIfGoneOff(secondsLeft);
89
81
 
@@ -98,7 +90,7 @@ export default class TimerCountdown extends LitElement {
98
90
  }
99
91
 
100
92
  // clear interval
101
- if (secondsLeft <= 1) {
93
+ if (secondsLeft <= 10) {
102
94
  this.disconnectedCallback();
103
95
  window?.Sentry?.captureMessage(sentryLogs.clearOneHourTimer);
104
96
  }
@@ -132,6 +124,15 @@ export default class TimerCountdown extends LitElement {
132
124
  * @memberof TimerCountdown
133
125
  */
134
126
  async reSyncTimerIfGoneOff(timerSecondsLeft) {
127
+ // debug info
128
+ console.log(
129
+ new Date().toLocaleTimeString(),
130
+ 'timeLeftInSec',
131
+ timerSecondsLeft,
132
+ ' ||| timeLeftInMin',
133
+ Math.ceil(timerSecondsLeft / 60)
134
+ );
135
+
135
136
  const currentTime = new Date();
136
137
 
137
138
  // current time - loan time
@@ -141,13 +142,15 @@ export default class TimerCountdown extends LitElement {
141
142
  const secondsShouldLeft = this.secondsLeftOnLoan - diffInSeconds;
142
143
 
143
144
  // convert in minutes
144
- const whatIsleft = Math.round(timerSecondsLeft / 60);
145
- const whatShouldLeft = Math.round(secondsShouldLeft / 60);
145
+ const whatIsleft = Math.round(timerSecondsLeft);
146
+ const whatShouldLeft = Math.round(secondsShouldLeft);
146
147
 
147
148
  if (whatIsleft !== whatShouldLeft) {
148
- console.log("timer is gone off, let's re-sync");
149
- console.log('whatIsleft', whatIsleft, 'whatShouldLeft', whatShouldLeft);
150
- this.secondsLeftOnLoan = secondsShouldLeft;
149
+ // debug info
150
+ console.log(
151
+ `timer is gone off, let's re-sync, whatIsleft -> ${whatIsleft}, whatShouldLeft -> ${whatShouldLeft}`
152
+ );
153
+ this.secondsLeftOnLoan = secondsShouldLeft; // the seconds should left in timer again
151
154
  }
152
155
  }
153
156
 
@@ -263,6 +263,8 @@ export default class IABookActions extends LitElement {
263
263
  if (this.borrowType === 'browsed') {
264
264
  this.suppressToast = false;
265
265
  this.autoLoanRenewChecker(true);
266
+ } else {
267
+ this.suppressToast = true;
266
268
  }
267
269
 
268
270
  return nothing;
@@ -271,11 +273,10 @@ export default class IABookActions extends LitElement {
271
273
  /**
272
274
  * detect click-event on document to close toast-template
273
275
  */
274
- window.addEventListener('click', e => {
275
- console.log('detech click event');
276
- // if (this.loanRenewHelper && this.loanRenewResult.secondsLeft > 0) {
277
- this.suppressToast = true;
278
- // }
276
+ document.addEventListener('click', e => {
277
+ if (this.loanRenewHelper && this.loanRenewResult.secondsLeft > 0) {
278
+ this.suppressToast = true;
279
+ }
279
280
 
280
281
  // reload when user click on book-page and book is EXPIRED
281
282
  const hasExpired =