@internetarchive/ia-book-actions 0.0.29-alpha26 → 0.0.29-alpha28
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
|
@@ -128,8 +128,8 @@
|
|
|
128
128
|
iaBookActions.localCache = localCache;
|
|
129
129
|
iaBookActions.loanRenewConfig = {
|
|
130
130
|
totalTime: 20, // 60 second = 1 min
|
|
131
|
-
autoCheckAt:
|
|
132
|
-
pageChangedInLast:
|
|
131
|
+
autoCheckAt: 12, // totalTime - 10th minute
|
|
132
|
+
pageChangedInLast: 5, // within last 15 second/minute
|
|
133
133
|
env: 'dev', // dev/prod
|
|
134
134
|
};
|
|
135
135
|
|
|
@@ -285,7 +285,7 @@
|
|
|
285
285
|
// dispatch event to say book page has flipped
|
|
286
286
|
document.querySelector('ia-book-actions').dispatchEvent(
|
|
287
287
|
new CustomEvent('BookReader:pageChanged', {
|
|
288
|
-
detail: { hasPageChanged: true },
|
|
288
|
+
detail: { props: { hasPageChanged: true }},
|
|
289
289
|
bubbles: true,
|
|
290
290
|
composed: true,
|
|
291
291
|
})
|
package/package.json
CHANGED
|
@@ -4,14 +4,14 @@ export default class TimerCountdown extends LitElement {
|
|
|
4
4
|
static get properties() {
|
|
5
5
|
return {
|
|
6
6
|
timeLeftOnLoan: { type: Number },
|
|
7
|
-
|
|
7
|
+
loanRenewConfig: { type: Object },
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
constructor() {
|
|
12
12
|
super();
|
|
13
13
|
this.timeLeftOnLoan = 0;
|
|
14
|
-
this.
|
|
14
|
+
this.loanRenewConfig = 0;
|
|
15
15
|
|
|
16
16
|
// private props
|
|
17
17
|
this.timerInterval = undefined;
|
|
@@ -35,7 +35,7 @@ export default class TimerCountdown extends LitElement {
|
|
|
35
35
|
// execute from last 10th minute to 0th minute
|
|
36
36
|
// - 10th - to check if user has viewed
|
|
37
37
|
// - till 0th - to show warning msg with remaining time to auto returned
|
|
38
|
-
if (Math.round(this.timeLeftOnLoan) <= this.autoCheckAt) {
|
|
38
|
+
if (Math.round(this.timeLeftOnLoan) <= this.loanRenewConfig.autoCheckAt) {
|
|
39
39
|
this.dispatchEvent(
|
|
40
40
|
new CustomEvent('IABookActions:loanRenew', {
|
|
41
41
|
detail: {
|
|
@@ -48,8 +48,8 @@ export default class TimerCountdown extends LitElement {
|
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
// clear interval if timer is < this.autoCheckAt
|
|
52
|
-
if (this.timeLeftOnLoan < this.autoCheckAt) {
|
|
51
|
+
// clear interval if timer is < this.loanRenewConfig.autoCheckAt
|
|
52
|
+
if (this.timeLeftOnLoan < this.loanRenewConfig.autoCheckAt) {
|
|
53
53
|
clearInterval(this.timerInterval);
|
|
54
54
|
}
|
|
55
55
|
}, 1000);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { nothing } from 'lit';
|
|
2
|
-
import { ToastConfig } from '@internetarchive/toast-manager';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* This class is used to determine if use is eligible for auto renew loan.
|
|
@@ -115,30 +114,6 @@ export class LoanRenewHelper {
|
|
|
115
114
|
});
|
|
116
115
|
}
|
|
117
116
|
|
|
118
|
-
/**
|
|
119
|
-
* Show toast messages on some specific loan renew features. e.g.
|
|
120
|
-
* - show success msg when book is auto renewed
|
|
121
|
-
* - show success msg when book is auto returned
|
|
122
|
-
* - show warninig msg when book is about to auto returned
|
|
123
|
-
*/
|
|
124
|
-
async showToastMessage() {
|
|
125
|
-
if (this.hideToast) return false;
|
|
126
|
-
|
|
127
|
-
const iaBookActions = document.querySelector('ia-book-actions').shadowRoot;
|
|
128
|
-
let toastTemplate = iaBookActions.querySelector('toast-template');
|
|
129
|
-
if (!toastTemplate) {
|
|
130
|
-
toastTemplate = document.createElement('toast-template');
|
|
131
|
-
}
|
|
132
|
-
await iaBookActions.appendChild(toastTemplate);
|
|
133
|
-
|
|
134
|
-
const config = new ToastConfig();
|
|
135
|
-
config.texts = this.result.texts?.replace(/#time/, this.result.timeLeft);
|
|
136
|
-
config.dismisOnClick = true;
|
|
137
|
-
toastTemplate.showToast({
|
|
138
|
-
config,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
117
|
/**
|
|
143
118
|
* Helper function to get time difference
|
|
144
119
|
*
|
package/src/ia-book-actions.js
CHANGED
|
@@ -84,7 +84,7 @@ export default class IABookActions extends LitElement {
|
|
|
84
84
|
this.loanRenewResult = {
|
|
85
85
|
texts: null,
|
|
86
86
|
renewNow: false,
|
|
87
|
-
timeLeft: 0
|
|
87
|
+
timeLeft: 0,
|
|
88
88
|
};
|
|
89
89
|
|
|
90
90
|
this._shadowRoot = this.attachShadow({ mode: 'open' });
|
|
@@ -219,7 +219,7 @@ export default class IABookActions extends LitElement {
|
|
|
219
219
|
() => {
|
|
220
220
|
this.startLoanTokenPoller();
|
|
221
221
|
|
|
222
|
-
if (!this.loanRenewResult.renewNow) {
|
|
222
|
+
if (this.borrowType === 'browsed' && !this.loanRenewResult.renewNow) {
|
|
223
223
|
this.resetTimerCountState();
|
|
224
224
|
}
|
|
225
225
|
},
|
|
@@ -234,19 +234,24 @@ export default class IABookActions extends LitElement {
|
|
|
234
234
|
* 2. IABookActions:loanRenew - dispatched from timer-countdown component
|
|
235
235
|
*/
|
|
236
236
|
bindLoanRenewEvents() {
|
|
237
|
-
|
|
237
|
+
/**
|
|
238
|
+
* dispatched this event from bookreader page changed
|
|
239
|
+
*/
|
|
238
240
|
window.addEventListener('BookReader:pageChanged', event => {
|
|
239
|
-
console.log(event.detail.props);
|
|
240
241
|
if (this.borrowType === 'browsed' && event.detail.props.hasPageChanged) {
|
|
241
|
-
console.log('actual page changed executed!')
|
|
242
|
+
console.log('actual page changed executed!');
|
|
242
243
|
this.autoLoanRenewChecker(true);
|
|
243
244
|
}
|
|
244
245
|
|
|
245
246
|
return nothing;
|
|
246
247
|
});
|
|
247
248
|
|
|
249
|
+
/**
|
|
250
|
+
* Detech click-event on document to close toast-template
|
|
251
|
+
*/
|
|
248
252
|
document.addEventListener('click', () => {
|
|
249
|
-
if (this.loanRenewHelper && this.
|
|
253
|
+
if (this.loanRenewHelper && this.loanRenewResult.timeLeft > 0) {
|
|
254
|
+
console.log('1');
|
|
250
255
|
this.suppressToast = true;
|
|
251
256
|
}
|
|
252
257
|
});
|
|
@@ -257,13 +262,11 @@ export default class IABookActions extends LitElement {
|
|
|
257
262
|
* 2. show warning message having remaining time
|
|
258
263
|
*/
|
|
259
264
|
this.addEventListener('IABookActions:loanRenew', async event => {
|
|
260
|
-
const eventDetails = event.detail;
|
|
261
|
-
|
|
262
265
|
await this.autoLoanRenewChecker(false);
|
|
263
266
|
|
|
264
267
|
// show warning message with remaining time to auto returned it.
|
|
265
|
-
if (this.
|
|
266
|
-
this.loanRenewResult.timeLeft =
|
|
268
|
+
if (this.loanRenewResult.renewNow === false) {
|
|
269
|
+
this.loanRenewResult.timeLeft = event.detail.timeLeft;
|
|
267
270
|
this.showToastMessage();
|
|
268
271
|
}
|
|
269
272
|
});
|
|
@@ -282,10 +285,15 @@ export default class IABookActions extends LitElement {
|
|
|
282
285
|
this.loanRenewResult = this.loanRenewHelper.result;
|
|
283
286
|
}
|
|
284
287
|
|
|
288
|
+
/**
|
|
289
|
+
* Show toast messages on some specific loan renew features. e.g.
|
|
290
|
+
* - show success msg when book is auto renewed
|
|
291
|
+
* - show success msg when book is auto returned
|
|
292
|
+
* - show warninig msg when book is about to auto returned
|
|
293
|
+
*/
|
|
285
294
|
async showToastMessage() {
|
|
286
|
-
if (this.suppressToast) return
|
|
295
|
+
if (this.suppressToast) return;
|
|
287
296
|
|
|
288
|
-
// this.result = this.loanRenewHelper.result;
|
|
289
297
|
const iaBookActions = document.querySelector('ia-book-actions').shadowRoot;
|
|
290
298
|
let toastTemplate = iaBookActions.querySelector('toast-template');
|
|
291
299
|
if (!toastTemplate) {
|
|
@@ -294,7 +302,10 @@ export default class IABookActions extends LitElement {
|
|
|
294
302
|
await iaBookActions.appendChild(toastTemplate);
|
|
295
303
|
|
|
296
304
|
const config = new ToastConfig();
|
|
297
|
-
config.texts = this.loanRenewResult.texts?.replace(
|
|
305
|
+
config.texts = this.loanRenewResult.texts?.replace(
|
|
306
|
+
/#time/,
|
|
307
|
+
this.loanRenewResult.timeLeft
|
|
308
|
+
);
|
|
298
309
|
config.dismisOnClick = true;
|
|
299
310
|
toastTemplate.showToast({
|
|
300
311
|
config,
|
|
@@ -358,28 +369,23 @@ export default class IABookActions extends LitElement {
|
|
|
358
369
|
* Reset timer animation state after book renewed
|
|
359
370
|
*/
|
|
360
371
|
async resetTimerCountState() {
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
const timerCountdown = this.shadowRoot.querySelector('timer-countdown');
|
|
364
|
-
const animationCircle = timerCountdown.shadowRoot.querySelector('.circle');
|
|
372
|
+
const timerCountdown = this._shadowRoot.querySelector('timer-countdown');
|
|
373
|
+
if (!timerCountdown) return;
|
|
365
374
|
|
|
366
|
-
|
|
367
|
-
const circleStroke = 315; // (π * 2 * radius)
|
|
375
|
+
const secondsLeft = Number(this.lendingStatus.secondsLeftOnLoan);
|
|
368
376
|
const strokeDashOffset =
|
|
369
|
-
(secondsLeft / this.loanRenewConfig.totalTime) *
|
|
370
|
-
circleStroke;
|
|
377
|
+
(secondsLeft / this.loanRenewConfig.totalTime) * 315;
|
|
371
378
|
|
|
372
379
|
// set seconds left in loan expire
|
|
373
|
-
timerCountdown.style?.setProperty(
|
|
374
|
-
|
|
375
|
-
`${secondsLeft}s`
|
|
376
|
-
);
|
|
380
|
+
timerCountdown.style?.setProperty('--timerSeconds', `${secondsLeft}s`);
|
|
381
|
+
|
|
377
382
|
// set circle stroke offset left in loan expire
|
|
378
383
|
timerCountdown.style?.setProperty(
|
|
379
384
|
'--timerStroke',
|
|
380
|
-
`${Number(strokeDashOffset)}`
|
|
385
|
+
`${Number(strokeDashOffset)}` // the perimeter of the circle = (π * 2 * radius)
|
|
381
386
|
);
|
|
382
387
|
|
|
388
|
+
const animationCircle = timerCountdown.shadowRoot.querySelector('.circle');
|
|
383
389
|
animationCircle.style.animationName = 'none';
|
|
384
390
|
setTimeout(() => {
|
|
385
391
|
animationCircle.style.animationName = 'circletimer';
|
|
@@ -409,7 +415,7 @@ export default class IABookActions extends LitElement {
|
|
|
409
415
|
return this.borrowType === 'browsed'
|
|
410
416
|
? html`<timer-countdown
|
|
411
417
|
.timeLeftOnLoan=${Number(this.lendingStatus.secondsLeftOnLoan)}
|
|
412
|
-
.
|
|
418
|
+
.loanRenewConfig=${this.loanRenewConfig}
|
|
413
419
|
></timer-countdown>`
|
|
414
420
|
: nothing;
|
|
415
421
|
}
|