@internetarchive/ia-book-actions 0.0.29-alpha27 → 0.0.29-alpha29

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.0.29-alpha27",
3
+ "version": "0.0.29-alpha29",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -4,14 +4,14 @@ export default class TimerCountdown extends LitElement {
4
4
  static get properties() {
5
5
  return {
6
6
  timeLeftOnLoan: { type: Number },
7
- autoCheckAt: { type: Number },
7
+ loanRenewConfig: { type: Object },
8
8
  };
9
9
  }
10
10
 
11
11
  constructor() {
12
12
  super();
13
13
  this.timeLeftOnLoan = 0;
14
- this.autoCheckAt = 0;
14
+ this.loanRenewConfig = 0;
15
15
 
16
16
  // private props
17
17
  this.timerInterval = undefined;
@@ -35,7 +35,7 @@ export default class TimerCountdown extends LitElement {
35
35
  // execute from last 10th minute to 0th minute
36
36
  // - 10th - to check if user has viewed
37
37
  // - till 0th - to show warning msg with remaining time to auto returned
38
- if (Math.round(this.timeLeftOnLoan) <= this.autoCheckAt) {
38
+ if (Math.round(this.timeLeftOnLoan) <= this.loanRenewConfig.autoCheckAt) {
39
39
  this.dispatchEvent(
40
40
  new CustomEvent('IABookActions:loanRenew', {
41
41
  detail: {
@@ -48,8 +48,8 @@ export default class TimerCountdown extends LitElement {
48
48
  );
49
49
  }
50
50
 
51
- // clear interval if timer is < this.autoCheckAt
52
- if (this.timeLeftOnLoan < this.autoCheckAt) {
51
+ // clear interval if timer is < this.loanRenewConfig.autoCheckAt
52
+ if (this.timeLeftOnLoan < this.loanRenewConfig.autoCheckAt) {
53
53
  clearInterval(this.timerInterval);
54
54
  }
55
55
  }, 1000);
@@ -1,5 +1,4 @@
1
1
  import { nothing } from 'lit';
2
- import { ToastConfig } from '@internetarchive/toast-manager';
3
2
 
4
3
  /**
5
4
  * This class is used to determine if use is eligible for auto renew loan.
@@ -115,30 +114,6 @@ export class LoanRenewHelper {
115
114
  });
116
115
  }
117
116
 
118
- /**
119
- * Show toast messages on some specific loan renew features. e.g.
120
- * - show success msg when book is auto renewed
121
- * - show success msg when book is auto returned
122
- * - show warninig msg when book is about to auto returned
123
- */
124
- async showToastMessage() {
125
- if (this.hideToast) return false;
126
-
127
- const iaBookActions = document.querySelector('ia-book-actions').shadowRoot;
128
- let toastTemplate = iaBookActions.querySelector('toast-template');
129
- if (!toastTemplate) {
130
- toastTemplate = document.createElement('toast-template');
131
- }
132
- await iaBookActions.appendChild(toastTemplate);
133
-
134
- const config = new ToastConfig();
135
- config.texts = this.result.texts?.replace(/#time/, this.result.timeLeft);
136
- config.dismisOnClick = true;
137
- toastTemplate.showToast({
138
- config,
139
- });
140
- }
141
-
142
117
  /**
143
118
  * Helper function to get time difference
144
119
  *
@@ -219,7 +219,7 @@ export default class IABookActions extends LitElement {
219
219
  () => {
220
220
  this.startLoanTokenPoller();
221
221
 
222
- if (!this.loanRenewResult.renewNow) {
222
+ if (this.borrowType === 'browsed' && !this.loanRenewResult.renewNow) {
223
223
  this.resetTimerCountState();
224
224
  }
225
225
  },
@@ -237,9 +237,9 @@ export default class IABookActions extends LitElement {
237
237
  /**
238
238
  * dispatched this event from bookreader page changed
239
239
  */
240
- window.addEventListener('BookReader:pageChanged', event => {
241
- if (this.borrowType === 'browsed' && event.detail.props.hasPageChanged) {
242
- console.log('actual page changed executed!')
240
+ window.addEventListener('BookReader:userAction', event => {
241
+ if (this.borrowType === 'browsed') {
242
+ console.log('user-action executed!');
243
243
  this.autoLoanRenewChecker(true);
244
244
  }
245
245
 
@@ -285,8 +285,14 @@ export default class IABookActions extends LitElement {
285
285
  this.loanRenewResult = this.loanRenewHelper.result;
286
286
  }
287
287
 
288
+ /**
289
+ * Show toast messages on some specific loan renew features. e.g.
290
+ * - show success msg when book is auto renewed
291
+ * - show success msg when book is auto returned
292
+ * - show warninig msg when book is about to auto returned
293
+ */
288
294
  async showToastMessage() {
289
- if (this.suppressToast) return false;
295
+ if (this.suppressToast) return;
290
296
 
291
297
  const iaBookActions = document.querySelector('ia-book-actions').shadowRoot;
292
298
  let toastTemplate = iaBookActions.querySelector('toast-template');
@@ -296,7 +302,10 @@ export default class IABookActions extends LitElement {
296
302
  await iaBookActions.appendChild(toastTemplate);
297
303
 
298
304
  const config = new ToastConfig();
299
- config.texts = this.loanRenewResult.texts?.replace(/#time/, this.loanRenewResult.timeLeft);
305
+ config.texts = this.loanRenewResult.texts?.replace(
306
+ /#time/,
307
+ this.loanRenewResult.timeLeft
308
+ );
300
309
  config.dismisOnClick = true;
301
310
  toastTemplate.showToast({
302
311
  config,
@@ -360,28 +369,23 @@ export default class IABookActions extends LitElement {
360
369
  * Reset timer animation state after book renewed
361
370
  */
362
371
  async resetTimerCountState() {
363
- const secondsLeft = Number(this.lendingStatus.secondsLeftOnLoan);
364
-
365
- const timerCountdown = this.shadowRoot.querySelector('timer-countdown');
366
- const animationCircle = timerCountdown.shadowRoot.querySelector('.circle');
372
+ const timerCountdown = this._shadowRoot.querySelector('timer-countdown');
373
+ if (!timerCountdown) return;
367
374
 
368
- // the perimeter of the circle
369
- const circleStroke = 315; // (π * 2 * radius)
375
+ const secondsLeft = Number(this.lendingStatus.secondsLeftOnLoan);
370
376
  const strokeDashOffset =
371
- (secondsLeft / this.loanRenewConfig.totalTime) *
372
- circleStroke;
377
+ (secondsLeft / this.loanRenewConfig.totalTime) * 315;
373
378
 
374
379
  // set seconds left in loan expire
375
- timerCountdown.style?.setProperty(
376
- '--timerSeconds',
377
- `${secondsLeft}s`
378
- );
380
+ timerCountdown.style?.setProperty('--timerSeconds', `${secondsLeft}s`);
381
+
379
382
  // set circle stroke offset left in loan expire
380
383
  timerCountdown.style?.setProperty(
381
384
  '--timerStroke',
382
- `${Number(strokeDashOffset)}`
385
+ `${Number(strokeDashOffset)}` // the perimeter of the circle = (π * 2 * radius)
383
386
  );
384
387
 
388
+ const animationCircle = timerCountdown.shadowRoot.querySelector('.circle');
385
389
  animationCircle.style.animationName = 'none';
386
390
  setTimeout(() => {
387
391
  animationCircle.style.animationName = 'circletimer';
@@ -411,7 +415,7 @@ export default class IABookActions extends LitElement {
411
415
  return this.borrowType === 'browsed'
412
416
  ? html`<timer-countdown
413
417
  .timeLeftOnLoan=${Number(this.lendingStatus.secondsLeftOnLoan)}
414
- .autoCheckAt=${this.loanRenewConfig.autoCheckAt}
418
+ .loanRenewConfig=${this.loanRenewConfig}
415
419
  ></timer-countdown>`
416
420
  : nothing;
417
421
  }