@internetarchive/ia-book-actions 0.0.29-alpha3 → 0.0.29-alpha31
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 +33 -32
- package/package.json +12 -6
- package/src/assets/data/lending-get-status-service.js +2 -2
- package/src/assets/styles/collapsible-action-group.js +2 -1
- package/src/components/collapsible-action-group.js +25 -12
- package/src/components/info-icon.js +0 -9
- package/src/components/text-group.js +1 -1
- package/src/components/timer-countdown.js +59 -74
- package/src/core/config/analytics-event-and-category.js +1 -0
- package/src/core/services/actions-config.js +2 -2
- package/src/core/services/actions-handler/actions-handler.js +37 -31
- package/src/core/services/get-lending-actions.js +6 -11
- package/src/core/services/loan-renew-helper.js +165 -0
- package/src/ia-book-actions.js +252 -127
- package/test/components/collapsible-action-group.test.js +2 -2
- package/test/core/services/get-lending-actions.test.js +4 -4
- package/test/ia-book-actions.test.js +5 -9
- package/src/assets/styles/timer-countdown.js +0 -58
- package/src/components/toast-message.js +0 -60
- package/src/core/services/one-hour-auto-renew.js +0 -151
package/demo/index.html
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
16
16
|
}
|
|
17
17
|
#demo {
|
|
18
|
-
height:
|
|
18
|
+
height: 100px;
|
|
19
19
|
}
|
|
20
20
|
ia-book-actions {
|
|
21
21
|
--white: #fff;
|
|
@@ -87,6 +87,7 @@
|
|
|
87
87
|
|
|
88
88
|
<script type="module">
|
|
89
89
|
/* eslint-disable */
|
|
90
|
+
|
|
90
91
|
import '../src/ia-book-actions.js';
|
|
91
92
|
import {
|
|
92
93
|
defaultLendingStatus,
|
|
@@ -96,7 +97,7 @@
|
|
|
96
97
|
import { LocalCache } from '@internetarchive/local-cache';
|
|
97
98
|
|
|
98
99
|
const localCache = new LocalCache({
|
|
99
|
-
namespace: '
|
|
100
|
+
namespace: 'loanRenew',
|
|
100
101
|
defaultTTL: 1 * 60, // 1 minute
|
|
101
102
|
});
|
|
102
103
|
|
|
@@ -104,10 +105,6 @@
|
|
|
104
105
|
const identifier = 'naturalhistoryof00unse_4111';
|
|
105
106
|
let bwbPurchaseUrl = 'https://www.betterworldbooks.com/product/detail/cambridge-ancient-hist-v04-0521044863';
|
|
106
107
|
|
|
107
|
-
let iaBookActions = document.querySelector('ia-book-actions');
|
|
108
|
-
|
|
109
|
-
// for debugging
|
|
110
|
-
window.iaBookActions = iaBookActions;
|
|
111
108
|
|
|
112
109
|
const modalConfig = new ModalConfig();
|
|
113
110
|
modalConfig.headerColor = '#d9534f';
|
|
@@ -117,6 +114,8 @@
|
|
|
117
114
|
}
|
|
118
115
|
|
|
119
116
|
// set defaultLendingStatus for unavailable (without borrowables) book
|
|
117
|
+
let iaBookActions = document.querySelector('ia-book-actions');
|
|
118
|
+
|
|
120
119
|
iaBookActions.userid = userid;
|
|
121
120
|
iaBookActions.identifier = identifier;
|
|
122
121
|
iaBookActions.bookTitle = 'Contemporary Black biography. Volume 39 : profiles from the interContemporary Black biography. Volume 39';
|
|
@@ -127,14 +126,15 @@
|
|
|
127
126
|
iaBookActions.tokenDelay = 2000; // 2 seconds
|
|
128
127
|
iaBookActions.returnUrl = 'https://openlibrary.org';
|
|
129
128
|
iaBookActions.localCache = localCache;
|
|
130
|
-
iaBookActions.
|
|
131
|
-
totalTime:
|
|
132
|
-
autoCheckAt:
|
|
133
|
-
|
|
129
|
+
iaBookActions.loanRenewConfig = {
|
|
130
|
+
totalTime: 70, // 60 second = 1 min
|
|
131
|
+
autoCheckAt: 65, // totalTime - 10th minute
|
|
132
|
+
pageChangedInLast: 5, // within last 15 second/minute
|
|
133
|
+
env: 'dev', // dev/prod
|
|
134
134
|
};
|
|
135
135
|
|
|
136
136
|
let lendingStatus1 = iaBookActions.lendingStatus;
|
|
137
|
-
let secondsLeftOnLoan =
|
|
137
|
+
let secondsLeftOnLoan = iaBookActions.loanRenewConfig.totalTime;
|
|
138
138
|
|
|
139
139
|
document.querySelectorAll('.titleBar input[type=checkbox]').forEach((item) => {
|
|
140
140
|
item.addEventListener('click', (e) => {
|
|
@@ -146,21 +146,6 @@
|
|
|
146
146
|
});
|
|
147
147
|
});
|
|
148
148
|
|
|
149
|
-
document.querySelectorAll('.autoRenew input[type=checkbox]').forEach((item) => {
|
|
150
|
-
item.addEventListener('click', (e) => {
|
|
151
|
-
if (e.target.checked) {
|
|
152
|
-
iaBookActions.autoRenew = true;
|
|
153
|
-
iaBookActions.resetTimerCountdown = true;
|
|
154
|
-
lendingStatus1.secondsLeftOnLoan = secondsLeftOnLoan;
|
|
155
|
-
} else {
|
|
156
|
-
iaBookActions.autoRenew = false;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
let lending = {...defaultLendingStatus, ...lendingStatus1};
|
|
160
|
-
iaBookActions.lendingStatus = lending;
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
149
|
document.querySelectorAll('.errorEnable input[type=checkbox]').forEach((item) => {
|
|
165
150
|
if (window.location.href.indexOf('?error=true') !== -1) {
|
|
166
151
|
item.checked = true;
|
|
@@ -226,10 +211,10 @@
|
|
|
226
211
|
await localCache.set({
|
|
227
212
|
key: `${identifier}-loanTime`,
|
|
228
213
|
value: new Date(), // current time
|
|
229
|
-
ttl:
|
|
230
|
-
})
|
|
214
|
+
ttl: Number(iaBookActions.loanRenewConfig.totalTime),
|
|
215
|
+
});
|
|
231
216
|
|
|
232
|
-
await localCache.delete(`${identifier}-
|
|
217
|
+
await localCache.delete(`${identifier}-pageChangedTime`);
|
|
233
218
|
} catch (error) {}
|
|
234
219
|
|
|
235
220
|
} else if(e.target.value === 'browsingExpired') {
|
|
@@ -242,8 +227,11 @@
|
|
|
242
227
|
lendingStatus1.user_has_browsed = false;
|
|
243
228
|
}
|
|
244
229
|
|
|
245
|
-
|
|
246
|
-
|
|
230
|
+
// wait for a while
|
|
231
|
+
setTimeout(() => {
|
|
232
|
+
let lending = {...defaultLendingStatus, ...lendingStatus1};
|
|
233
|
+
iaBookActions.lendingStatus = lending;
|
|
234
|
+
}, 10);
|
|
247
235
|
});
|
|
248
236
|
});
|
|
249
237
|
|
|
@@ -292,6 +280,17 @@
|
|
|
292
280
|
iaBookActions.bwbPurchaseUrl = bwbPurchaseUrl;
|
|
293
281
|
})
|
|
294
282
|
});
|
|
283
|
+
|
|
284
|
+
document.querySelector('.pageChangedEvent').addEventListener('click', () => {
|
|
285
|
+
// dispatch event to say book page has flipped
|
|
286
|
+
document.querySelector('ia-book-actions').dispatchEvent(
|
|
287
|
+
new CustomEvent('BookReader:userAction', {
|
|
288
|
+
detail: {},
|
|
289
|
+
bubbles: true,
|
|
290
|
+
composed: true,
|
|
291
|
+
})
|
|
292
|
+
);
|
|
293
|
+
})
|
|
295
294
|
</script>
|
|
296
295
|
|
|
297
296
|
<div>
|
|
@@ -302,6 +301,9 @@
|
|
|
302
301
|
<td class="titleBar">
|
|
303
302
|
<label><input type="checkbox" name="title" value="title" />Title Bar</label>
|
|
304
303
|
</td>
|
|
304
|
+
<td>
|
|
305
|
+
<button class="pageChangedEvent">Page Change Event</button>
|
|
306
|
+
</td>
|
|
305
307
|
</tr>
|
|
306
308
|
</table>
|
|
307
309
|
</fieldset>
|
|
@@ -311,7 +313,6 @@
|
|
|
311
313
|
<table class="initial">
|
|
312
314
|
<tr colspan='5'>
|
|
313
315
|
<td class="errorEnable"><label><input type="checkbox" name="errorEnable" value="errorEnable" />Do you want to see error response?</label></td>
|
|
314
|
-
<td class="autoRenew"><label><input type="checkbox" name="autoRenew" value="autoRenew" />Do you want to auto-renew 1 hour</label></td>
|
|
315
316
|
</tr>
|
|
316
317
|
<tr>
|
|
317
318
|
<td class="userState">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@internetarchive/ia-book-actions",
|
|
3
|
-
"version": "0.0.29-
|
|
3
|
+
"version": "0.0.29-alpha31",
|
|
4
4
|
"description": "Bookreader actions for borrowable book",
|
|
5
5
|
"author": "Internet Archive",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"start": "web-dev-server",
|
|
14
|
-
"lint": "eslint --ext .js",
|
|
15
|
-
"format": "eslint --ext .js
|
|
14
|
+
"lint": "eslint --ext .js,.html . --ignore-path .gitignore && prettier \"**/*.js\" --check --ignore-path .gitignore",
|
|
15
|
+
"format": "eslint --ext .js,.html . --fix --ignore-path .gitignore && prettier \"**/*.js\" --write --ignore-path .gitignore",
|
|
16
16
|
"test": "yarn run lint && yarn test:fast",
|
|
17
17
|
"test:fast": "web-test-runner --coverage --playwright --browsers chromium firefox webkit",
|
|
18
18
|
"test:watch": "web-test-runner --watch --playwright --browsers chromium firefox webkit"
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"@internetarchive/local-cache": "^0.2.0",
|
|
23
23
|
"@internetarchive/modal-manager": "^0.2.1",
|
|
24
24
|
"@internetarchive/shared-resize-observer": "^0.2.0",
|
|
25
|
-
"
|
|
25
|
+
"@internetarchive/toast-manager": "0.0.1-alpha9",
|
|
26
|
+
"lit": "^2.5.0"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@open-wc/eslint-config": "^4.2.0",
|
|
@@ -43,6 +44,12 @@
|
|
|
43
44
|
"sinon": "^13.0.2"
|
|
44
45
|
},
|
|
45
46
|
"eslintConfig": {
|
|
47
|
+
"rules": {
|
|
48
|
+
"no-console": "off",
|
|
49
|
+
"no-unused-expressions": "off",
|
|
50
|
+
"class-methods-use-this": "off",
|
|
51
|
+
"lit-a11y/click-events-have-key-events": "off"
|
|
52
|
+
},
|
|
46
53
|
"extends": [
|
|
47
54
|
"@open-wc/eslint-config",
|
|
48
55
|
"eslint-config-prettier"
|
|
@@ -53,8 +60,7 @@
|
|
|
53
60
|
"arrowParens": "avoid"
|
|
54
61
|
},
|
|
55
62
|
"husky": {
|
|
56
|
-
"hooks": {
|
|
57
|
-
}
|
|
63
|
+
"hooks": {}
|
|
58
64
|
},
|
|
59
65
|
"lint-staged": {
|
|
60
66
|
"*.js": [
|
|
@@ -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,
|
|
@@ -118,7 +118,7 @@ export const canBrowseAndBorrow = {
|
|
|
118
118
|
loanStartDate: '2021-07-30 09:57:40',
|
|
119
119
|
loansUrl: '/details/@neeraj-archive?tab=loans#loans-on-loan',
|
|
120
120
|
maxLoans: 10,
|
|
121
|
-
secondsLeftOnLoan:
|
|
121
|
+
secondsLeftOnLoan: 12,
|
|
122
122
|
shouldProtectImages: true,
|
|
123
123
|
totalWaitlistCount: 0,
|
|
124
124
|
userHasBorrowed: false,
|
|
@@ -12,6 +12,7 @@ export default css`
|
|
|
12
12
|
}
|
|
13
13
|
.actiongroup {
|
|
14
14
|
display: flex;
|
|
15
|
+
margin-right: 10px;
|
|
15
16
|
}
|
|
16
17
|
.action-buttons {
|
|
17
18
|
display: inline-flex;
|
|
@@ -33,12 +34,12 @@ export default css`
|
|
|
33
34
|
}
|
|
34
35
|
.primary {
|
|
35
36
|
background-color: ${whiteColor};
|
|
37
|
+
margin-right: 4px;
|
|
36
38
|
}
|
|
37
39
|
.primary,
|
|
38
40
|
.secondary {
|
|
39
41
|
position: relative;
|
|
40
42
|
border-radius: 5px;
|
|
41
|
-
margin: 0 3px;
|
|
42
43
|
}
|
|
43
44
|
.primary .initial {
|
|
44
45
|
border-radius: 4px 0 0 4px;
|
|
@@ -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,8 +32,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
28
32
|
dropdownArrow: { type: String },
|
|
29
33
|
disabled: { type: Boolean },
|
|
30
34
|
returnUrl: { type: String },
|
|
31
|
-
|
|
32
|
-
autoRenewConfig: { type: Object },
|
|
35
|
+
renewNow: { type: Boolean },
|
|
33
36
|
};
|
|
34
37
|
}
|
|
35
38
|
|
|
@@ -49,8 +52,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
49
52
|
this.loaderIcon = 'https://archive.org/upload/images/tree/loading.gif';
|
|
50
53
|
this.disabled = false;
|
|
51
54
|
this.returnUrl = '';
|
|
52
|
-
this.
|
|
53
|
-
this.autoRenewConfig = {};
|
|
55
|
+
this.renewNow = false;
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
updated(changed) {
|
|
@@ -61,17 +63,28 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
61
63
|
this.resetActions();
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
if (this.
|
|
65
|
-
this.
|
|
66
|
-
new CustomEvent('autoBrowseBook', {
|
|
67
|
-
detail: {
|
|
68
|
-
event: { 'autoRenewed1Hour': 'browseBook' },
|
|
69
|
-
},
|
|
70
|
-
})
|
|
71
|
-
);
|
|
66
|
+
if (changed.has('renewNow') && this.renewNow === true) {
|
|
67
|
+
this.dispatchLoanRenewEvent();
|
|
72
68
|
}
|
|
73
69
|
}
|
|
74
70
|
|
|
71
|
+
// dispatch this event to loan renew handler
|
|
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.
|
|
79
|
+
this.dispatchEvent(
|
|
80
|
+
new CustomEvent('loanRenew', {
|
|
81
|
+
detail: {
|
|
82
|
+
event: { category, action },
|
|
83
|
+
},
|
|
84
|
+
})
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
75
88
|
/**
|
|
76
89
|
* merge primaryActions and secondaryActions into dropdown
|
|
77
90
|
*/
|
|
@@ -43,21 +43,12 @@ export class InfoIcon extends LitElement {
|
|
|
43
43
|
vertical-align: middle;
|
|
44
44
|
--iconFillColor: white;
|
|
45
45
|
}
|
|
46
|
-
.more-info-icon {
|
|
47
|
-
margin-left: 10px;
|
|
48
|
-
}
|
|
49
46
|
.more-info-icon img {
|
|
50
47
|
width: 24px;
|
|
51
48
|
height: 24px;
|
|
52
49
|
vertical-align: middle;
|
|
53
50
|
background: white;
|
|
54
51
|
}
|
|
55
|
-
.more-info-icon.mobile {
|
|
56
|
-
position: absolute;
|
|
57
|
-
top: 4px;
|
|
58
|
-
right: 55px;
|
|
59
|
-
margin-top: 15px;
|
|
60
|
-
}
|
|
61
52
|
.hidden {
|
|
62
53
|
display: none;
|
|
63
54
|
}
|
|
@@ -3,46 +3,44 @@ import { html, css, LitElement } from 'lit';
|
|
|
3
3
|
export default class TimerCountdown extends LitElement {
|
|
4
4
|
static get properties() {
|
|
5
5
|
return {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
resetTimerCountdown: { type: Boolean },
|
|
6
|
+
timeLeftOnLoan: { type: Number },
|
|
7
|
+
loanRenewConfig: { type: Object },
|
|
9
8
|
};
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
constructor() {
|
|
13
12
|
super();
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
13
|
+
this.timeLeftOnLoan = 0;
|
|
14
|
+
this.loanRenewConfig = 0;
|
|
15
|
+
|
|
16
|
+
// private props
|
|
16
17
|
this.timerInterval = undefined;
|
|
17
|
-
this.resetTimerCountdown = false;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
disconnectedCallback() {
|
|
21
|
-
clearInterval(this.timerInterval)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
firstUpdated() {
|
|
25
|
-
this.timerCountdown();
|
|
21
|
+
clearInterval(this.timerInterval);
|
|
26
22
|
}
|
|
27
23
|
|
|
28
24
|
updated(changed) {
|
|
29
|
-
if (changed.has('
|
|
25
|
+
if (changed.has('timeLeftOnLoan') && this.timeLeftOnLoan > 0) {
|
|
30
26
|
clearInterval(this.timerInterval);
|
|
31
|
-
this.timerCountdown()
|
|
27
|
+
this.timerCountdown();
|
|
32
28
|
}
|
|
33
29
|
}
|
|
34
|
-
|
|
30
|
+
|
|
35
31
|
timerCountdown() {
|
|
36
32
|
this.timerInterval = setInterval(() => {
|
|
37
|
-
this.
|
|
33
|
+
this.timeLeftOnLoan -= 1;
|
|
38
34
|
|
|
39
|
-
// execute
|
|
40
|
-
if
|
|
35
|
+
// execute from last 10th minute to 0th minute
|
|
36
|
+
// - 10th - to check if user has viewed
|
|
37
|
+
// - till 0th - to show warning msg with remaining time to auto returned
|
|
38
|
+
if (Math.round(this.timeLeftOnLoan) <= this.loanRenewConfig.autoCheckAt) {
|
|
41
39
|
this.dispatchEvent(
|
|
42
|
-
new CustomEvent('
|
|
40
|
+
new CustomEvent('IABookActions:loanRenew', {
|
|
43
41
|
detail: {
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
hasPageChanged: false,
|
|
43
|
+
timeLeft: Math.round(this.timeLeftOnLoan),
|
|
46
44
|
},
|
|
47
45
|
bubbles: true,
|
|
48
46
|
composed: true,
|
|
@@ -50,76 +48,63 @@ export default class TimerCountdown extends LitElement {
|
|
|
50
48
|
);
|
|
51
49
|
}
|
|
52
50
|
|
|
53
|
-
if
|
|
54
|
-
|
|
51
|
+
// clear interval if timer is < this.loanRenewConfig.autoCheckAt
|
|
52
|
+
if (this.timeLeftOnLoan < this.loanRenewConfig.autoCheckAt) {
|
|
53
|
+
clearInterval(this.timerInterval);
|
|
54
|
+
}
|
|
55
55
|
}, 1000);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
59
58
|
render() {
|
|
60
|
-
return html
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
return html`
|
|
60
|
+
<svg
|
|
61
|
+
width="16"
|
|
62
|
+
height="16"
|
|
63
|
+
viewBox="0 0 100 100"
|
|
64
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
65
|
+
>
|
|
66
|
+
<circle class="circle" cx="50" cy="50" r="50" />
|
|
67
|
+
</svg>
|
|
68
|
+
<span>${Math.round(this.timeLeftOnLoan)}</span>
|
|
69
|
+
`;
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
static get styles() {
|
|
73
|
+
const white = css`var(--white, #fff)`;
|
|
74
|
+
const timerSecondsLeft = css`var(--timerSeconds, 6000s)`;
|
|
75
|
+
const timerStrokeLeft = css`var(--timerStroke, 315)`;
|
|
76
|
+
|
|
69
77
|
return css`
|
|
70
78
|
:host {
|
|
71
79
|
right: 5px;
|
|
72
|
-
font-size: 14px;
|
|
73
80
|
position: absolute;
|
|
74
81
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
width: 40px;
|
|
81
|
-
text-align: center;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
#countdown-number {
|
|
85
|
-
color: white;
|
|
86
|
-
display: inline-block;
|
|
87
|
-
line-height: 40px;
|
|
88
|
-
margin-right: 12px;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
svg {
|
|
92
|
-
position: absolute;
|
|
93
|
-
top: 0;
|
|
94
|
-
right: 0;
|
|
95
|
-
width: 40px;
|
|
96
|
-
height: 40px;
|
|
97
|
-
transform: rotateY(-180deg) rotateZ(-90deg);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
svg circle {
|
|
101
|
-
stroke-dasharray: 113px;
|
|
102
|
-
stroke-dashoffset: 0px;
|
|
103
|
-
stroke-linecap: round;
|
|
104
|
-
stroke-width: 3px;
|
|
105
|
-
stroke: white;
|
|
106
|
-
fill: none;
|
|
107
|
-
animation: countdown 60s linear infinite forwards;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
@keyframes countdown {
|
|
111
|
-
from {
|
|
112
|
-
stroke-dashoffset: 0px;
|
|
82
|
+
|
|
83
|
+
@keyframes circletimer {
|
|
84
|
+
0% {
|
|
85
|
+
stroke-dashoffset: ${timerStrokeLeft};
|
|
86
|
+
stroke-dasharray: 315;
|
|
113
87
|
}
|
|
114
|
-
|
|
115
|
-
stroke-dashoffset:
|
|
88
|
+
100% {
|
|
89
|
+
stroke-dashoffset: 0;
|
|
90
|
+
stroke-dasharray: 315;
|
|
116
91
|
}
|
|
117
92
|
}
|
|
118
|
-
|
|
119
|
-
|
|
93
|
+
|
|
94
|
+
svg {
|
|
95
|
+
background-color: ${white};
|
|
96
|
+
border-radius: 50px;
|
|
97
|
+
border: 2px solid ${white};
|
|
98
|
+
transform: rotateZ(-90deg);
|
|
120
99
|
}
|
|
121
|
-
|
|
122
|
-
|
|
100
|
+
|
|
101
|
+
svg .circle {
|
|
102
|
+
stroke: #000;
|
|
103
|
+
stroke-width: 100px;
|
|
104
|
+
fill: ${white};
|
|
105
|
+
stroke-dashoffset: 315;
|
|
106
|
+
stroke-dasharray: 0;
|
|
107
|
+
animation: ${timerSecondsLeft} circletimer linear;
|
|
123
108
|
}
|
|
124
109
|
`;
|
|
125
110
|
}
|
|
@@ -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',
|
|
@@ -36,7 +36,7 @@ export default class ActionsConfig {
|
|
|
36
36
|
firstBrowseConfig() {
|
|
37
37
|
return {
|
|
38
38
|
id: 'browseBook',
|
|
39
|
-
text: 'Borrow for 1 hour'
|
|
39
|
+
text: 'Borrow', // changed texts from 'Borrow for 1 hour' to 'Borrow'
|
|
40
40
|
className: 'primary',
|
|
41
41
|
analyticsEvent: {
|
|
42
42
|
category: this.analyticsCategories.preview,
|
|
@@ -48,7 +48,7 @@ export default class ActionsConfig {
|
|
|
48
48
|
browseAgainConfig() {
|
|
49
49
|
return {
|
|
50
50
|
id: 'browseBookAgain',
|
|
51
|
-
text: 'Borrow again'
|
|
51
|
+
text: 'Borrow', // changed texts fro 'Borrow again' to 'Borrow'
|
|
52
52
|
className: 'primary',
|
|
53
53
|
analyticsEvent: {
|
|
54
54
|
category: this.analyticsCategories.browse,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
2
|
|
|
3
|
-
import { LocalCache } from '@internetarchive/local-cache';
|
|
4
3
|
import { URLHelper } from '../../config/url-helper.js';
|
|
5
4
|
import ActionsHandlerService from './actions-handler-service.js';
|
|
6
5
|
import * as Cookies from '../doc-cookies.js';
|
|
@@ -16,14 +15,7 @@ import * as Cookies from '../doc-cookies.js';
|
|
|
16
15
|
export default class ActionsHandler extends LitElement {
|
|
17
16
|
constructor() {
|
|
18
17
|
super();
|
|
19
|
-
this.identifier = '';
|
|
20
18
|
this.ajaxTimeout = 6000;
|
|
21
|
-
this.returnUrl = '';
|
|
22
|
-
this.autoRenewConfig = {};
|
|
23
|
-
|
|
24
|
-
this.localCache = new LocalCache({
|
|
25
|
-
namespace: '1HourLoanStorage',
|
|
26
|
-
});
|
|
27
19
|
|
|
28
20
|
this.bindEvents();
|
|
29
21
|
}
|
|
@@ -36,7 +28,7 @@ export default class ActionsHandler extends LitElement {
|
|
|
36
28
|
);
|
|
37
29
|
}
|
|
38
30
|
|
|
39
|
-
|
|
31
|
+
bindEvents() {
|
|
40
32
|
this.addEventListener('browseBook', ({ detail }) => {
|
|
41
33
|
this.handleBrowseIt();
|
|
42
34
|
this.setConsecutiveLoanCounts();
|
|
@@ -51,9 +43,8 @@ export default class ActionsHandler extends LitElement {
|
|
|
51
43
|
this.sendEvent(category, action);
|
|
52
44
|
});
|
|
53
45
|
|
|
54
|
-
this.addEventListener('
|
|
55
|
-
|
|
56
|
-
this.handleAutoBrowseIt();
|
|
46
|
+
this.addEventListener('loanRenew', ({ detail }) => {
|
|
47
|
+
this.handleLoanRenew();
|
|
57
48
|
const { category, action } = detail.event;
|
|
58
49
|
this.sendEvent(category, action);
|
|
59
50
|
});
|
|
@@ -112,7 +103,7 @@ export default class ActionsHandler extends LitElement {
|
|
|
112
103
|
handleBrowseIt() {
|
|
113
104
|
const action = 'browse_book';
|
|
114
105
|
this.dispatchToggleActionGroup();
|
|
115
|
-
this.setBrowseTimeSession()
|
|
106
|
+
this.setBrowseTimeSession();
|
|
116
107
|
|
|
117
108
|
ActionsHandlerService({
|
|
118
109
|
action,
|
|
@@ -126,21 +117,27 @@ export default class ActionsHandler extends LitElement {
|
|
|
126
117
|
});
|
|
127
118
|
}
|
|
128
119
|
|
|
129
|
-
|
|
130
|
-
const action = '
|
|
131
|
-
this.setBrowseTimeSession()
|
|
120
|
+
handleLoanRenew() {
|
|
121
|
+
const action = 'renew_loan';
|
|
132
122
|
|
|
133
123
|
ActionsHandlerService({
|
|
134
124
|
action,
|
|
135
125
|
identifier: this.identifier,
|
|
136
|
-
success:
|
|
126
|
+
success: data => {
|
|
127
|
+
// success analytics by isa?
|
|
128
|
+
this.setBrowseTimeSession();
|
|
129
|
+
this.dispatchEvent(
|
|
130
|
+
new CustomEvent('loanAutoRenewed', {
|
|
131
|
+
detail: { action, data },
|
|
132
|
+
})
|
|
133
|
+
);
|
|
134
|
+
},
|
|
137
135
|
error: data => {
|
|
138
136
|
this.dispatchActionError(action, data);
|
|
139
137
|
},
|
|
140
138
|
});
|
|
141
139
|
}
|
|
142
140
|
|
|
143
|
-
|
|
144
141
|
handleReturnIt() {
|
|
145
142
|
const action = 'return_loan';
|
|
146
143
|
this.dispatchToggleActionGroup();
|
|
@@ -291,6 +288,28 @@ export default class ActionsHandler extends LitElement {
|
|
|
291
288
|
}
|
|
292
289
|
}
|
|
293
290
|
|
|
291
|
+
/**
|
|
292
|
+
* set browse time in indexedDB
|
|
293
|
+
*/
|
|
294
|
+
async setBrowseTimeSession() {
|
|
295
|
+
try {
|
|
296
|
+
const { totalTime } = this.loanRenewConfig;
|
|
297
|
+
const expireDate = new Date(new Date().getTime() + totalTime * 1000);
|
|
298
|
+
|
|
299
|
+
// set a value
|
|
300
|
+
await this.localCache.set({
|
|
301
|
+
key: `${this.identifier}-loanTime`,
|
|
302
|
+
value: expireDate,
|
|
303
|
+
ttl: Number(totalTime),
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
// delete pageChangedTime when book is auto renew at nth minute
|
|
307
|
+
await this.localCache.delete(`${this.identifier}-pageChangedTime`);
|
|
308
|
+
} catch (error) {
|
|
309
|
+
console.log(error);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
294
313
|
deleteLoanCookies() {
|
|
295
314
|
const date = new Date();
|
|
296
315
|
date.setTime(date.getTime() - 24 * 60 * 60 * 1000); // one day ago
|
|
@@ -310,17 +329,4 @@ export default class ActionsHandler extends LitElement {
|
|
|
310
329
|
'.archive.org'
|
|
311
330
|
);
|
|
312
331
|
}
|
|
313
|
-
|
|
314
|
-
async setBrowseTimeSession() {
|
|
315
|
-
try {
|
|
316
|
-
// set a value
|
|
317
|
-
await this.localCache.set({
|
|
318
|
-
key: `${this.identifier}-loanTime`,
|
|
319
|
-
value: new Date(), // current time
|
|
320
|
-
ttl: parseInt(this.autoRenewConfig.totalTime),
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
await this.localCache.delete(`${this.identifier}-pageFlipTime`);
|
|
324
|
-
} catch (error) {}
|
|
325
|
-
}
|
|
326
332
|
}
|