@internetarchive/ia-book-actions 0.1.9-alpha3 → 0.1.9-alpha5
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:
|
|
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
|
@@ -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 =
|
|
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
|
|
@@ -144,14 +144,14 @@ export default class LoanAnanlytics {
|
|
|
144
144
|
* @memberof LoanAnanlytics
|
|
145
145
|
*/
|
|
146
146
|
sendEvent(eventCategory, eventAction, label, extraParams) {
|
|
147
|
-
console.log(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
);
|
|
147
|
+
// console.log(
|
|
148
|
+
// 'eventCategory:-',
|
|
149
|
+
// eventCategory,
|
|
150
|
+
// '\t||\teventAction:-',
|
|
151
|
+
// eventAction,
|
|
152
|
+
// '\t||\tlabel:-',
|
|
153
|
+
// label
|
|
154
|
+
// );
|
|
155
155
|
|
|
156
156
|
window?.archive_analytics?.send_event_no_sampling(
|
|
157
157
|
eventCategory,
|
package/src/ia-book-actions.js
CHANGED
|
@@ -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
|
|
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
|
|
@@ -236,8 +243,9 @@ export default class IABookActions extends LitElement {
|
|
|
236
243
|
}
|
|
237
244
|
|
|
238
245
|
if (this.borrowType === 'browsed') {
|
|
246
|
+
console.log('this.borrowType', this.borrowType);
|
|
239
247
|
// start timer for browsed.
|
|
240
|
-
this.startBrowseTimer();
|
|
248
|
+
await this.startBrowseTimer();
|
|
241
249
|
}
|
|
242
250
|
|
|
243
251
|
// early return if not borrowed or no action-bar
|
|
@@ -273,13 +281,6 @@ export default class IABookActions extends LitElement {
|
|
|
273
281
|
* dispatched this event from bookreader page changed
|
|
274
282
|
*/
|
|
275
283
|
window.addEventListener('BookReader:userAction', () => {
|
|
276
|
-
this.suppressToast = true;
|
|
277
|
-
this.closeToastManager();
|
|
278
|
-
|
|
279
|
-
if (this.suppressAutoRenew) {
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
284
|
if (this.borrowType === 'browsed') {
|
|
284
285
|
this.autoLoanRenewChecker(true);
|
|
285
286
|
}
|
|
@@ -292,7 +293,6 @@ export default class IABookActions extends LitElement {
|
|
|
292
293
|
* @see TimerCountdown::timerCountdown
|
|
293
294
|
*/
|
|
294
295
|
this.addEventListener('IABookActions:loanRenew', async event => {
|
|
295
|
-
console.log('** IABookActions:loanRenew', event.detail);
|
|
296
296
|
await this.autoLoanRenewChecker(false);
|
|
297
297
|
|
|
298
298
|
/**
|
|
@@ -359,6 +359,7 @@ export default class IABookActions extends LitElement {
|
|
|
359
359
|
* Show the waring modal to ask user if they are still reading
|
|
360
360
|
*/
|
|
361
361
|
async showWarningModal() {
|
|
362
|
+
console.log('****** showWarningModal ******');
|
|
362
363
|
await this.useModalManager();
|
|
363
364
|
|
|
364
365
|
// if secondsLeft < 60, consider it 1 minute
|
|
@@ -379,32 +380,21 @@ export default class IABookActions extends LitElement {
|
|
|
379
380
|
);
|
|
380
381
|
|
|
381
382
|
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
|
-
>
|
|
383
|
+
<div id="custom-buttons" style="display:flex;justify-content:center;">
|
|
388
384
|
<button
|
|
389
385
|
style="${modalButtonStyle.iaButton} ${modalButtonStyle.renew}"
|
|
390
|
-
@click=${
|
|
391
|
-
|
|
392
|
-
// e.target.parentNode.style.pointerEvents = "none";
|
|
393
|
-
// e.target.parentNode.style.opacity = "0.8";
|
|
394
|
-
this._attemptToRenew = true;
|
|
386
|
+
@click=${event => {
|
|
387
|
+
this.changeModalState(event);
|
|
395
388
|
this.autoLoanRenewChecker(true);
|
|
396
389
|
}}
|
|
397
390
|
>
|
|
398
|
-
|
|
399
|
-
? html` <ia-activity-indicator
|
|
400
|
-
mode="processing"
|
|
401
|
-
style=${modalButtonStyle.loaderIcon}
|
|
402
|
-
></ia-activity-indicator>`
|
|
403
|
-
: 'Keep reading'}
|
|
391
|
+
Keep reading
|
|
404
392
|
</button>
|
|
405
393
|
<button
|
|
406
394
|
style="${modalButtonStyle.iaButton} ${modalButtonStyle.return}"
|
|
407
|
-
@click=${
|
|
395
|
+
@click=${event => {
|
|
396
|
+
this.changeModalState(event);
|
|
397
|
+
document.querySelector('ia-book-actions').disableActionGroup = true;
|
|
408
398
|
this.returnNow = true;
|
|
409
399
|
}}
|
|
410
400
|
>
|
|
@@ -415,6 +405,27 @@ export default class IABookActions extends LitElement {
|
|
|
415
405
|
this.modal.showModal({ config, customModalContent: customContent });
|
|
416
406
|
}
|
|
417
407
|
|
|
408
|
+
/**
|
|
409
|
+
* helper function to change button click states on modal-manager
|
|
410
|
+
* - add loader on button click
|
|
411
|
+
* - change button appearance
|
|
412
|
+
*
|
|
413
|
+
* @param {Event} event
|
|
414
|
+
*/
|
|
415
|
+
changeModalState(event) {
|
|
416
|
+
if (event.target === undefined) return;
|
|
417
|
+
|
|
418
|
+
const button = event.target;
|
|
419
|
+
button.innerHTML = `<ia-activity-indicator
|
|
420
|
+
mode="processing"
|
|
421
|
+
style=${modalButtonStyle.loaderIcon}
|
|
422
|
+
></ia-activity-indicator>`;
|
|
423
|
+
|
|
424
|
+
const parentElement = event.target.parentNode;
|
|
425
|
+
parentElement.style.pointerEvents = 'none';
|
|
426
|
+
parentElement.style.opacity = 0.8;
|
|
427
|
+
}
|
|
428
|
+
|
|
418
429
|
/**
|
|
419
430
|
* Show modal when book is auto returned
|
|
420
431
|
*/
|
|
@@ -446,11 +457,8 @@ export default class IABookActions extends LitElement {
|
|
|
446
457
|
* close/hide modal-manager
|
|
447
458
|
*/
|
|
448
459
|
async closeModalManager() {
|
|
449
|
-
console.log('** closeModalManager');
|
|
450
460
|
this.modal = document.querySelector('modal-manager');
|
|
451
|
-
|
|
452
|
-
this.modal?.closeModal();
|
|
453
|
-
}
|
|
461
|
+
this.modal?.closeModal();
|
|
454
462
|
}
|
|
455
463
|
|
|
456
464
|
/**
|
|
@@ -474,11 +482,8 @@ export default class IABookActions extends LitElement {
|
|
|
474
482
|
* close/hide toast message
|
|
475
483
|
*/
|
|
476
484
|
async closeToastManager() {
|
|
477
|
-
console.log('** closeToastManager');
|
|
478
485
|
this.toast = this.shadowRoot.querySelector('toast-template');
|
|
479
|
-
|
|
480
|
-
this.toast?.remove();
|
|
481
|
-
}
|
|
486
|
+
this.toast?.remove();
|
|
482
487
|
}
|
|
483
488
|
|
|
484
489
|
/**
|
|
@@ -518,6 +523,9 @@ export default class IABookActions extends LitElement {
|
|
|
518
523
|
}
|
|
519
524
|
|
|
520
525
|
async browseHasRenew() {
|
|
526
|
+
console.log('****** browseHasRenew ******');
|
|
527
|
+
window?.IALendingIntervals?.clearAll();
|
|
528
|
+
|
|
521
529
|
const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
|
|
522
530
|
const secondsLeft = (loanTime - new Date()) / 1000; // different in seconds
|
|
523
531
|
|
|
@@ -528,24 +536,6 @@ export default class IABookActions extends LitElement {
|
|
|
528
536
|
secondsLeftOnLoan: secondsLeft,
|
|
529
537
|
};
|
|
530
538
|
this.lendingStatus = currStatus;
|
|
531
|
-
|
|
532
|
-
this.startBrowseTimer();
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
startBrowseTimer() {
|
|
536
|
-
clearTimeout(this.browseTimer);
|
|
537
|
-
const {
|
|
538
|
-
browsingExpired,
|
|
539
|
-
user_has_browsed,
|
|
540
|
-
secondsLeftOnLoan,
|
|
541
|
-
} = this.lendingStatus;
|
|
542
|
-
if (!user_has_browsed || browsingExpired) {
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
this.browseTimer = setTimeout(() => {
|
|
547
|
-
this.browseHasExpired();
|
|
548
|
-
}, secondsLeftOnLoan * 1000);
|
|
549
539
|
}
|
|
550
540
|
|
|
551
541
|
/**
|
|
@@ -571,6 +561,26 @@ export default class IABookActions extends LitElement {
|
|
|
571
561
|
window?.Sentry?.captureMessage(sentryLogs.browseHasExpired);
|
|
572
562
|
}
|
|
573
563
|
|
|
564
|
+
async startBrowseTimer() {
|
|
565
|
+
clearTimeout(this.browseTimer);
|
|
566
|
+
|
|
567
|
+
const {
|
|
568
|
+
browsingExpired,
|
|
569
|
+
user_has_browsed,
|
|
570
|
+
secondsLeftOnLoan,
|
|
571
|
+
} = this.lendingStatus;
|
|
572
|
+
if (!user_has_browsed || browsingExpired) {
|
|
573
|
+
console.log('user not browsed', this.lendingStatus);
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
console.log('user browsed', this.lendingStatus);
|
|
578
|
+
|
|
579
|
+
this.browseTimer = setTimeout(() => {
|
|
580
|
+
this.browseHasExpired();
|
|
581
|
+
}, secondsLeftOnLoan * 1000);
|
|
582
|
+
}
|
|
583
|
+
|
|
574
584
|
/**
|
|
575
585
|
* Reset timer animation state after book renewed
|
|
576
586
|
*/
|
|
@@ -665,16 +675,6 @@ export default class IABookActions extends LitElement {
|
|
|
665
675
|
async handleLoanAutoRenewed(event) {
|
|
666
676
|
if (this.loanRenewResult.renewNow) {
|
|
667
677
|
window?.IALendingIntervals?.clearAll();
|
|
668
|
-
this._attemptToRenew = false;
|
|
669
|
-
|
|
670
|
-
this.suppressToast = false;
|
|
671
|
-
await this.browseHasRenew();
|
|
672
|
-
await this.resetTimerCountState();
|
|
673
|
-
|
|
674
|
-
// close the modal
|
|
675
|
-
await this.modal.closeModal();
|
|
676
|
-
|
|
677
|
-
window?.Sentry?.captureMessage(sentryLogs.bookHasRenewed);
|
|
678
678
|
|
|
679
679
|
// testing console....
|
|
680
680
|
console.log('IABookActions: AutoRenewed:- ', {
|
|
@@ -682,6 +682,15 @@ export default class IABookActions extends LitElement {
|
|
|
682
682
|
loanRenewResult: this.loanRenewResult,
|
|
683
683
|
secondsLeftOnLoan: Math.round(this.lendingStatus.secondsLeftOnLoan),
|
|
684
684
|
});
|
|
685
|
+
|
|
686
|
+
await this.browseHasRenew();
|
|
687
|
+
await this.resetTimerCountState();
|
|
688
|
+
|
|
689
|
+
// close the modal
|
|
690
|
+
this.modal?.remove();
|
|
691
|
+
this.modal?.showModal({ config: {}, customModalContent: `` });
|
|
692
|
+
|
|
693
|
+
window?.Sentry?.captureMessage(sentryLogs.bookHasRenewed);
|
|
685
694
|
}
|
|
686
695
|
}
|
|
687
696
|
|
|
@@ -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
|
|
279
|
+
'This book has been returned due to inactivity.'
|
|
278
280
|
);
|
|
279
281
|
});
|
|
280
282
|
|
|
@@ -347,7 +349,7 @@ describe('Auto renew one hour loan', () => {
|
|
|
347
349
|
});
|
|
348
350
|
el.dispatchEvent(myEvent);
|
|
349
351
|
|
|
350
|
-
await aTimeout(
|
|
352
|
+
await aTimeout(1900); // wait for 1.9 second
|
|
351
353
|
await el.updateComplete;
|
|
352
354
|
|
|
353
355
|
expect(el.loanRenewResult.texts).to.equal(
|