@internetarchive/ia-book-actions 0.1.9-alpha3 → 0.1.9-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 = '';
132
132
  iaBookActions.localCache = localCache;
133
133
 
134
- let loanTotalTime2Min = { loanTotalTime: 100, loanRenewAtLast: 97, pageChangedInLast: 15 };
134
+ let loanTotalTime2Min = { loanTotalTime: 65, loanRenewAtLast: 60, pageChangedInLast: 15 };
135
135
  let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 180, pageChangedInLast: 15 };
136
136
  let loanTotalTime1Hour = { loanTotalTime: 3600, loanRenewAtLast: 660, 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.9-alpha3",
3
+ "version": "0.1.9-alpha4",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -41,7 +41,7 @@ export default class TimerCountdown extends LitElement {
41
41
  * delay seconds in setInterval function
42
42
  * @type {number}
43
43
  */
44
- this.timerExecutionSeconds = 60;
44
+ this.timerExecutionSeconds = 30;
45
45
  }
46
46
 
47
47
  disconnectedCallback() {
@@ -66,6 +66,7 @@ export default class TimerCountdown extends LitElement {
66
66
  // store current time
67
67
  this.timeWhenTimerStart = new Date();
68
68
 
69
+ // this.dispatchLoanRenewEvent(secondsLeft);
69
70
  /**
70
71
  * set interval in window object
71
72
  * @see ia-lending-intervals.js
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable camelcase */
2
+ /* eslint-disable class-methods-use-this */
2
3
  import { html, css, LitElement, nothing } from 'lit';
3
4
 
4
5
  import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
@@ -23,13 +24,17 @@ export const events = {
23
24
  browseExpired: 'IABookReader:BrowsingHasExpired',
24
25
  };
25
26
 
27
+ /**
28
+ * custom styling for modal-manager buttons
29
+ * TODO: lets allow modal-manager to know ia-button classes
30
+ */
26
31
  export const modalButtonStyle = {
27
32
  iaButton:
28
33
  'min-height:3.5rem;cursor:pointer;color:white;border-radius:0.4rem;border:1px solid #c5d1df;padding:4px 8px;width:auto;user-select:none;',
29
34
  renew: 'background:#194880;width:110px;',
30
- return: 'background:#d9534f;',
35
+ return: 'background:#d9534f;width:120px;',
31
36
  loaderIcon:
32
- 'display:inline-block;width:20px;height:20px;margin-top:2px;color:white; --activityIndicatorLoadingRingColor:#fff;--activityIndicatorLoadingDotColor:#fff;',
37
+ 'display:inline-block;width:20px;height:20px;margin-top:2px;color:white;--activityIndicatorLoadingRingColor:#fff;--activityIndicatorLoadingDotColor:#fff;',
33
38
  refresh:
34
39
  'background:none;font-size:inherit;border:0;padding:0;color:#0000ee;cursor:pointer;text-decoration:underline',
35
40
  };
@@ -56,7 +61,6 @@ export default class IABookActions extends LitElement {
56
61
  localCache: { type: Object },
57
62
  loanRenewTimeConfig: { type: Object },
58
63
  loanRenewResult: { type: Object },
59
- _active: { state: true },
60
64
  };
61
65
  }
62
66
 
@@ -74,7 +78,6 @@ export default class IABookActions extends LitElement {
74
78
  this.sharedObserver = undefined;
75
79
  this.disableActionGroup = false;
76
80
  this.modal = undefined;
77
- this.toast = undefined;
78
81
  this.tokenDelay = 120; // in seconds
79
82
 
80
83
  // private props
@@ -84,10 +87,14 @@ export default class IABookActions extends LitElement {
84
87
  this.secondaryActions = [];
85
88
  this.lendingOptions = {};
86
89
  this.borrowType = ''; // (browsed|borrowed)
90
+ this.browseTimer = undefined;
91
+
92
+ /** @deprecated */
93
+ this.toast = undefined;
94
+ /** @deprecated */
87
95
  this.suppressToast = false;
96
+ /** @deprecated */
88
97
  this.suppressAutoRenew = false;
89
- this.browseTimer = undefined;
90
- this._attemptToRenew = false;
91
98
 
92
99
  /**
93
100
  * when user click on [return the book] button on warning modal
@@ -292,7 +299,6 @@ export default class IABookActions extends LitElement {
292
299
  * @see TimerCountdown::timerCountdown
293
300
  */
294
301
  this.addEventListener('IABookActions:loanRenew', async event => {
295
- console.log('** IABookActions:loanRenew', event.detail);
296
302
  await this.autoLoanRenewChecker(false);
297
303
 
298
304
  /**
@@ -379,32 +385,21 @@ export default class IABookActions extends LitElement {
379
385
  );
380
386
 
381
387
  const customContent = html`<br />
382
- <div
383
- id="custom-buttons"
384
- style="display:flex;justify-content:center;${this._attemptToRenew
385
- ? 'pointer-events:none;opacity:0.8'
386
- : ''}"
387
- >
388
+ <div id="custom-buttons" style="display:flex;justify-content:center;">
388
389
  <button
389
390
  style="${modalButtonStyle.iaButton} ${modalButtonStyle.renew}"
390
- @click=${() => {
391
- console.log('clicked on keep reading button');
392
- // e.target.parentNode.style.pointerEvents = "none";
393
- // e.target.parentNode.style.opacity = "0.8";
394
- this._attemptToRenew = true;
391
+ @click=${async event => {
392
+ this.changeModalState(event);
395
393
  this.autoLoanRenewChecker(true);
396
394
  }}
397
395
  >
398
- ${this._attemptToRenew
399
- ? html` <ia-activity-indicator
400
- mode="processing"
401
- style=${modalButtonStyle.loaderIcon}
402
- ></ia-activity-indicator>`
403
- : 'Keep reading'}
396
+ Keep reading
404
397
  </button>
405
398
  <button
406
399
  style="${modalButtonStyle.iaButton} ${modalButtonStyle.return}"
407
- @click=${() => {
400
+ @click=${async event => {
401
+ this.changeModalState(event);
402
+ document.querySelector('ia-book-actions').disableActionGroup = true;
408
403
  this.returnNow = true;
409
404
  }}
410
405
  >
@@ -415,6 +410,27 @@ export default class IABookActions extends LitElement {
415
410
  this.modal.showModal({ config, customModalContent: customContent });
416
411
  }
417
412
 
413
+ /**
414
+ * helper function to change button click states on modal-manager
415
+ * - add loader on button click
416
+ * - change button appearance
417
+ *
418
+ * @param {Event} event
419
+ */
420
+ changeModalState(event) {
421
+ if (event.target === undefined) return;
422
+
423
+ const button = event.target;
424
+ button.innerHTML = `<ia-activity-indicator
425
+ mode="processing"
426
+ style=${modalButtonStyle.loaderIcon}
427
+ ></ia-activity-indicator>`;
428
+
429
+ const parentElement = event.target.parentNode;
430
+ parentElement.style.pointerEvents = 'none';
431
+ parentElement.style.opacity = 0.8;
432
+ }
433
+
418
434
  /**
419
435
  * Show modal when book is auto returned
420
436
  */
@@ -665,14 +681,14 @@ export default class IABookActions extends LitElement {
665
681
  async handleLoanAutoRenewed(event) {
666
682
  if (this.loanRenewResult.renewNow) {
667
683
  window?.IALendingIntervals?.clearAll();
668
- this._attemptToRenew = false;
669
684
 
670
685
  this.suppressToast = false;
671
686
  await this.browseHasRenew();
672
687
  await this.resetTimerCountState();
673
688
 
674
689
  // close the modal
675
- await this.modal.closeModal();
690
+ this.modal?.remove();
691
+ this.modal?.showModal({ config: {}, customModalContent: `` });
676
692
 
677
693
  window?.Sentry?.captureMessage(sentryLogs.bookHasRenewed);
678
694
 
@@ -80,7 +80,7 @@ describe('Loan Renew Determine', () => {
80
80
  );
81
81
 
82
82
  expect(toastMsg).to.be.equal(
83
- 'This book will be automatically returned in 2 minutes unless you turn a page.'
83
+ 'With no action, this book will be auto-returned in 2 minutes.'
84
84
  );
85
85
  });
86
86
  });
@@ -188,7 +188,9 @@ describe('Borrow status actions', () => {
188
188
  },
189
189
  ];
190
190
 
191
- expect(el.primaryTitle).to.equal('');
191
+ expect(el.primaryTitle).to.equal(
192
+ 'Renews automatically as long as pages are turned.'
193
+ );
192
194
  expect(el.primaryActions.length).to.equal(2);
193
195
  expect(el.primaryActions[0].text).to.equal('Log In and Borrow');
194
196
  expect(el.primaryActions[0].text).to.equal(expectedPrimaryActions[0].text);
@@ -274,7 +276,7 @@ describe('Browsing expired status', () => {
274
276
  expect(el.loanRenewResult.renewNow).to.equal(false);
275
277
  expect(el.loanRenewResult.secondsLeft).to.equal(0);
276
278
  expect(el.loanRenewResult.texts).to.equal(
277
- 'This book has been automatically returned due to inactivity.'
279
+ 'This book has been returned due to inactivity.'
278
280
  );
279
281
  });
280
282