@internetarchive/ia-book-actions 0.0.12-1 → 0.0.12-2

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.12-1",
3
+ "version": "0.0.12-2",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -144,7 +144,6 @@ export default class GetLendingActions {
144
144
  primaryTitle: 'Book available to patrons with print disabilities.',
145
145
  primaryActions: [unavailable],
146
146
  primaryColor: 'primary',
147
- secondaryActions: [],
148
147
  };
149
148
  }
150
149
 
@@ -76,7 +76,12 @@ export class LoanTokenPoller {
76
76
  action,
77
77
  error: data => {
78
78
  this.disconnectedInterval(); // stop token fetch api
79
- this.errorCallback({ detail: { action, data } });
79
+
80
+ if (isInitial) {
81
+ this.errorCallback({ detail: { action, data } });
82
+ } else {
83
+ this.errorCallback({ detail: { action, data, isExpired: true } });
84
+ }
80
85
  },
81
86
  success: () => {
82
87
  if (isInitial) this.successCallback();
@@ -162,6 +162,10 @@ export default class IABookActions extends LitElement {
162
162
  this.startBrowseTimer();
163
163
  }
164
164
 
165
+ if (this.lendingStatus.browsingExpired) {
166
+ this.tokenPoller.disconnectedInterval();
167
+ }
168
+
165
169
  // early return if not borrowed or no action-bar
166
170
  if (!this.borrowType || this.barType === 'title') {
167
171
  this.lendingBarPostInit();
@@ -261,6 +265,7 @@ export default class IABookActions extends LitElement {
261
265
  * @param {Object} event - The employee who is responsible for the project
262
266
  * @param {string} event.detail.action - action when error occurred like 'browseBook', 'borrowBook'
263
267
  * @param {string} event.detail.data.error - error message
268
+ * @param {string} event.detail.data.isExpired - triggered when loan is expired
264
269
  */
265
270
  handleLendingActionError(event) {
266
271
  // toggle activity loader
@@ -268,8 +273,9 @@ export default class IABookActions extends LitElement {
268
273
 
269
274
  const action = event?.detail?.action;
270
275
  const errorMsg = event?.detail?.data?.error;
276
+ const loanExpired = event?.detail?.data?.isExpired;
271
277
 
272
- if (errorMsg) this.showErrorModal(errorMsg, action);
278
+ if (errorMsg) this.showErrorModal(errorMsg, action, loanExpired);
273
279
 
274
280
  // update action bar state if book is not available to browse or borrow.
275
281
  if (errorMsg && errorMsg.match(/not available to borrow/gm)) {
@@ -290,7 +296,7 @@ export default class IABookActions extends LitElement {
290
296
  }
291
297
 
292
298
  /* show error message if something went wrong */
293
- async showErrorModal(errorMsg, action) {
299
+ async showErrorModal(errorMsg, action, loanExpired) {
294
300
  this.disableActionGroup = false;
295
301
 
296
302
  // check if this.modal passed as prop
@@ -311,23 +317,14 @@ export default class IABookActions extends LitElement {
311
317
  });
312
318
 
313
319
  if (action === 'create_token') {
314
- const refreshButton = html`<button
315
- style="background:none;font-size:inherit;border:0;padding:0;color:#0000ee;cursor:pointer;text-decoration:underline"
316
- @click=${() => window.location.reload(true)}
317
- >
318
- refresh
319
- </button>`;
320
-
321
320
  modalConfig.closeOnBackdropClick = false;
322
- modalConfig.showCloseButton = false;
323
- modalConfig.message = html` Uh oh, something went wrong trying to access
324
- this book.<br />
325
- Please ${refreshButton} to try again or send us an email to
326
- <a
327
- href="mailto:info@archive.org?subject=Help: cannot access my borrowed book: ${this
328
- .identifier}"
329
- >info@archive.org</a
330
- >`;
321
+ if (loanExpired) {
322
+ modalConfig.showCloseButton = true;
323
+ modalConfig.message = this.loanExpiredMessage;
324
+ } else {
325
+ modalConfig.showCloseButton = false;
326
+ modalConfig.message = this.loanErrorMessage;
327
+ }
331
328
  }
332
329
 
333
330
  this.modal.showModal({
@@ -335,6 +332,29 @@ export default class IABookActions extends LitElement {
335
332
  });
336
333
  }
337
334
 
335
+ /* eslint-disable class-methods-use-this */
336
+ get loanExpiredMessage() {
337
+ return html`Your current loan is expired, please close this model and click
338
+ on <strong>Borrow Again</strong> button to continue reading this book`;
339
+ }
340
+
341
+ get loanErrorMessage() {
342
+ const refreshButton = html`<button
343
+ style="background:none;font-size:inherit;border:0;padding:0;color:#0000ee;cursor:pointer;text-decoration:underline"
344
+ @click=${() => window.location.reload(true)}
345
+ >
346
+ refresh
347
+ </button>`;
348
+
349
+ return html`Uh oh, something went wrong trying to access this book.<br />
350
+ Please ${refreshButton} to try again or send us an email to
351
+ <a
352
+ href="mailto:info@archive.org?subject=Help: cannot access my borrowed book: ${this
353
+ .identifier}"
354
+ >info@archive.org</a
355
+ >`;
356
+ }
357
+
338
358
  get iconClass() {
339
359
  return this.width <= mobileContainerWidth ? 'mobile' : 'desktop';
340
360
  }