@internetarchive/ia-book-actions 0.1.11-b6 → 0.1.11-b8

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.1.11-b6",
3
+ "version": "0.1.11-b8",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -21,7 +21,7 @@ export default async function ActionsHandlerService(options) {
21
21
  const tokenError = 'loan token not found. please try again later.';
22
22
  const borrowError =
23
23
  'This book is not available to borrow at this time. Please try again later.';
24
- const erroneousActions = ['browse_book', 'borrow_book', 'create_token'];
24
+ const erroneousActions = ['browse_book', 'borrow_book', 'create_token', 'renew_loan'];
25
25
  const shouldReturnError =
26
26
  location?.href?.indexOf('?error=true') !== -1 &&
27
27
  location?.hostname !== 'archive.org';
@@ -142,7 +142,13 @@ export default class ActionsHandler extends LitElement {
142
142
  action,
143
143
  identifier: this.identifier,
144
144
  success: data => {
145
- console.log("RENEW_LOAN --- ", data, action, data.loan, this.identifier);
145
+ console.log(
146
+ 'RENEW_LOAN --- ',
147
+ data,
148
+ action,
149
+ data.loan,
150
+ this.identifier
151
+ );
146
152
  if (data?.success === true && data?.loan?.renewal === true) {
147
153
  this.setBrowseTimeSession();
148
154
  this.dispatchEvent(
@@ -77,7 +77,6 @@ export default class IABookActions extends LitElement {
77
77
  this.barType = 'action'; // 'title'|'action'
78
78
  this.sharedObserver = undefined;
79
79
  this.disableActionGroup = false;
80
- this.modal = undefined;
81
80
  this.tokenDelay = 120; // in seconds
82
81
 
83
82
  // private props
@@ -308,19 +307,18 @@ export default class IABookActions extends LitElement {
308
307
  this.loanRenewResult = this.loanRenewHelper.result;
309
308
  }
310
309
 
311
- /**
312
- * create / select the modal-manager component on DOM
313
- * @memberof IABookActions
314
- */
315
- async useModalManager() {
316
- if (!this.modal) {
317
- this.modal = document.querySelector('modal-manager');
310
+ /** @returns HTMLElement */
311
+ get modal() {
312
+ let modalOnDom = document.querySelector('modal-manager');
318
313
 
319
- if (!this.modal) this.modal = document.createElement('modal-manager');
314
+ if (!modalOnDom) {
315
+ const newModal = document.createElement('modal-manager');
316
+ document.body.appendChild(newModal);
317
+ modalOnDom = newModal;
320
318
  }
321
319
 
322
- this.modal.id = 'action-bar-modal';
323
- await document.body.appendChild(this.modal);
320
+ modalOnDom.id = 'action-bar-modal';
321
+ return modalOnDom;
324
322
  }
325
323
 
326
324
  /**
@@ -328,7 +326,6 @@ export default class IABookActions extends LitElement {
328
326
  */
329
327
  async showWarningModal() {
330
328
  console.log('****** showWarningModal ******');
331
- await this.useModalManager();
332
329
 
333
330
  // if secondsLeft < 60, consider it 1 minute
334
331
  let { secondsLeft } = this.loanRenewResult;
@@ -338,16 +335,17 @@ export default class IABookActions extends LitElement {
338
335
  secondsLeft = secondsLeft > 60 ? secondsLeft : 60;
339
336
  }
340
337
 
341
- const config = new ModalConfig();
342
- config.headline = 'Are you still here?';
343
- config.showCloseButton = false;
344
- config.closeOnBackdropClick = false;
345
- config.message = this.loanRenewHelper?.getMessageTexts(
346
- this.loanRenewResult.texts,
347
- secondsLeft
348
- );
338
+ const config = new ModalConfig({
339
+ headline: 'Are you still here?',
340
+ showCloseButton: false,
341
+ closeOnBackdropClick: false,
342
+ message: this.loanRenewHelper?.getMessageTexts(
343
+ this.loanRenewResult.texts,
344
+ secondsLeft
345
+ )
346
+ });
349
347
 
350
- const customContent = html`<br />
348
+ const customModalContent = html`<br />
351
349
  <div id="custom-buttons" style="display:flex;justify-content:center;">
352
350
  <button
353
351
  style="${modalButtonStyle.iaButton} ${modalButtonStyle.renew}"
@@ -367,7 +365,7 @@ export default class IABookActions extends LitElement {
367
365
  </button>
368
366
  </div> `;
369
367
 
370
- this.modal?.showModal({ config, customModalContent: customContent });
368
+ this.modal?.showModal({ config, customModalContent });
371
369
  }
372
370
 
373
371
  async patronWantsToRenewBook(event) {
@@ -403,15 +401,15 @@ export default class IABookActions extends LitElement {
403
401
  */
404
402
  async showExpiredModal() {
405
403
  console.log('showExpiredModal()');
406
- await this.useModalManager();
407
404
 
408
- const config = new ModalConfig();
409
- config.headline = '';
410
- config.showCloseButton = false;
411
- config.closeOnBackdropClick = false;
412
- config.message = 'This book has been returned due to inactivity.';
405
+ const config = new ModalConfig({
406
+ headline: '',
407
+ showCloseButton: false,
408
+ closeOnBackdropClick: false,
409
+ message: 'This book has been returned due to inactivity.'
410
+ });
413
411
 
414
- const customContent = html`<br />
412
+ const customModalContent = html`<br />
415
413
  <div style="text-align: center">
416
414
  <button
417
415
  style="${modalButtonStyle.iaButton} ${modalButtonStyle.renew}"
@@ -423,7 +421,7 @@ export default class IABookActions extends LitElement {
423
421
  </button>
424
422
  </div> `;
425
423
 
426
- this.modal?.showModal({ config, customModalContent: customContent });
424
+ this.modal?.showModal({ config, customModalContent });
427
425
  }
428
426
 
429
427
  /**
@@ -669,6 +667,7 @@ export default class IABookActions extends LitElement {
669
667
  await this.resetTimerCountState();
670
668
 
671
669
  // close the modal
670
+ this.modal.removeAttribute('id');
672
671
  this.modal?.remove();
673
672
  this.modal?.showModal({ config: {}, customModalContent: `` });
674
673
 
@@ -908,7 +907,6 @@ export default class IABookActions extends LitElement {
908
907
 
909
908
  /* show error message if something went wrong */
910
909
  async showErrorModal(errorMsg, action) {
911
- await this.useModalManager();
912
910
 
913
911
  const modalConfig = new ModalConfig({
914
912
  title: 'Lending error',