@internetarchive/ia-book-actions 0.0.29-alpha4 → 0.0.29-alpha6
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 +3 -3
- package/package.json +9 -3
- package/src/assets/data/lending-get-status-service.js +1 -1
- package/src/components/collapsible-action-group.js +4 -4
- package/src/components/timer-countdown.js +16 -29
- package/src/components/toast-message.js +6 -4
- package/src/core/services/actions-handler/actions-handler.js +18 -25
- package/src/core/services/one-hour-auto-renew.js +74 -55
- package/src/ia-book-actions.js +36 -33
- package/src/assets/styles/timer-countdown.js +0 -58
package/demo/index.html
CHANGED
|
@@ -128,8 +128,8 @@
|
|
|
128
128
|
iaBookActions.returnUrl = 'https://openlibrary.org';
|
|
129
129
|
iaBookActions.localCache = localCache;
|
|
130
130
|
iaBookActions.autoRenewConfig = {
|
|
131
|
-
totalTime:
|
|
132
|
-
autoCheckAt:
|
|
131
|
+
totalTime: 60, // 60 second = 1 min
|
|
132
|
+
autoCheckAt: 55, // totalTime - 10th minute
|
|
133
133
|
FlippedInLast: 15, // within last 15 second/minute
|
|
134
134
|
};
|
|
135
135
|
|
|
@@ -226,7 +226,7 @@
|
|
|
226
226
|
await localCache.set({
|
|
227
227
|
key: `${identifier}-loanTime`,
|
|
228
228
|
value: new Date(), // current time
|
|
229
|
-
ttl:
|
|
229
|
+
ttl: Number(iaBookActions.autoRenewConfig.totalTime),
|
|
230
230
|
})
|
|
231
231
|
|
|
232
232
|
await localCache.delete(`${identifier}-pageFlipTime`);
|
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-alpha6",
|
|
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"
|
|
@@ -43,6 +43,12 @@
|
|
|
43
43
|
"sinon": "^13.0.2"
|
|
44
44
|
},
|
|
45
45
|
"eslintConfig": {
|
|
46
|
+
"rules": {
|
|
47
|
+
"no-console": "off",
|
|
48
|
+
"no-unused-expressions": "off",
|
|
49
|
+
"class-methods-use-this": "off",
|
|
50
|
+
"lit-a11y/click-events-have-key-events": "off"
|
|
51
|
+
},
|
|
46
52
|
"extends": [
|
|
47
53
|
"@open-wc/eslint-config",
|
|
48
54
|
"eslint-config-prettier"
|
|
@@ -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,
|
|
@@ -28,8 +28,8 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
28
28
|
dropdownArrow: { type: String },
|
|
29
29
|
disabled: { type: Boolean },
|
|
30
30
|
returnUrl: { type: String },
|
|
31
|
+
localCache: { type: Function },
|
|
31
32
|
browseAgainNow: { type: Boolean },
|
|
32
|
-
autoRenewConfig: { type: Object },
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -49,8 +49,8 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
49
49
|
this.loaderIcon = 'https://archive.org/upload/images/tree/loading.gif';
|
|
50
50
|
this.disabled = false;
|
|
51
51
|
this.returnUrl = '';
|
|
52
|
+
this.localCache = undefined;
|
|
52
53
|
this.browseAgainNow = false;
|
|
53
|
-
this.autoRenewConfig = {};
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
updated(changed) {
|
|
@@ -61,11 +61,11 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
61
61
|
this.resetActions();
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
if (this.browseAgainNow === true) {
|
|
64
|
+
if (changed.has('browseAgainNow') && this.browseAgainNow === true) {
|
|
65
65
|
this.dispatchEvent(
|
|
66
66
|
new CustomEvent('autoBrowseBook', {
|
|
67
67
|
detail: {
|
|
68
|
-
event: {
|
|
68
|
+
event: { autoRenewed1Hour: 'browseBook' },
|
|
69
69
|
},
|
|
70
70
|
})
|
|
71
71
|
);
|
|
@@ -11,33 +11,31 @@ export default class TimerCountdown extends LitElement {
|
|
|
11
11
|
|
|
12
12
|
constructor() {
|
|
13
13
|
super();
|
|
14
|
-
this.time =
|
|
14
|
+
this.time = 0;
|
|
15
15
|
this.autoCheckAt = 0;
|
|
16
16
|
this.timerInterval = undefined;
|
|
17
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('time') && this.time > 0) {
|
|
26
|
+
console.log('changed', this.time);
|
|
27
|
+
|
|
30
28
|
clearInterval(this.timerInterval);
|
|
31
|
-
this.timerCountdown()
|
|
29
|
+
this.timerCountdown();
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
|
-
|
|
32
|
+
|
|
35
33
|
timerCountdown() {
|
|
36
34
|
this.timerInterval = setInterval(() => {
|
|
37
35
|
this.time -= 1;
|
|
38
36
|
|
|
39
37
|
// execute 50th minute check
|
|
40
|
-
if (this.time === this.autoCheckAt) {
|
|
38
|
+
if (Math.round(this.time) === this.autoCheckAt) {
|
|
41
39
|
this.dispatchEvent(
|
|
42
40
|
new CustomEvent('autoRenewAttempt', {
|
|
43
41
|
detail: {
|
|
@@ -51,18 +49,16 @@ export default class TimerCountdown extends LitElement {
|
|
|
51
49
|
}
|
|
52
50
|
|
|
53
51
|
if (this.time === 0) clearInterval(this.timerInterval);
|
|
54
|
-
|
|
55
52
|
}, 1000);
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
|
|
59
55
|
render() {
|
|
60
56
|
return html`<div id="countdown">
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
<div id="countdown-number">${Math.round(this.time)}</div>
|
|
58
|
+
<svg>
|
|
59
|
+
<circle r="18" cx="20" cy="20"></circle>
|
|
60
|
+
</svg>
|
|
61
|
+
</div>`;
|
|
66
62
|
}
|
|
67
63
|
|
|
68
64
|
static get styles() {
|
|
@@ -72,22 +68,13 @@ export default class TimerCountdown extends LitElement {
|
|
|
72
68
|
font-size: 14px;
|
|
73
69
|
position: absolute;
|
|
74
70
|
}
|
|
75
|
-
#countdown1 {
|
|
76
|
-
position: relative;
|
|
77
|
-
margin: auto;
|
|
78
|
-
margin-top: 100px;
|
|
79
|
-
height: 40px;
|
|
80
|
-
width: 40px;
|
|
81
|
-
text-align: center;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
71
|
#countdown-number {
|
|
85
72
|
color: white;
|
|
86
73
|
display: inline-block;
|
|
87
74
|
line-height: 40px;
|
|
88
75
|
margin-right: 12px;
|
|
89
76
|
}
|
|
90
|
-
|
|
77
|
+
|
|
91
78
|
svg {
|
|
92
79
|
position: absolute;
|
|
93
80
|
top: 0;
|
|
@@ -96,7 +83,7 @@ export default class TimerCountdown extends LitElement {
|
|
|
96
83
|
height: 40px;
|
|
97
84
|
transform: rotateY(-180deg) rotateZ(-90deg);
|
|
98
85
|
}
|
|
99
|
-
|
|
86
|
+
|
|
100
87
|
svg circle {
|
|
101
88
|
stroke-dasharray: 113px;
|
|
102
89
|
stroke-dashoffset: 0px;
|
|
@@ -106,7 +93,7 @@ export default class TimerCountdown extends LitElement {
|
|
|
106
93
|
fill: none;
|
|
107
94
|
animation: countdown 60s linear infinite forwards;
|
|
108
95
|
}
|
|
109
|
-
|
|
96
|
+
|
|
110
97
|
@keyframes countdown {
|
|
111
98
|
from {
|
|
112
99
|
stroke-dashoffset: 0px;
|
|
@@ -22,8 +22,11 @@ export class ToastMessage extends LitElement {
|
|
|
22
22
|
<span
|
|
23
23
|
class="toast-message fade-in ${this.textClass}"
|
|
24
24
|
title="Click/tap to close"
|
|
25
|
-
@click=${() => {
|
|
26
|
-
|
|
25
|
+
@click=${() => {
|
|
26
|
+
this.dismisOnClick ? (this.hideToast = true) : nothing;
|
|
27
|
+
}}
|
|
28
|
+
>${this.texts}</span
|
|
29
|
+
>
|
|
27
30
|
`
|
|
28
31
|
: nothing;
|
|
29
32
|
}
|
|
@@ -34,14 +37,13 @@ export class ToastMessage extends LitElement {
|
|
|
34
37
|
return css`
|
|
35
38
|
:host {
|
|
36
39
|
display: inline-block;
|
|
37
|
-
|
|
38
40
|
}
|
|
39
41
|
.toast-message {
|
|
40
42
|
z-index: 2;
|
|
41
43
|
position: absolute;
|
|
42
44
|
top: ${heightFromTop};
|
|
43
45
|
font-size: 1.4rem;
|
|
44
|
-
font-family:
|
|
46
|
+
font-family: 'Helvetica Neue';
|
|
45
47
|
color: #fff;
|
|
46
48
|
left: 50%;
|
|
47
49
|
background: #333;
|
|
@@ -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';
|
|
@@ -20,11 +19,6 @@ export default class ActionsHandler extends LitElement {
|
|
|
20
19
|
this.ajaxTimeout = 6000;
|
|
21
20
|
this.returnUrl = '';
|
|
22
21
|
this.autoRenewConfig = {};
|
|
23
|
-
|
|
24
|
-
this.localCache = new LocalCache({
|
|
25
|
-
namespace: '1HourLoanStorage',
|
|
26
|
-
});
|
|
27
|
-
|
|
28
22
|
this.bindEvents();
|
|
29
23
|
}
|
|
30
24
|
|
|
@@ -112,7 +106,7 @@ export default class ActionsHandler extends LitElement {
|
|
|
112
106
|
handleBrowseIt() {
|
|
113
107
|
const action = 'browse_book';
|
|
114
108
|
this.dispatchToggleActionGroup();
|
|
115
|
-
this.setBrowseTimeSession()
|
|
109
|
+
this.setBrowseTimeSession();
|
|
116
110
|
|
|
117
111
|
ActionsHandlerService({
|
|
118
112
|
action,
|
|
@@ -128,23 +122,20 @@ export default class ActionsHandler extends LitElement {
|
|
|
128
122
|
|
|
129
123
|
handleAutoBrowseIt() {
|
|
130
124
|
const action = 'renew_loan';
|
|
131
|
-
this.setBrowseTimeSession()
|
|
125
|
+
this.setBrowseTimeSession();
|
|
132
126
|
|
|
133
127
|
ActionsHandlerService({
|
|
134
128
|
action,
|
|
135
129
|
identifier: this.identifier,
|
|
136
130
|
success: () => {
|
|
137
|
-
console.log('success!');
|
|
131
|
+
// console.log('success!');
|
|
138
132
|
},
|
|
139
133
|
error: data => {
|
|
140
|
-
console.log(data);
|
|
141
|
-
console.log('error!');
|
|
142
134
|
this.dispatchActionError(action, data);
|
|
143
135
|
},
|
|
144
136
|
});
|
|
145
137
|
}
|
|
146
138
|
|
|
147
|
-
|
|
148
139
|
handleReturnIt() {
|
|
149
140
|
const action = 'return_loan';
|
|
150
141
|
this.dispatchToggleActionGroup();
|
|
@@ -295,6 +286,21 @@ export default class ActionsHandler extends LitElement {
|
|
|
295
286
|
}
|
|
296
287
|
}
|
|
297
288
|
|
|
289
|
+
async setBrowseTimeSession() {
|
|
290
|
+
try {
|
|
291
|
+
// set a value
|
|
292
|
+
await this.localCache.set({
|
|
293
|
+
key: `${this.identifier}-loanTime`,
|
|
294
|
+
value: new Date(), // current time
|
|
295
|
+
ttl: Number(this.autoRenewConfig.totalTime),
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
await this.localCache.delete(`${this.identifier}-pageFlipTime`);
|
|
299
|
+
} catch (error) {
|
|
300
|
+
console.log(error);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
298
304
|
deleteLoanCookies() {
|
|
299
305
|
const date = new Date();
|
|
300
306
|
date.setTime(date.getTime() - 24 * 60 * 60 * 1000); // one day ago
|
|
@@ -314,17 +320,4 @@ export default class ActionsHandler extends LitElement {
|
|
|
314
320
|
'.archive.org'
|
|
315
321
|
);
|
|
316
322
|
}
|
|
317
|
-
|
|
318
|
-
async setBrowseTimeSession() {
|
|
319
|
-
try {
|
|
320
|
-
// set a value
|
|
321
|
-
await this.localCache.set({
|
|
322
|
-
key: `${this.identifier}-loanTime`,
|
|
323
|
-
value: new Date(), // current time
|
|
324
|
-
ttl: parseInt(this.autoRenewConfig.totalTime),
|
|
325
|
-
})
|
|
326
|
-
|
|
327
|
-
await this.localCache.delete(`${this.identifier}-pageFlipTime`);
|
|
328
|
-
} catch (error) {}
|
|
329
|
-
}
|
|
330
323
|
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { nothing } from 'lit';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This class is used to determine if use is eligible for auto renew loan.
|
|
5
5
|
*
|
|
6
|
-
* ActionsHandlerService is a function being used to execute
|
|
7
6
|
*/
|
|
8
7
|
export class OneHourAutoRenew {
|
|
9
|
-
constructor(
|
|
10
|
-
|
|
8
|
+
constructor(
|
|
9
|
+
isPageClick,
|
|
10
|
+
identifier,
|
|
11
|
+
localCache,
|
|
12
|
+
autoRenewConfig,
|
|
13
|
+
userHasBrowsed
|
|
14
|
+
) {
|
|
15
|
+
this.isPageClick = isPageClick;
|
|
11
16
|
this.identifier = identifier;
|
|
12
17
|
this.localCache = localCache;
|
|
13
18
|
this.autoRenewConfig = autoRenewConfig;
|
|
@@ -15,14 +20,17 @@ export class OneHourAutoRenew {
|
|
|
15
20
|
|
|
16
21
|
// messages for auto return machenism
|
|
17
22
|
this.autoRenewMessage = 'This book has been renewed for another hour.';
|
|
18
|
-
this.autoReturnMessage =
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
this.autoReturnMessage =
|
|
24
|
+
'This book has been auto-returned due to inactivity.';
|
|
25
|
+
this.autoReturnWarning =
|
|
26
|
+
'This book will be auto-returned in 10 minutes unless you turn a page.';
|
|
27
|
+
|
|
21
28
|
// private props
|
|
22
29
|
this.resultRes = {
|
|
23
30
|
toastTexts: this.autoReturnMessage,
|
|
24
31
|
hideToast: true,
|
|
25
32
|
renewNow: false,
|
|
33
|
+
browseAgainNow: false,
|
|
26
34
|
};
|
|
27
35
|
|
|
28
36
|
return this.handleBookAutoRenew();
|
|
@@ -30,20 +38,19 @@ export class OneHourAutoRenew {
|
|
|
30
38
|
|
|
31
39
|
async handleBookAutoRenew() {
|
|
32
40
|
try {
|
|
33
|
-
// if page is not
|
|
41
|
+
// if page is not clicked in last 15 minutes,
|
|
34
42
|
// instantaly renew it if user viewed new page in last 10 minutes
|
|
35
|
-
if (this.
|
|
36
|
-
console.log('page flipped
|
|
37
|
-
this.setPageFlippedTime();
|
|
43
|
+
if (this.isPageClick) {
|
|
44
|
+
console.log('page flipped!!');
|
|
38
45
|
return this.userFlippedBookPage(); // user clicked on page
|
|
39
|
-
} else {
|
|
40
|
-
console.log('auto checker!')
|
|
41
|
-
return this.autoCheckerTimer(); // auto checker at 50th minute
|
|
42
46
|
}
|
|
43
|
-
|
|
47
|
+
console.log('auto checker!');
|
|
48
|
+
return this.autoCheckerTimer(); // auto checker at 50th minute
|
|
44
49
|
} catch (error) {
|
|
45
|
-
console.log(error)
|
|
50
|
+
console.log(error);
|
|
46
51
|
}
|
|
52
|
+
|
|
53
|
+
return nothing;
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
async setPageFlippedTime() {
|
|
@@ -51,8 +58,8 @@ export class OneHourAutoRenew {
|
|
|
51
58
|
await this.localCache.set({
|
|
52
59
|
key: `${this.identifier}-pageFlipTime`,
|
|
53
60
|
value: new Date(), // current time
|
|
54
|
-
ttl:
|
|
55
|
-
})
|
|
61
|
+
ttl: Number(this.autoRenewConfig.totalTime),
|
|
62
|
+
});
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
async userFlippedBookPage() {
|
|
@@ -60,59 +67,93 @@ export class OneHourAutoRenew {
|
|
|
60
67
|
totalTime, // 60
|
|
61
68
|
autoCheckAt, // 50
|
|
62
69
|
} = this.autoRenewConfig;
|
|
63
|
-
const
|
|
70
|
+
const currentTime = new Date();
|
|
64
71
|
const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
|
|
65
72
|
|
|
66
|
-
const lastTimeFrame =
|
|
73
|
+
const lastTimeFrame = this.changeTime(
|
|
67
74
|
loanTime,
|
|
68
75
|
totalTime - autoCheckAt,
|
|
69
76
|
'add'
|
|
70
77
|
); // 50 seconds
|
|
71
78
|
|
|
72
|
-
if (
|
|
79
|
+
if (currentTime >= lastTimeFrame) {
|
|
73
80
|
console.log('1 YES NOW BORROW IT AGAIN NOW!');
|
|
74
81
|
this.resultRes.toastTexts = this.autoRenewMessage;
|
|
75
|
-
this.resultRes.browseAgainNow = true;
|
|
76
82
|
this.resultRes.hideToast = false;
|
|
77
83
|
this.resultRes.renewNow = true;
|
|
84
|
+
this.resultRes.browseAgainNow = true;
|
|
85
|
+
|
|
86
|
+
this.setNewBrowseTime();
|
|
87
|
+
} else {
|
|
88
|
+
console.log("can't autorenew this time!");
|
|
78
89
|
}
|
|
79
90
|
|
|
91
|
+
this.setPageFlippedTime();
|
|
80
92
|
return this.resultRes;
|
|
81
93
|
}
|
|
82
94
|
|
|
83
95
|
async autoCheckerTimer() {
|
|
84
|
-
const
|
|
96
|
+
const currentTime = new Date();
|
|
85
97
|
const { FlippedInLast } = this.autoRenewConfig;
|
|
86
|
-
const lastPageFlipTime = await this.localCache.get(
|
|
98
|
+
const lastPageFlipTime = await this.localCache.get(
|
|
99
|
+
`${this.identifier}-pageFlipTime`
|
|
100
|
+
);
|
|
87
101
|
|
|
88
102
|
// last 15 min if used flipped a page.
|
|
89
|
-
const lastFlipTimeFrame =
|
|
90
|
-
|
|
103
|
+
const lastFlipTimeFrame = this.changeTime(
|
|
104
|
+
currentTime,
|
|
91
105
|
FlippedInLast,
|
|
92
106
|
'sub'
|
|
93
107
|
); // 15 seconds
|
|
94
108
|
|
|
95
|
-
if (
|
|
109
|
+
if (
|
|
110
|
+
lastPageFlipTime === undefined ||
|
|
111
|
+
lastPageFlipTime <= lastFlipTimeFrame
|
|
112
|
+
) {
|
|
113
|
+
// not viewed
|
|
96
114
|
console.log('2 not viewed, warning message!');
|
|
97
115
|
this.resultRes.toastTexts = this.autoReturnWarning;
|
|
98
116
|
this.resultRes.hideToast = false;
|
|
99
|
-
} else if (lastPageFlipTime >= lastFlipTimeFrame) {
|
|
117
|
+
} else if (lastPageFlipTime >= lastFlipTimeFrame) {
|
|
118
|
+
// viewed in last time frame
|
|
100
119
|
console.log('3 viewed, auto renew and message!');
|
|
101
120
|
this.resultRes.toastTexts = this.autoRenewMessage;
|
|
102
121
|
this.resultRes.browseAgainNow = true;
|
|
103
122
|
this.resultRes.hideToast = false;
|
|
104
123
|
this.resultRes.renewNow = true;
|
|
105
124
|
|
|
106
|
-
|
|
107
|
-
await this.localCache.delete(`${this.identifier}-pageFlipTime`);
|
|
125
|
+
this.setNewBrowseTime();
|
|
108
126
|
}
|
|
109
127
|
|
|
110
128
|
return this.resultRes;
|
|
111
129
|
}
|
|
112
130
|
|
|
113
|
-
async
|
|
114
|
-
|
|
115
|
-
|
|
131
|
+
async setNewBrowseTime() {
|
|
132
|
+
try {
|
|
133
|
+
// last 15 min if used flipped a page.
|
|
134
|
+
const expireDate = this.changeTime(
|
|
135
|
+
new Date(),
|
|
136
|
+
this.autoRenewConfig.totalTime,
|
|
137
|
+
'add'
|
|
138
|
+
); // 15 seconds
|
|
139
|
+
|
|
140
|
+
// set a value
|
|
141
|
+
await this.localCache.set({
|
|
142
|
+
key: `${this.identifier}-loanTime`,
|
|
143
|
+
value: expireDate, // expireDate time
|
|
144
|
+
ttl: Number(this.autoRenewConfig.totalTime),
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// delete pageFlipTime when book is auto renew at nth minute
|
|
148
|
+
await this.localCache.delete(`${this.identifier}-pageFlipTime`);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.log(error);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
changeTime(date, minutes, op) {
|
|
155
|
+
if (date === undefined) return nothing;
|
|
156
|
+
|
|
116
157
|
if (op === 'sub') {
|
|
117
158
|
return new Date(date.getTime() - minutes * 1000);
|
|
118
159
|
}
|
|
@@ -120,7 +161,6 @@ export class OneHourAutoRenew {
|
|
|
120
161
|
return new Date(date.getTime() + minutes * 1000);
|
|
121
162
|
}
|
|
122
163
|
|
|
123
|
-
|
|
124
164
|
sendEvent(eventCategory, eventAction) {
|
|
125
165
|
window?.archive_analytics?.send_event(
|
|
126
166
|
eventCategory,
|
|
@@ -128,25 +168,4 @@ export class OneHourAutoRenew {
|
|
|
128
168
|
`identifier=${this.identifier}`
|
|
129
169
|
);
|
|
130
170
|
}
|
|
131
|
-
|
|
132
|
-
async handleAutoRenew() {
|
|
133
|
-
const action = 'renew_loan';
|
|
134
|
-
ActionsHandlerService({
|
|
135
|
-
identifier: this.identifier,
|
|
136
|
-
action,
|
|
137
|
-
error: data => {
|
|
138
|
-
window?.Sentry?.captureMessage(
|
|
139
|
-
'handleAutoRenew error',
|
|
140
|
-
JSON.stringify(data)
|
|
141
|
-
);
|
|
142
|
-
// this.errorCallback({ detail: { action, data } });
|
|
143
|
-
// send LendingServiceError to GA
|
|
144
|
-
this.sendEvent('handleAutoRenew', action);
|
|
145
|
-
},
|
|
146
|
-
success: () => {
|
|
147
|
-
console.log('success!');
|
|
148
|
-
return 'success';
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
171
|
}
|
package/src/ia-book-actions.js
CHANGED
|
@@ -36,7 +36,6 @@ export default class IABookActions extends LitElement {
|
|
|
36
36
|
attribute: false,
|
|
37
37
|
},
|
|
38
38
|
barType: { type: String },
|
|
39
|
-
autoRenew: { type: Boolean },
|
|
40
39
|
sharedObserver: { attribute: false },
|
|
41
40
|
disableActionGroup: { type: Boolean },
|
|
42
41
|
modal: { Object },
|
|
@@ -61,16 +60,15 @@ export default class IABookActions extends LitElement {
|
|
|
61
60
|
this.bwbPurchaseUrl = '';
|
|
62
61
|
this.lendingBarPostInit = () => {};
|
|
63
62
|
this.barType = 'action'; // 'title'|'action'
|
|
64
|
-
this.autoRenew = false;
|
|
65
63
|
this.sharedObserver = undefined;
|
|
66
64
|
this.disableActionGroup = false;
|
|
67
65
|
this.modal = undefined;
|
|
68
66
|
this.tokenDelay = 120000; // 2 minutes
|
|
69
67
|
this.localCache = new LocalCache({
|
|
70
|
-
namespace: '1HourLoanStorage'
|
|
71
|
-
})
|
|
72
|
-
this.autoRenewConfig = {}
|
|
73
|
-
this.
|
|
68
|
+
namespace: '1HourLoanStorage',
|
|
69
|
+
});
|
|
70
|
+
this.autoRenewConfig = {};
|
|
71
|
+
this.autoRenewRes = undefined;
|
|
74
72
|
|
|
75
73
|
// private props
|
|
76
74
|
this.primaryActions = [];
|
|
@@ -102,15 +100,12 @@ export default class IABookActions extends LitElement {
|
|
|
102
100
|
}
|
|
103
101
|
|
|
104
102
|
updated(changed) {
|
|
105
|
-
console.log(changed)
|
|
103
|
+
// console.log(changed)
|
|
106
104
|
if (changed.has('lendingStatus') || changed.has('bwbPurchaseUrl')) {
|
|
107
105
|
this.setupLendingToolbarActions();
|
|
108
106
|
this.update();
|
|
109
107
|
}
|
|
110
108
|
|
|
111
|
-
if (changed.has('autoRenew')) {
|
|
112
|
-
this.resetTimerCountdown = true;
|
|
113
|
-
}
|
|
114
109
|
if (changed.has('sharedObserver')) {
|
|
115
110
|
this.disconnectResizeObserver();
|
|
116
111
|
this.setupResizeObserver();
|
|
@@ -118,23 +113,27 @@ export default class IABookActions extends LitElement {
|
|
|
118
113
|
}
|
|
119
114
|
|
|
120
115
|
bindAutoRenewEvent() {
|
|
121
|
-
// dispatched this event from timer-countdown
|
|
116
|
+
// dispatched this event from timer-countdown
|
|
122
117
|
this.addEventListener('autoRenewAttempt', async event => {
|
|
123
|
-
const
|
|
118
|
+
const isPageClick = event.detail.bookPageChange;
|
|
124
119
|
|
|
125
|
-
this.
|
|
126
|
-
|
|
120
|
+
this.autoRenewRes = await new OneHourAutoRenew(
|
|
121
|
+
isPageClick,
|
|
127
122
|
this.identifier,
|
|
128
123
|
this.localCache,
|
|
129
124
|
this.autoRenewConfig,
|
|
130
|
-
this.lendingStatus.user_has_browsed &&
|
|
125
|
+
this.lendingStatus.user_has_browsed &&
|
|
126
|
+
!this.lendingStatus.browsingExpired
|
|
131
127
|
);
|
|
128
|
+
console.log(this.autoRenewRes);
|
|
129
|
+
|
|
130
|
+
this.toastTexts = this.autoRenewRes.toastTexts;
|
|
131
|
+
this.hideToast = this.autoRenewRes.hideToast;
|
|
132
|
+
this.browseAgainNow = this.autoRenewRes.browseAgainNow;
|
|
132
133
|
|
|
133
|
-
this.toastTexts = this.autoRenewObj.toastTexts;
|
|
134
|
-
this.hideToast = this.autoRenewObj.hideToast;
|
|
135
|
-
this.browseAgainNow = this.autoRenewObj.renewNow;
|
|
136
134
|
if (this.browseAgainNow) {
|
|
137
135
|
await this.browseHasRenew();
|
|
136
|
+
// this.resetTimerCountdown = true;
|
|
138
137
|
}
|
|
139
138
|
});
|
|
140
139
|
}
|
|
@@ -142,6 +141,7 @@ export default class IABookActions extends LitElement {
|
|
|
142
141
|
async browseHasExpired() {
|
|
143
142
|
const currStatus = { ...this.lendingStatus, browsingExpired: true };
|
|
144
143
|
this.lendingStatus = currStatus;
|
|
144
|
+
this.browseAgainNow = false;
|
|
145
145
|
|
|
146
146
|
// remove respected key:value
|
|
147
147
|
await this.localCache.delete(`${this.identifier}-loanTime`);
|
|
@@ -152,13 +152,17 @@ export default class IABookActions extends LitElement {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
async browseHasRenew() {
|
|
155
|
-
const
|
|
155
|
+
const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
|
|
156
|
+
const secondsLeft = (loanTime - new Date()) / 1000; // different in seconds
|
|
157
|
+
|
|
158
|
+
const currStatus = {
|
|
156
159
|
...this.lendingStatus,
|
|
157
160
|
user_has_browsed: true,
|
|
158
161
|
browsingExpired: false,
|
|
159
|
-
secondsLeftOnLoan:
|
|
162
|
+
secondsLeftOnLoan: secondsLeft,
|
|
160
163
|
};
|
|
161
164
|
this.lendingStatus = currStatus;
|
|
165
|
+
// this.performUpdate()
|
|
162
166
|
|
|
163
167
|
this.startBrowseTimer();
|
|
164
168
|
}
|
|
@@ -289,6 +293,7 @@ export default class IABookActions extends LitElement {
|
|
|
289
293
|
}
|
|
290
294
|
|
|
291
295
|
get timerCountdownTemplate() {
|
|
296
|
+
// console.log(this.borrowType, this.remainingTime, this.autoRenewConfig.autoCheckAt, this.resetTimerCountdown);
|
|
292
297
|
return this.borrowType === 'browsed'
|
|
293
298
|
? html`<timer-countdown
|
|
294
299
|
time=${Number(this.remainingTime)}
|
|
@@ -302,7 +307,7 @@ export default class IABookActions extends LitElement {
|
|
|
302
307
|
return html`
|
|
303
308
|
<toast-message
|
|
304
309
|
.texts=${this.toastTexts}
|
|
305
|
-
?dismisOnClick=${true}
|
|
310
|
+
?dismisOnClick=${Boolean(true)}
|
|
306
311
|
?hideToast=${this.hideToast}
|
|
307
312
|
></toast-message>
|
|
308
313
|
`;
|
|
@@ -310,7 +315,7 @@ export default class IABookActions extends LitElement {
|
|
|
310
315
|
|
|
311
316
|
get bookActionBar() {
|
|
312
317
|
return html`
|
|
313
|
-
<button @click=${() => this.pageFlipEvent
|
|
318
|
+
<button @click=${() => this.pageFlipEvent}>Page Flip</button>
|
|
314
319
|
<collapsible-action-group
|
|
315
320
|
.userid=${this.userid}
|
|
316
321
|
.identifier=${this.identifier}
|
|
@@ -320,7 +325,7 @@ export default class IABookActions extends LitElement {
|
|
|
320
325
|
.width=${this.width}
|
|
321
326
|
.borrowType=${this.borrowType}
|
|
322
327
|
.returnUrl=${this.returnUrl}
|
|
323
|
-
.
|
|
328
|
+
.localCache=${this.localCache}
|
|
324
329
|
.autoRenewConfig=${this.autoRenewConfig}
|
|
325
330
|
?hasAdminAccess=${this.hasAdminAccess}
|
|
326
331
|
?disabled=${this.disableActionGroup}
|
|
@@ -335,15 +340,13 @@ export default class IABookActions extends LitElement {
|
|
|
335
340
|
}
|
|
336
341
|
|
|
337
342
|
// will move this function to bookreader...
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
);
|
|
346
|
-
} catch (error) { console.log(error) }
|
|
343
|
+
pageFlipEvent() {
|
|
344
|
+
// dispatch event to say book page has flipped
|
|
345
|
+
document.querySelector('ia-book-actions').dispatchEvent(
|
|
346
|
+
new CustomEvent('autoRenewAttempt', {
|
|
347
|
+
detail: { bookPageChange: true },
|
|
348
|
+
})
|
|
349
|
+
);
|
|
347
350
|
}
|
|
348
351
|
|
|
349
352
|
/**
|
|
@@ -512,7 +515,7 @@ export default class IABookActions extends LitElement {
|
|
|
512
515
|
}
|
|
513
516
|
|
|
514
517
|
toast-message {
|
|
515
|
-
--messageHeightFromTop:
|
|
518
|
+
--messageHeightFromTop: 14.5%;
|
|
516
519
|
}
|
|
517
520
|
`;
|
|
518
521
|
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { css } from 'lit';
|
|
2
|
-
|
|
3
|
-
export default timerCountDownStyle = css`
|
|
4
|
-
:host {
|
|
5
|
-
right: 5px;
|
|
6
|
-
font-size: 14px;
|
|
7
|
-
position: absolute;
|
|
8
|
-
}
|
|
9
|
-
#countdown1 {
|
|
10
|
-
position: relative;
|
|
11
|
-
margin: auto;
|
|
12
|
-
margin-top: 100px;
|
|
13
|
-
height: 40px;
|
|
14
|
-
width: 40px;
|
|
15
|
-
text-align: center;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
#countdown-number {
|
|
19
|
-
color: white;
|
|
20
|
-
display: inline-block;
|
|
21
|
-
line-height: 40px;
|
|
22
|
-
margin-right: 12px;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
svg {
|
|
26
|
-
position: absolute;
|
|
27
|
-
top: 0;
|
|
28
|
-
right: 0;
|
|
29
|
-
width: 40px;
|
|
30
|
-
height: 40px;
|
|
31
|
-
transform: rotateY(-180deg) rotateZ(-90deg);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
svg circle {
|
|
35
|
-
stroke-dasharray: 113px;
|
|
36
|
-
stroke-dashoffset: 0px;
|
|
37
|
-
stroke-linecap: round;
|
|
38
|
-
stroke-width: 3px;
|
|
39
|
-
stroke: white;
|
|
40
|
-
fill: none;
|
|
41
|
-
animation: countdown 60s linear infinite forwards;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
@keyframes countdown {
|
|
45
|
-
from {
|
|
46
|
-
stroke-dashoffset: 0px;
|
|
47
|
-
}
|
|
48
|
-
to {
|
|
49
|
-
stroke-dashoffset: 113px;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
.hidden {
|
|
53
|
-
display: none;
|
|
54
|
-
}
|
|
55
|
-
.visible {
|
|
56
|
-
display: inline-block;
|
|
57
|
-
}
|
|
58
|
-
`;
|