@internetarchive/ia-book-actions 0.0.29-alpha10 → 0.0.29-alpha12
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 +7 -7
- package/package.json +1 -1
- package/src/components/collapsible-action-group.js +17 -7
- package/src/components/timer-countdown.js +2 -2
- package/src/components/toast-message.js +5 -7
- package/src/core/config/analytics-event-and-category.js +1 -0
- package/src/core/services/actions-handler/actions-handler.js +5 -5
- package/src/core/services/{one-hour-auto-renew.js → one-hour-loan-renew.js} +54 -57
- package/src/ia-book-actions.js +52 -44
package/demo/index.html
CHANGED
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
import { LocalCache } from '@internetarchive/local-cache';
|
|
98
98
|
|
|
99
99
|
const localCache = new LocalCache({
|
|
100
|
-
namespace: '
|
|
100
|
+
namespace: 'loanRenew',
|
|
101
101
|
defaultTTL: 1 * 60, // 1 minute
|
|
102
102
|
});
|
|
103
103
|
|
|
@@ -128,14 +128,14 @@
|
|
|
128
128
|
iaBookActions.tokenDelay = 2000; // 2 seconds
|
|
129
129
|
iaBookActions.returnUrl = 'https://openlibrary.org';
|
|
130
130
|
iaBookActions.localCache = localCache;
|
|
131
|
-
iaBookActions.
|
|
131
|
+
iaBookActions.loanRenewConfig = {
|
|
132
132
|
totalTime: 60, // 60 second = 1 min
|
|
133
133
|
autoCheckAt: 55, // totalTime - 10th minute
|
|
134
|
-
|
|
134
|
+
pageChangedInLast: 15, // within last 15 second/minute
|
|
135
135
|
};
|
|
136
136
|
|
|
137
137
|
let lendingStatus1 = iaBookActions.lendingStatus;
|
|
138
|
-
let secondsLeftOnLoan = iaBookActions.
|
|
138
|
+
let secondsLeftOnLoan = iaBookActions.loanRenewConfig.totalTime;
|
|
139
139
|
|
|
140
140
|
document.querySelectorAll('.titleBar input[type=checkbox]').forEach((item) => {
|
|
141
141
|
item.addEventListener('click', (e) => {
|
|
@@ -212,10 +212,10 @@
|
|
|
212
212
|
await localCache.set({
|
|
213
213
|
key: `${identifier}-loanTime`,
|
|
214
214
|
value: new Date(), // current time
|
|
215
|
-
ttl: Number(iaBookActions.
|
|
216
|
-
})
|
|
215
|
+
ttl: Number(iaBookActions.loanRenewConfig.totalTime),
|
|
216
|
+
});
|
|
217
217
|
|
|
218
|
-
await localCache.delete(`${identifier}-
|
|
218
|
+
await localCache.delete(`${identifier}-pageChangedTime`);
|
|
219
219
|
} catch (error) {}
|
|
220
220
|
|
|
221
221
|
} else if(e.target.value === 'browsingExpired') {
|
package/package.json
CHANGED
|
@@ -9,6 +9,10 @@ import CollapsibleActionGroupStyle from '../assets/styles/collapsible-action-gro
|
|
|
9
9
|
|
|
10
10
|
import { tabletContainerWidth } from '../core/config/constants.js';
|
|
11
11
|
import { purchaseIcon } from '../assets/data/purchase.js';
|
|
12
|
+
import {
|
|
13
|
+
analyticsCategories,
|
|
14
|
+
analyticsActions,
|
|
15
|
+
} from '../core/config/analytics-event-and-category.js';
|
|
12
16
|
import {
|
|
13
17
|
dropdownOpened,
|
|
14
18
|
dropdownClosed,
|
|
@@ -28,7 +32,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
28
32
|
dropdownArrow: { type: String },
|
|
29
33
|
disabled: { type: Boolean },
|
|
30
34
|
returnUrl: { type: String },
|
|
31
|
-
|
|
35
|
+
renewNow: { type: Boolean },
|
|
32
36
|
};
|
|
33
37
|
}
|
|
34
38
|
|
|
@@ -48,7 +52,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
48
52
|
this.loaderIcon = 'https://archive.org/upload/images/tree/loading.gif';
|
|
49
53
|
this.disabled = false;
|
|
50
54
|
this.returnUrl = '';
|
|
51
|
-
this.
|
|
55
|
+
this.renewNow = false;
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
updated(changed) {
|
|
@@ -59,17 +63,23 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
59
63
|
this.resetActions();
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
if (changed.has('
|
|
63
|
-
this.
|
|
66
|
+
if (changed.has('renewNow') && this.renewNow === true) {
|
|
67
|
+
this.dispatchLoanRenewEvent();
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
// dispatch this event to loan renew handler
|
|
68
|
-
|
|
72
|
+
dispatchLoanRenewEvent() {
|
|
73
|
+
const { category, action } = {
|
|
74
|
+
category: analyticsCategories.browse,
|
|
75
|
+
action: analyticsActions.browseLoanRenew,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// listen in action-handler.js to execute ajax call on petabox.
|
|
69
79
|
this.dispatchEvent(
|
|
70
|
-
new CustomEvent('
|
|
80
|
+
new CustomEvent('loanRenew', {
|
|
71
81
|
detail: {
|
|
72
|
-
event: {
|
|
82
|
+
event: { category, action },
|
|
73
83
|
},
|
|
74
84
|
})
|
|
75
85
|
);
|
|
@@ -35,9 +35,9 @@ export default class TimerCountdown extends LitElement {
|
|
|
35
35
|
// execute 50th minute check
|
|
36
36
|
if (Math.round(this.time) === this.autoCheckAt) {
|
|
37
37
|
this.dispatchEvent(
|
|
38
|
-
new CustomEvent('
|
|
38
|
+
new CustomEvent('IABookActions:loanRenew', {
|
|
39
39
|
detail: {
|
|
40
|
-
|
|
40
|
+
isPageChanged: false,
|
|
41
41
|
},
|
|
42
42
|
bubbles: true,
|
|
43
43
|
composed: true,
|
|
@@ -5,27 +5,24 @@ export class ToastMessage extends LitElement {
|
|
|
5
5
|
return {
|
|
6
6
|
texts: { type: String },
|
|
7
7
|
dismisOnClick: { type: Boolean },
|
|
8
|
-
hideToast: { type: Boolean },
|
|
9
8
|
clostAfter: { type: Number },
|
|
10
9
|
};
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
constructor() {
|
|
14
13
|
super();
|
|
15
|
-
this.texts =
|
|
16
|
-
this.textClass = '';
|
|
17
|
-
this.hideToast = false;
|
|
14
|
+
this.texts = null;
|
|
18
15
|
this.clostAfter = 0;
|
|
19
16
|
}
|
|
20
17
|
|
|
21
18
|
render() {
|
|
22
|
-
return
|
|
19
|
+
return this.texts
|
|
23
20
|
? html`
|
|
24
21
|
<span
|
|
25
|
-
class="toast-message fade-in
|
|
22
|
+
class="toast-message fade-in"
|
|
26
23
|
title="Click/tap to close"
|
|
27
24
|
@click=${() => {
|
|
28
|
-
this.dismisOnClick ?
|
|
25
|
+
this.dismisOnClick ? this.texts = null : nothing;
|
|
29
26
|
}}
|
|
30
27
|
>${this.texts}</span
|
|
31
28
|
>
|
|
@@ -40,6 +37,7 @@ export class ToastMessage extends LitElement {
|
|
|
40
37
|
:host {
|
|
41
38
|
display: inline-block;
|
|
42
39
|
}
|
|
40
|
+
|
|
43
41
|
.toast-message {
|
|
44
42
|
z-index: 2;
|
|
45
43
|
position: absolute;
|
|
@@ -13,6 +13,7 @@ export const analyticsCategories = {
|
|
|
13
13
|
export const analyticsActions = {
|
|
14
14
|
browse: 'Borrow-1Hour',
|
|
15
15
|
browseAgain: 'Borrow-Again',
|
|
16
|
+
browseLoanRenew: 'Borrow-Loan-Renew',
|
|
16
17
|
borrow: 'Borrow-14Days',
|
|
17
18
|
waitlistJoin: 'JoinWaitlist',
|
|
18
19
|
waitlistLeave: 'LeaveWaitlist',
|
|
@@ -43,8 +43,8 @@ export default class ActionsHandler extends LitElement {
|
|
|
43
43
|
this.sendEvent(category, action);
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
this.addEventListener('
|
|
47
|
-
this.
|
|
46
|
+
this.addEventListener('loanRenew', ({ detail }) => {
|
|
47
|
+
this.handleLoanRenew();
|
|
48
48
|
const { category, action } = detail.event;
|
|
49
49
|
this.sendEvent(category, action);
|
|
50
50
|
});
|
|
@@ -117,7 +117,7 @@ export default class ActionsHandler extends LitElement {
|
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
handleLoanRenew() {
|
|
121
121
|
const action = 'renew_loan';
|
|
122
122
|
this.setBrowseTimeSession();
|
|
123
123
|
|
|
@@ -289,11 +289,11 @@ export default class ActionsHandler extends LitElement {
|
|
|
289
289
|
await this.localCache.set({
|
|
290
290
|
key: `${this.identifier}-loanTime`,
|
|
291
291
|
value: new Date(), // current time
|
|
292
|
-
ttl: Number(this.
|
|
292
|
+
ttl: Number(this.loanRenewConfig.totalTime),
|
|
293
293
|
});
|
|
294
294
|
|
|
295
295
|
// delete flip time
|
|
296
|
-
await this.localCache.delete(`${this.identifier}-
|
|
296
|
+
await this.localCache.delete(`${this.identifier}-pageChangedTime`);
|
|
297
297
|
} catch (error) {
|
|
298
298
|
console.log(error);
|
|
299
299
|
}
|
|
@@ -4,44 +4,43 @@ import { nothing } from 'lit';
|
|
|
4
4
|
* This class is used to determine if use is eligible for auto renew loan.
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
|
-
export class
|
|
7
|
+
export class OneHourLoanRenew {
|
|
8
8
|
constructor(
|
|
9
|
-
|
|
9
|
+
isPageChanged,
|
|
10
10
|
identifier,
|
|
11
11
|
localCache,
|
|
12
|
-
|
|
12
|
+
loanRenewConfig
|
|
13
13
|
) {
|
|
14
|
-
this.
|
|
14
|
+
this.isPageChanged = isPageChanged;
|
|
15
15
|
this.identifier = identifier;
|
|
16
16
|
this.localCache = localCache;
|
|
17
|
-
this.
|
|
17
|
+
this.loanRenewConfig = loanRenewConfig;
|
|
18
18
|
|
|
19
19
|
// messages for auto return machenism
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
20
|
+
this.loanRenewMessage = 'This book has been renewed for another hour.';
|
|
21
|
+
this.loanReturnMessage =
|
|
22
22
|
'This book has been auto-returned due to inactivity.';
|
|
23
|
-
this.
|
|
23
|
+
this.loanReturnWarning =
|
|
24
24
|
'This book will be auto-returned in 10 minutes unless you turn a page.';
|
|
25
25
|
|
|
26
26
|
// private props
|
|
27
|
-
this.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
browseAgainNow: false,
|
|
27
|
+
this.loanRenewResult = {
|
|
28
|
+
texts: null,
|
|
29
|
+
renewNow: false,
|
|
31
30
|
};
|
|
32
31
|
|
|
33
|
-
return this.
|
|
32
|
+
return this.handleLoanRenew();
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
handleLoanRenew() {
|
|
37
36
|
try {
|
|
38
37
|
// when user click/flip on book page
|
|
39
|
-
if (this.
|
|
40
|
-
console.log('page
|
|
41
|
-
return this.
|
|
38
|
+
if (this.isPageChanged) {
|
|
39
|
+
console.log('page changed!!');
|
|
40
|
+
return this.pageChanged(); // user clicked on page
|
|
42
41
|
}
|
|
43
|
-
|
|
44
|
-
return this.
|
|
42
|
+
|
|
43
|
+
return this.autoChecker(); // auto checker at 50th minute
|
|
45
44
|
} catch (error) {
|
|
46
45
|
console.log(error);
|
|
47
46
|
}
|
|
@@ -49,20 +48,11 @@ export class OneHourAutoRenew {
|
|
|
49
48
|
return nothing;
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
async setPageFlippedTime() {
|
|
54
|
-
await this.localCache.set({
|
|
55
|
-
key: `${this.identifier}-pageFlipTime`,
|
|
56
|
-
value: new Date(), // current time
|
|
57
|
-
ttl: Number(this.autoRenewConfig.totalTime),
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async userFlippedBookPage() {
|
|
51
|
+
async pageChanged() {
|
|
62
52
|
const {
|
|
63
53
|
totalTime, // 60
|
|
64
54
|
autoCheckAt, // 50
|
|
65
|
-
} = this.
|
|
55
|
+
} = this.loanRenewConfig;
|
|
66
56
|
const currentTime = new Date();
|
|
67
57
|
const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
|
|
68
58
|
|
|
@@ -70,33 +60,32 @@ export class OneHourAutoRenew {
|
|
|
70
60
|
loanTime,
|
|
71
61
|
totalTime - autoCheckAt,
|
|
72
62
|
'add'
|
|
73
|
-
);
|
|
63
|
+
);
|
|
74
64
|
|
|
75
65
|
// if user viewed new page in last 10 minutes, renew immediately
|
|
76
66
|
if (currentTime >= lastTimeFrame) {
|
|
77
|
-
console.log('
|
|
78
|
-
this.
|
|
79
|
-
this.
|
|
80
|
-
this.autoRenewResult.browseAgainNow = true;
|
|
67
|
+
console.log('Yes, borrow it again now!');
|
|
68
|
+
this.loanRenewResult.texts = this.loanRenewMessage;
|
|
69
|
+
this.loanRenewResult.renewNow = true;
|
|
81
70
|
|
|
82
|
-
this.
|
|
71
|
+
this.setLoanRenewedTime();
|
|
83
72
|
}
|
|
84
73
|
|
|
85
|
-
this.
|
|
86
|
-
return this.
|
|
74
|
+
this.setPageChangedTime();
|
|
75
|
+
return this.loanRenewResult;
|
|
87
76
|
}
|
|
88
77
|
|
|
89
|
-
async
|
|
78
|
+
async autoChecker() {
|
|
90
79
|
const currentTime = new Date();
|
|
91
|
-
const {
|
|
80
|
+
const { pageChangedInLast } = this.loanRenewConfig;
|
|
92
81
|
const lastPageFlipTime = await this.localCache.get(
|
|
93
|
-
`${this.identifier}-
|
|
82
|
+
`${this.identifier}-pageChangedTime`
|
|
94
83
|
);
|
|
95
84
|
|
|
96
85
|
// last 15 min if used flipped a page.
|
|
97
86
|
const lastFlipTimeFrame = this.changeTime(
|
|
98
87
|
currentTime,
|
|
99
|
-
|
|
88
|
+
pageChangedInLast,
|
|
100
89
|
'sub'
|
|
101
90
|
); // 15 seconds
|
|
102
91
|
|
|
@@ -105,29 +94,37 @@ export class OneHourAutoRenew {
|
|
|
105
94
|
lastPageFlipTime <= lastFlipTimeFrame
|
|
106
95
|
) {
|
|
107
96
|
// not viewed
|
|
108
|
-
console.log('Not viewed,
|
|
109
|
-
this.
|
|
110
|
-
this.
|
|
111
|
-
this.autoRenewResult.hideToast = false;
|
|
97
|
+
console.log('Not viewed, don\'t borrow it!');
|
|
98
|
+
this.loanRenewResult.texts = this.loanReturnWarning;
|
|
99
|
+
this.loanRenewResult.renewNow = false;
|
|
112
100
|
} else if (lastPageFlipTime >= lastFlipTimeFrame) {
|
|
113
101
|
// viewed in last time frame
|
|
114
|
-
console.log('
|
|
115
|
-
this.
|
|
116
|
-
this.
|
|
117
|
-
this.autoRenewResult.hideToast = false;
|
|
102
|
+
console.log('Yes viewed, borrow it again!');
|
|
103
|
+
this.loanRenewResult.texts = this.loanRenewMessage;
|
|
104
|
+
this.loanRenewResult.renewNow = true;
|
|
118
105
|
|
|
119
|
-
this.
|
|
106
|
+
this.setLoanRenewedTime();
|
|
120
107
|
}
|
|
121
108
|
|
|
122
|
-
return this.
|
|
109
|
+
return this.loanRenewResult;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
// save page changed time in indexedDB
|
|
114
|
+
async setPageChangedTime() {
|
|
115
|
+
await this.localCache.set({
|
|
116
|
+
key: `${this.identifier}-pageChangedTime`,
|
|
117
|
+
value: new Date(), // current time
|
|
118
|
+
ttl: Number(this.loanRenewConfig.totalTime),
|
|
119
|
+
});
|
|
123
120
|
}
|
|
124
121
|
|
|
125
|
-
async
|
|
122
|
+
async setLoanRenewedTime() {
|
|
126
123
|
try {
|
|
127
124
|
// last 15 min if used flipped a page.
|
|
128
125
|
const expireDate = this.changeTime(
|
|
129
126
|
new Date(),
|
|
130
|
-
this.
|
|
127
|
+
this.loanRenewConfig.totalTime,
|
|
131
128
|
'add'
|
|
132
129
|
); // 15 seconds
|
|
133
130
|
|
|
@@ -135,11 +132,11 @@ export class OneHourAutoRenew {
|
|
|
135
132
|
await this.localCache.set({
|
|
136
133
|
key: `${this.identifier}-loanTime`,
|
|
137
134
|
value: expireDate, // expireDate time
|
|
138
|
-
ttl: Number(this.
|
|
135
|
+
ttl: Number(this.loanRenewConfig.totalTime),
|
|
139
136
|
});
|
|
140
137
|
|
|
141
|
-
// delete
|
|
142
|
-
await this.localCache.delete(`${this.identifier}-
|
|
138
|
+
// delete pageChangedTime when book is auto renew at nth minute
|
|
139
|
+
await this.localCache.delete(`${this.identifier}-pageChangedTime`);
|
|
143
140
|
} catch (error) {
|
|
144
141
|
console.log(error);
|
|
145
142
|
}
|
package/src/ia-book-actions.js
CHANGED
|
@@ -15,7 +15,7 @@ import './components/toast-message.js';
|
|
|
15
15
|
import { mobileContainerWidth } from './core/config/constants.js';
|
|
16
16
|
import { GetLendingActions } from './core/services/get-lending-actions.js';
|
|
17
17
|
import { LoanTokenPoller } from './core/services/loan-token-poller.js';
|
|
18
|
-
import {
|
|
18
|
+
import { OneHourLoanRenew } from './core/services/one-hour-loan-renew.js';
|
|
19
19
|
|
|
20
20
|
export const events = {
|
|
21
21
|
browseExpired: 'IABookReader:BrowsingHasExpired',
|
|
@@ -41,8 +41,8 @@ export default class IABookActions extends LitElement {
|
|
|
41
41
|
modal: { Object },
|
|
42
42
|
tokenDelay: { type: Number },
|
|
43
43
|
localCache: { type: Object },
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
loanRenewConfig: { type: Object },
|
|
45
|
+
loanRenewResult: { type: Object },
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -62,17 +62,18 @@ export default class IABookActions extends LitElement {
|
|
|
62
62
|
this.modal = undefined;
|
|
63
63
|
this.tokenDelay = 120000; // 2 minutes
|
|
64
64
|
this.localCache = new LocalCache({
|
|
65
|
-
namespace: '
|
|
65
|
+
namespace: 'loanRenew',
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
// loan auto renew
|
|
69
|
-
this.
|
|
70
|
-
this.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
this.isPageChanged = false;
|
|
70
|
+
this.loanRenewConfig = {};
|
|
71
|
+
this.loanRenewResult = {
|
|
72
|
+
texts: null,
|
|
73
|
+
renewNow: false,
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
+
|
|
76
77
|
// private props
|
|
77
78
|
this.primaryActions = [];
|
|
78
79
|
this.primaryTitle = '';
|
|
@@ -83,7 +84,7 @@ export default class IABookActions extends LitElement {
|
|
|
83
84
|
this.consecutiveLoanCounts = 1; // consecutive loan count
|
|
84
85
|
this.browserTimer = undefined;
|
|
85
86
|
|
|
86
|
-
this.
|
|
87
|
+
this.bindLoanRenewEvents();
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
disconnectedCallback() {
|
|
@@ -111,45 +112,53 @@ export default class IABookActions extends LitElement {
|
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
|
|
114
|
-
|
|
115
|
-
// dispatched this event from
|
|
116
|
-
this.addEventListener('
|
|
117
|
-
const isPageClick = event.detail.bookPageChange;
|
|
115
|
+
bindLoanRenewEvents() {
|
|
116
|
+
// dispatched this event from bookreader page changed
|
|
117
|
+
this.addEventListener('BookReader:pageChanged', e => {
|
|
118
118
|
|
|
119
|
-
// early return if
|
|
120
|
-
if (
|
|
119
|
+
// early return if book is not browsed (1 hour borrow)
|
|
120
|
+
if (this.borrowType !== 'browsed') return nothing;
|
|
121
121
|
|
|
122
|
-
this.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.localCache,
|
|
126
|
-
this.autoRenewConfig
|
|
127
|
-
);
|
|
122
|
+
this.isPageChanged = true;
|
|
123
|
+
this.executeLoanRenew();
|
|
124
|
+
})
|
|
128
125
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
this.
|
|
126
|
+
// dispatched this event from timer-countdown
|
|
127
|
+
this.addEventListener('IABookActions:loanRenew', e => {
|
|
128
|
+
this.isPageChanged = false;
|
|
129
|
+
this.executeLoanRenew();
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
async executeLoanRenew() {
|
|
134
|
+
this.loanRenewResult = await new OneHourLoanRenew(
|
|
135
|
+
this.isPageChanged,
|
|
136
|
+
this.identifier,
|
|
137
|
+
this.localCache,
|
|
138
|
+
this.loanRenewConfig
|
|
139
|
+
);
|
|
137
140
|
|
|
138
|
-
|
|
139
|
-
|
|
141
|
+
console.log(this.loanRenewResult)
|
|
142
|
+
|
|
143
|
+
if (this.loanRenewResult.renewNow) {
|
|
144
|
+
this.tokenPoller.disconnectedInterval();
|
|
145
|
+
await this.browseHasRenew();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return nothing;
|
|
140
149
|
}
|
|
141
150
|
|
|
142
151
|
async browseHasExpired() {
|
|
143
152
|
const currStatus = { ...this.lendingStatus, browsingExpired: true };
|
|
144
153
|
this.lendingStatus = currStatus;
|
|
145
|
-
this.
|
|
154
|
+
this.loanRenewResult.renewNow = false;
|
|
146
155
|
|
|
147
156
|
// remove respected key:value
|
|
148
157
|
await this.localCache.delete(`${this.identifier}-loanTime`);
|
|
149
|
-
await this.localCache.delete(`${this.identifier}-
|
|
158
|
+
await this.localCache.delete(`${this.identifier}-pageChangedTime`);
|
|
150
159
|
|
|
151
160
|
// show message after browsed book is expired.
|
|
152
|
-
this.
|
|
161
|
+
this.loanRenewResult.texts = 'This book has been auto-returned due to inactivity.';
|
|
153
162
|
}
|
|
154
163
|
|
|
155
164
|
async browseHasRenew() {
|
|
@@ -278,7 +287,7 @@ export default class IABookActions extends LitElement {
|
|
|
278
287
|
// - start token poller immediately
|
|
279
288
|
setTimeout(() => {
|
|
280
289
|
this.startLoanTokenPoller();
|
|
281
|
-
}, this.
|
|
290
|
+
}, this.loanRenewResult.renewNow ? this.tokenDelay : 100);
|
|
282
291
|
}
|
|
283
292
|
|
|
284
293
|
render() {
|
|
@@ -304,7 +313,7 @@ export default class IABookActions extends LitElement {
|
|
|
304
313
|
return this.borrowType === 'browsed'
|
|
305
314
|
? html`<timer-countdown
|
|
306
315
|
time=${Number(this.lendingStatus.secondsLeftOnLoan)}
|
|
307
|
-
.autoCheckAt=${this.
|
|
316
|
+
.autoCheckAt=${this.loanRenewConfig.autoCheckAt}
|
|
308
317
|
></timer-countdown>`
|
|
309
318
|
: nothing;
|
|
310
319
|
}
|
|
@@ -312,16 +321,15 @@ export default class IABookActions extends LitElement {
|
|
|
312
321
|
get toastMessageTemplate() {
|
|
313
322
|
return html`
|
|
314
323
|
<toast-message
|
|
315
|
-
.texts=${this.
|
|
324
|
+
.texts=${this.loanRenewResult.texts}
|
|
316
325
|
?dismisOnClick=${Boolean(true)}
|
|
317
|
-
?hideToast=${this.autoRenewResult.hideToast}
|
|
318
326
|
></toast-message>
|
|
319
327
|
`;
|
|
320
328
|
}
|
|
321
329
|
|
|
322
330
|
get bookActionBar() {
|
|
323
331
|
return html`
|
|
324
|
-
<button @click=${() => this.
|
|
332
|
+
<button @click=${() => this.pageChangedEvent()}>Page Change</button>
|
|
325
333
|
<collapsible-action-group
|
|
326
334
|
.userid=${this.userid}
|
|
327
335
|
.identifier=${this.identifier}
|
|
@@ -332,10 +340,10 @@ export default class IABookActions extends LitElement {
|
|
|
332
340
|
.borrowType=${this.borrowType}
|
|
333
341
|
.returnUrl=${this.returnUrl}
|
|
334
342
|
.localCache=${this.localCache}
|
|
335
|
-
.
|
|
343
|
+
.loanRenewConfig=${this.loanRenewConfig}
|
|
336
344
|
?hasAdminAccess=${this.hasAdminAccess}
|
|
337
345
|
?disabled=${this.disableActionGroup}
|
|
338
|
-
?
|
|
346
|
+
?renewNow=${this.loanRenewResult.renewNow}
|
|
339
347
|
@lendingActionError=${this.handleLendingActionError}
|
|
340
348
|
@toggleActionGroup=${this.handleToggleActionGroup}
|
|
341
349
|
>
|
|
@@ -346,11 +354,11 @@ export default class IABookActions extends LitElement {
|
|
|
346
354
|
}
|
|
347
355
|
|
|
348
356
|
// will move this function to bookreader...
|
|
349
|
-
|
|
357
|
+
pageChangedEvent() {
|
|
350
358
|
// dispatch event to say book page has flipped
|
|
351
359
|
document.querySelector('ia-book-actions').dispatchEvent(
|
|
352
|
-
new CustomEvent('
|
|
353
|
-
detail: {
|
|
360
|
+
new CustomEvent('BookReader:pageChanged', {
|
|
361
|
+
detail: { isPageChanged: true },
|
|
354
362
|
bubbles: true,
|
|
355
363
|
composed: true,
|
|
356
364
|
})
|