@internetarchive/ia-book-actions 0.1.8 → 0.1.9-alpha1
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 +1 -1
- package/package.json +1 -1
- package/src/assets/data/lending-get-status-service.js +1 -1
- package/src/components/timer-countdown.js +2 -0
- package/src/core/services/get-lending-actions.js +3 -4
- package/src/core/services/loan-renew-helper.js +1 -1
- package/src/ia-book-actions.js +137 -25
package/demo/index.html
CHANGED
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
iaBookActions.returnUrl = '';
|
|
132
132
|
iaBookActions.localCache = localCache;
|
|
133
133
|
|
|
134
|
-
let loanTotalTime2Min = { loanTotalTime:
|
|
134
|
+
let loanTotalTime2Min = { loanTotalTime: 10, loanRenewAtLast: 5, pageChangedInLast: 8 };
|
|
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
|
@@ -100,7 +100,7 @@ export const canBrowseAndBorrow = {
|
|
|
100
100
|
// userid: "",
|
|
101
101
|
bookUrl: '/details/practicalorganic00plim',
|
|
102
102
|
daysLeftOnLoan: 0,
|
|
103
|
-
isAdmin:
|
|
103
|
+
isAdmin: false,
|
|
104
104
|
isArchiveOrgLending: true,
|
|
105
105
|
isAvailable: false,
|
|
106
106
|
isAvailableForBrowsing: false,
|
|
@@ -40,7 +40,7 @@ import ActionsConfig from './actions-config.js';
|
|
|
40
40
|
* @enum {string}
|
|
41
41
|
*/
|
|
42
42
|
export const bookTitles = {
|
|
43
|
-
available_1hr: 'Renews
|
|
43
|
+
available_1hr: 'Renews automatically as long as pages are turned.',
|
|
44
44
|
available_14d: 'This book can be borrowed for 14 days.',
|
|
45
45
|
available_pd: 'Book available to patrons with print disabilities.',
|
|
46
46
|
available_waitlist: 'A waitlist is available.',
|
|
@@ -49,7 +49,7 @@ export const bookTitles = {
|
|
|
49
49
|
being_borrowed: 'Another patron is using this book. Please check back later.',
|
|
50
50
|
eligible_pd: 'You are eligible for print-disabled access.',
|
|
51
51
|
on_waitlist: 'You are on the waitlist for this book.',
|
|
52
|
-
session_expired: '',
|
|
52
|
+
session_expired: 'Renews automatically as long as pages are turned.',
|
|
53
53
|
unavailable: 'This book is not available at this time.',
|
|
54
54
|
};
|
|
55
55
|
|
|
@@ -98,8 +98,7 @@ export class GetLendingActions {
|
|
|
98
98
|
let isBrowsing =
|
|
99
99
|
lendingStatus.user_has_browsed && !lendingStatus.browsingExpired;
|
|
100
100
|
if (isBrowsing) {
|
|
101
|
-
primaryTitleText =
|
|
102
|
-
'Returns automatically after 25 minutes of inactivity.';
|
|
101
|
+
primaryTitleText = bookTitles.available_1hr;
|
|
103
102
|
} else {
|
|
104
103
|
primaryTitleText = `Your loan of this book has ${lendingStatus.daysLeftOnLoan} days left.`;
|
|
105
104
|
}
|
|
@@ -16,7 +16,7 @@ export class LoanRenewHelper {
|
|
|
16
16
|
this.loanRenewMessage =
|
|
17
17
|
'This book has been renewed for #time #unitsOfTime.';
|
|
18
18
|
this.loanReturnWarning =
|
|
19
|
-
'
|
|
19
|
+
'With no action, this book will be auto-returned in #time #unitsOfTime.';
|
|
20
20
|
|
|
21
21
|
// private props
|
|
22
22
|
this.result = {
|
package/src/ia-book-actions.js
CHANGED
|
@@ -23,6 +23,15 @@ export const events = {
|
|
|
23
23
|
browseExpired: 'IABookReader:BrowsingHasExpired',
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
export const modalButtonStyle = {
|
|
27
|
+
iaButton:
|
|
28
|
+
'min-height:3rem;cursor:pointer;color:white;border-radius:0.4rem;border:1px solid transparent;padding:4px 8px;',
|
|
29
|
+
renew: 'background:#194880;border:1px solid #c5d1df;',
|
|
30
|
+
return: 'background:#d9534f;color:white;border:1px solid #c5d1df;',
|
|
31
|
+
refresh:
|
|
32
|
+
'background:none;font-size:inherit;border:0;padding:0;color:#0000ee;cursor:pointer;text-decoration:underline',
|
|
33
|
+
};
|
|
34
|
+
|
|
26
35
|
export default class IABookActions extends LitElement {
|
|
27
36
|
static get properties() {
|
|
28
37
|
return {
|
|
@@ -62,6 +71,7 @@ export default class IABookActions extends LitElement {
|
|
|
62
71
|
this.sharedObserver = undefined;
|
|
63
72
|
this.disableActionGroup = false;
|
|
64
73
|
this.modal = undefined;
|
|
74
|
+
this.toast = undefined;
|
|
65
75
|
this.tokenDelay = 120; // in seconds
|
|
66
76
|
|
|
67
77
|
// private props
|
|
@@ -287,7 +297,7 @@ export default class IABookActions extends LitElement {
|
|
|
287
297
|
'browsingExpired' in this.lendingStatus &&
|
|
288
298
|
this.lendingStatus?.browsingExpired;
|
|
289
299
|
if (hasExpired && e.target.nodeName !== 'IA-BOOK-ACTIONS') {
|
|
290
|
-
window.location?.reload();
|
|
300
|
+
// window.location?.reload();
|
|
291
301
|
}
|
|
292
302
|
});
|
|
293
303
|
|
|
@@ -323,7 +333,9 @@ export default class IABookActions extends LitElement {
|
|
|
323
333
|
secondsLeft -= 60;
|
|
324
334
|
|
|
325
335
|
this.loanRenewResult.secondsLeft = secondsLeft;
|
|
326
|
-
|
|
336
|
+
|
|
337
|
+
// this.showToastMessage();
|
|
338
|
+
this.showModalManager();
|
|
327
339
|
}
|
|
328
340
|
});
|
|
329
341
|
}
|
|
@@ -347,17 +359,126 @@ export default class IABookActions extends LitElement {
|
|
|
347
359
|
}
|
|
348
360
|
|
|
349
361
|
/**
|
|
362
|
+
* create / select the modal-manager component on DOM
|
|
363
|
+
*
|
|
364
|
+
* @memberof IABookActions
|
|
365
|
+
*/
|
|
366
|
+
async useModalManager() {
|
|
367
|
+
if (!this.modal) {
|
|
368
|
+
this.modal = document.querySelector('modal-manager');
|
|
369
|
+
|
|
370
|
+
if (!this.modal) this.modal = document.createElement('modal-manager');
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
this.modal.id = 'action-bar-modal';
|
|
374
|
+
await document.body.appendChild(this.modal);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
async showModalManager(type = '') {
|
|
378
|
+
if (this.suppressToast) return;
|
|
379
|
+
|
|
380
|
+
await this.useModalManager();
|
|
381
|
+
|
|
382
|
+
// if secondsLeft < 60, consider it 1 minute
|
|
383
|
+
let { secondsLeft } = this.loanRenewResult;
|
|
384
|
+
if (secondsLeft === undefined) {
|
|
385
|
+
secondsLeft = this.lendingStatus.secondsLeftOnLoan;
|
|
386
|
+
} else {
|
|
387
|
+
secondsLeft = secondsLeft > 60 ? secondsLeft : 60;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
let customContent = '';
|
|
391
|
+
|
|
392
|
+
const config = new ModalConfig();
|
|
393
|
+
|
|
394
|
+
config.headline = 'Are you still here?';
|
|
395
|
+
config.showCloseButton = false;
|
|
396
|
+
config.closeOnBackdropClick = false;
|
|
397
|
+
|
|
398
|
+
if (type === 'expired') {
|
|
399
|
+
config.message = 'This book has been returned due to inactivity.';
|
|
400
|
+
customContent = html`<br />
|
|
401
|
+
<div style="text-align: center">
|
|
402
|
+
<button
|
|
403
|
+
style="${modalButtonStyle.iaButton} ${modalButtonStyle.renew}"
|
|
404
|
+
@click=${() => {
|
|
405
|
+
window.location?.reload();
|
|
406
|
+
}}
|
|
407
|
+
>
|
|
408
|
+
Okay
|
|
409
|
+
</button>
|
|
410
|
+
</div> `;
|
|
411
|
+
} else {
|
|
412
|
+
config.message = this.loanRenewHelper?.getMessageTexts(
|
|
413
|
+
this.loanRenewResult.texts,
|
|
414
|
+
secondsLeft
|
|
415
|
+
);
|
|
416
|
+
customContent = html`<br />
|
|
417
|
+
<div style="text-align: center">
|
|
418
|
+
<button
|
|
419
|
+
style="${modalButtonStyle.iaButton} ${modalButtonStyle.renew}"
|
|
420
|
+
@click=${() => {
|
|
421
|
+
this.autoLoanRenewChecker(true);
|
|
422
|
+
}}
|
|
423
|
+
>
|
|
424
|
+
Keep reading
|
|
425
|
+
</button>
|
|
426
|
+
<button
|
|
427
|
+
style="${modalButtonStyle.iaButton} ${modalButtonStyle.return}"
|
|
428
|
+
@click=${() => {
|
|
429
|
+
this.dispatchEvent(new CustomEvent('returnNow', {}));
|
|
430
|
+
// this.browseHasExpired();
|
|
431
|
+
}}
|
|
432
|
+
>
|
|
433
|
+
Return the book
|
|
434
|
+
</button>
|
|
435
|
+
</div> `;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
this.modal.showModal({ config, customModalContent: customContent });
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* close/hide modal-manager
|
|
443
|
+
*/
|
|
444
|
+
async closeModalManager() {
|
|
445
|
+
console.log('** closeModalManager');
|
|
446
|
+
this.modal = document.querySelector('modal-manager');
|
|
447
|
+
if (this.modal) {
|
|
448
|
+
this.modal?.closeModal();
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* @deprecated
|
|
454
|
+
* create / select the toast-template component on DOM
|
|
455
|
+
*
|
|
456
|
+
* @memberof IABookActions
|
|
457
|
+
*/
|
|
458
|
+
async useToastManager() {
|
|
459
|
+
if (!this.toast) {
|
|
460
|
+
this.toast = this.shadowRoot.querySelector('toast-template');
|
|
461
|
+
|
|
462
|
+
if (!this.toast) this.toast = document.createElement('toast-template');
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
await this.shadowRoot.appendChild(this.toast);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* @deprecated
|
|
350
470
|
* close/hide toast message
|
|
351
471
|
*/
|
|
352
472
|
async closeToastManager() {
|
|
353
473
|
console.log('** closeToastManager');
|
|
354
|
-
|
|
355
|
-
if (
|
|
356
|
-
|
|
474
|
+
this.toast = this.shadowRoot.querySelector('toast-template');
|
|
475
|
+
if (this.toast) {
|
|
476
|
+
this.toast?.remove();
|
|
357
477
|
}
|
|
358
478
|
}
|
|
359
479
|
|
|
360
480
|
/**
|
|
481
|
+
* @deprecated
|
|
361
482
|
* Show toast messages on some specific loan renew features. e.g.
|
|
362
483
|
* - show message when book is auto renewed
|
|
363
484
|
* - show message when book is expired
|
|
@@ -370,11 +491,7 @@ export default class IABookActions extends LitElement {
|
|
|
370
491
|
});
|
|
371
492
|
if (this.suppressToast) return;
|
|
372
493
|
|
|
373
|
-
|
|
374
|
-
if (!toastTemplate) {
|
|
375
|
-
toastTemplate = document.createElement('toast-template');
|
|
376
|
-
}
|
|
377
|
-
await this.shadowRoot.appendChild(toastTemplate);
|
|
494
|
+
await this.useToastManager();
|
|
378
495
|
|
|
379
496
|
// if secondsLeft < 60, consider it 1 minute
|
|
380
497
|
let { secondsLeft } = this.loanRenewResult;
|
|
@@ -391,7 +508,7 @@ export default class IABookActions extends LitElement {
|
|
|
391
508
|
secondsLeft
|
|
392
509
|
);
|
|
393
510
|
|
|
394
|
-
|
|
511
|
+
this.toast?.showToast({
|
|
395
512
|
config,
|
|
396
513
|
});
|
|
397
514
|
}
|
|
@@ -445,8 +562,9 @@ export default class IABookActions extends LitElement {
|
|
|
445
562
|
this.loanRenewResult.texts =
|
|
446
563
|
'This book has been automatically returned due to inactivity.';
|
|
447
564
|
|
|
448
|
-
this.suppressToast = false;
|
|
449
|
-
this.showToastMessage();
|
|
565
|
+
// this.suppressToast = false;
|
|
566
|
+
// this.showToastMessage();
|
|
567
|
+
this.showModalManager('expired');
|
|
450
568
|
|
|
451
569
|
window?.Sentry?.captureMessage(sentryLogs.browseHasExpired);
|
|
452
570
|
}
|
|
@@ -547,9 +665,12 @@ export default class IABookActions extends LitElement {
|
|
|
547
665
|
|
|
548
666
|
this.suppressToast = false;
|
|
549
667
|
await this.browseHasRenew();
|
|
550
|
-
await this.showToastMessage();
|
|
668
|
+
// await this.showToastMessage();
|
|
551
669
|
await this.resetTimerCountState();
|
|
552
670
|
|
|
671
|
+
// close the modal
|
|
672
|
+
await this.modal?.closeModal();
|
|
673
|
+
|
|
553
674
|
window?.Sentry?.captureMessage(sentryLogs.bookHasRenewed);
|
|
554
675
|
|
|
555
676
|
// testing console....
|
|
@@ -656,16 +777,7 @@ export default class IABookActions extends LitElement {
|
|
|
656
777
|
|
|
657
778
|
/* show error message if something went wrong */
|
|
658
779
|
async showErrorModal(errorMsg, action) {
|
|
659
|
-
|
|
660
|
-
if (!this.modal) {
|
|
661
|
-
this.modal = document.querySelector('modal-manager');
|
|
662
|
-
|
|
663
|
-
// check the DOM if <modal-manager> already there
|
|
664
|
-
if (!this.modal) this.modal = document.createElement('modal-manager');
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
this.modal.id = 'action-bar-modal';
|
|
668
|
-
await document.body.appendChild(this.modal);
|
|
780
|
+
await this.useModalManager();
|
|
669
781
|
|
|
670
782
|
const modalConfig = new ModalConfig({
|
|
671
783
|
title: 'Lending error',
|
|
@@ -676,7 +788,7 @@ export default class IABookActions extends LitElement {
|
|
|
676
788
|
|
|
677
789
|
if (action === 'create_token') {
|
|
678
790
|
const refreshButton = html`<button
|
|
679
|
-
style="
|
|
791
|
+
style="${modalButtonStyle.refresh}"
|
|
680
792
|
@click=${() => window.location.reload(true)}
|
|
681
793
|
>
|
|
682
794
|
refresh
|