@internetarchive/ia-book-actions 0.1.4-alpha5 → 0.1.4-alpha7
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 +12 -1
- package/package.json +1 -1
- package/src/components/timer-countdown.js +2 -2
- package/src/ia-book-actions.js +19 -13
package/demo/index.html
CHANGED
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
iaBookActions.localCache = localCache;
|
|
133
133
|
|
|
134
134
|
let loanTotalTime2Min = { loanTotalTime: 20, loanRenewAtLast: 15, pageChangedInLast: 5 };
|
|
135
|
-
let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast:
|
|
135
|
+
let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 230, pageChangedInLast: 15 };
|
|
136
136
|
let loanTotalTime1Hour = { loanTotalTime: 3600, loanRenewAtLast: 600, pageChangedInLast: 900 };
|
|
137
137
|
|
|
138
138
|
iaBookActions.loanRenewTimeConfig = loanTotalTime5Min;
|
|
@@ -298,6 +298,16 @@
|
|
|
298
298
|
})
|
|
299
299
|
);
|
|
300
300
|
})
|
|
301
|
+
|
|
302
|
+
document.querySelector('.pageChangedEventSec').addEventListener('click', () => {
|
|
303
|
+
window.dispatchEvent(
|
|
304
|
+
new CustomEvent('BookReader:userAction', {
|
|
305
|
+
detail: {},
|
|
306
|
+
bubbles: true,
|
|
307
|
+
composed: true,
|
|
308
|
+
})
|
|
309
|
+
);
|
|
310
|
+
})
|
|
301
311
|
</script>
|
|
302
312
|
|
|
303
313
|
<div>
|
|
@@ -310,6 +320,7 @@
|
|
|
310
320
|
</td>
|
|
311
321
|
<td>
|
|
312
322
|
<button class="pageChangedEvent">Page Change Event</button>
|
|
323
|
+
<button class="pageChangedEventSec">BR Controls Event</button>
|
|
313
324
|
</td>
|
|
314
325
|
</tr>
|
|
315
326
|
</table>
|
package/package.json
CHANGED
|
@@ -32,10 +32,10 @@ export default class TimerCountdown extends LitElement {
|
|
|
32
32
|
this.loanRenewAtLast = 0;
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* store time when timer is started
|
|
36
36
|
* @type {string}
|
|
37
37
|
*/
|
|
38
|
-
this.timeWhenTimerStart =
|
|
38
|
+
this.timeWhenTimerStart = '';
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* delay seconds in setInterval function
|
package/src/ia-book-actions.js
CHANGED
|
@@ -240,7 +240,7 @@ export default class IABookActions extends LitElement {
|
|
|
240
240
|
*/
|
|
241
241
|
setTimeout(
|
|
242
242
|
() => {
|
|
243
|
-
this.startLoanTokenPoller();
|
|
243
|
+
if (!hasExpired) this.startLoanTokenPoller();
|
|
244
244
|
},
|
|
245
245
|
|
|
246
246
|
// if book is renew while reading, let's wait to execute create-token api
|
|
@@ -260,13 +260,13 @@ export default class IABookActions extends LitElement {
|
|
|
260
260
|
* dispatched this event from bookreader page changed
|
|
261
261
|
*/
|
|
262
262
|
window.addEventListener('BookReader:userAction', () => {
|
|
263
|
+
console.log('user action');
|
|
263
264
|
this.suppressToast = true;
|
|
265
|
+
this.closeToastManager();
|
|
264
266
|
|
|
265
267
|
if (this.borrowType === 'browsed') {
|
|
266
268
|
this.autoLoanRenewChecker(true);
|
|
267
269
|
}
|
|
268
|
-
|
|
269
|
-
return nothing;
|
|
270
270
|
});
|
|
271
271
|
|
|
272
272
|
/**
|
|
@@ -293,6 +293,7 @@ export default class IABookActions extends LitElement {
|
|
|
293
293
|
* @see TimerCountdown::timerCountdown
|
|
294
294
|
*/
|
|
295
295
|
this.addEventListener('IABookActions:loanRenew', async event => {
|
|
296
|
+
console.log('event::loanRenew');
|
|
296
297
|
await this.autoLoanRenewChecker(false);
|
|
297
298
|
|
|
298
299
|
// show warning message with remaining time to auto returned it.
|
|
@@ -321,6 +322,16 @@ export default class IABookActions extends LitElement {
|
|
|
321
322
|
this.loanRenewResult = this.loanRenewHelper.result;
|
|
322
323
|
}
|
|
323
324
|
|
|
325
|
+
/**
|
|
326
|
+
* close/hide toast message
|
|
327
|
+
*/
|
|
328
|
+
async closeToastManager() {
|
|
329
|
+
let toastTemplate = this.shadowRoot.querySelector('toast-template');
|
|
330
|
+
if (toastTemplate) {
|
|
331
|
+
toastTemplate?.remove();
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
324
335
|
/**
|
|
325
336
|
* Show toast messages on some specific loan renew features. e.g.
|
|
326
337
|
* - show message when book is auto renewed
|
|
@@ -330,14 +341,11 @@ export default class IABookActions extends LitElement {
|
|
|
330
341
|
async showToastMessage() {
|
|
331
342
|
if (this.suppressToast) return;
|
|
332
343
|
|
|
333
|
-
|
|
334
|
-
if (!iaBookActions) return;
|
|
335
|
-
|
|
336
|
-
let toastTemplate = iaBookActions.querySelector('toast-template');
|
|
344
|
+
let toastTemplate = this.shadowRoot.querySelector('toast-template');
|
|
337
345
|
if (!toastTemplate) {
|
|
338
346
|
toastTemplate = document.createElement('toast-template');
|
|
339
347
|
}
|
|
340
|
-
await
|
|
348
|
+
await this.shadowRoot.appendChild(toastTemplate);
|
|
341
349
|
|
|
342
350
|
// if secondsLeft < 60, consider it 1 minute
|
|
343
351
|
let { secondsLeft } = this.loanRenewResult;
|
|
@@ -574,8 +582,7 @@ export default class IABookActions extends LitElement {
|
|
|
574
582
|
* @param {string} event.detail.data.error - error message
|
|
575
583
|
*/
|
|
576
584
|
handleLendingActionError(event) {
|
|
577
|
-
|
|
578
|
-
this.handleToggleActionGroup();
|
|
585
|
+
this.disableActionGroup = false;
|
|
579
586
|
|
|
580
587
|
// clear all intervals for lending system when error occured
|
|
581
588
|
window?.IALendingIntervals?.clearAll();
|
|
@@ -583,7 +590,8 @@ export default class IABookActions extends LitElement {
|
|
|
583
590
|
const action = event?.detail?.action;
|
|
584
591
|
const errorMsg = event?.detail?.data?.error;
|
|
585
592
|
|
|
586
|
-
|
|
593
|
+
// template not show create_token errors
|
|
594
|
+
if (errorMsg && action !== 'create_token') this.showErrorModal(errorMsg, action);
|
|
587
595
|
|
|
588
596
|
// if error related to loan token
|
|
589
597
|
// - clear tokenPoller interval
|
|
@@ -617,8 +625,6 @@ export default class IABookActions extends LitElement {
|
|
|
617
625
|
|
|
618
626
|
/* show error message if something went wrong */
|
|
619
627
|
async showErrorModal(errorMsg, action) {
|
|
620
|
-
this.disableActionGroup = false;
|
|
621
|
-
|
|
622
628
|
// check if this.modal passed as prop
|
|
623
629
|
if (!this.modal) {
|
|
624
630
|
this.modal = document.querySelector('modal-manager');
|