@internetarchive/ia-book-actions 0.1.10 → 0.1.11-a1
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 -1
- package/demo/with-bookreader.html +146 -0
- package/package.json +1 -1
- package/src/components/confirmation-modal.js +0 -0
- package/src/components/timer-countdown.js +46 -29
- package/src/core/config/ia-lending-intervals.js +8 -2
- package/src/core/services/actions-handler/actions-handler.js +1 -1
- package/src/core/services/loan-renew-helper.js +11 -4
- package/src/ia-book-actions.js +84 -34
package/demo/index.html
CHANGED
|
@@ -88,6 +88,7 @@
|
|
|
88
88
|
|
|
89
89
|
<body>
|
|
90
90
|
<ia-book-actions></ia-book-actions>
|
|
91
|
+
<modal-manager></modal-manager>
|
|
91
92
|
|
|
92
93
|
<script type="module">
|
|
93
94
|
/* eslint-disable */
|
|
@@ -97,6 +98,7 @@
|
|
|
97
98
|
defaultLendingStatus,
|
|
98
99
|
canBrowseAndBorrow,
|
|
99
100
|
} from '../src/assets/data/lending-get-status-service.js';
|
|
101
|
+
import '@internetarchive/modal-manager';
|
|
100
102
|
import { ModalConfig } from '@internetarchive/modal-manager';
|
|
101
103
|
import { LocalCache } from '@internetarchive/local-cache';
|
|
102
104
|
|
|
@@ -290,7 +292,7 @@
|
|
|
290
292
|
|
|
291
293
|
document.querySelector('.pageChangedEvent').addEventListener('click', () => {
|
|
292
294
|
// dispatch event to say book page has flipped
|
|
293
|
-
|
|
295
|
+
window.dispatchEvent(
|
|
294
296
|
new CustomEvent('BookReader:userAction', {
|
|
295
297
|
detail: {},
|
|
296
298
|
bubbles: true,
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en-GB">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
|
7
|
+
<style>
|
|
8
|
+
html {
|
|
9
|
+
font-size: 10px;
|
|
10
|
+
/* This is to match petabox's base font size */
|
|
11
|
+
}
|
|
12
|
+
body {
|
|
13
|
+
margin: 0;
|
|
14
|
+
text-align: center;
|
|
15
|
+
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
16
|
+
}
|
|
17
|
+
#demo {
|
|
18
|
+
height: 50px;
|
|
19
|
+
}
|
|
20
|
+
ia-book-actions {
|
|
21
|
+
--white: #fff;
|
|
22
|
+
--black: #000;
|
|
23
|
+
--primaryBGColor: var(--black);
|
|
24
|
+
--secondaryBGColor: #222;
|
|
25
|
+
--tertiaryBGColor: #333;
|
|
26
|
+
--primaryTextColor: var(--white);
|
|
27
|
+
--primaryCTAFill: #194880;
|
|
28
|
+
--primaryCTABorder: #c5d1df;
|
|
29
|
+
--secondaryCTAFill: #333;
|
|
30
|
+
--secondaryCTABorder: #999;
|
|
31
|
+
--secondaryCTAFillRGB: 51, 51, 51;
|
|
32
|
+
--primaryErrorCTAFill: #e51c26;
|
|
33
|
+
--primaryErrorCTABorder: #f8c6c8;
|
|
34
|
+
--primaryCTAFillRGB: 25, 72, 128;
|
|
35
|
+
--primaryErrorCTAFillRGB: 229, 28, 38;
|
|
36
|
+
--primaryDisableCTAFill: #767676;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
fieldset {
|
|
40
|
+
width: fit-content;
|
|
41
|
+
margin-top: 50px;
|
|
42
|
+
}
|
|
43
|
+
fieldset legend {
|
|
44
|
+
text-align: left;
|
|
45
|
+
font-size: 12px;
|
|
46
|
+
}
|
|
47
|
+
td {
|
|
48
|
+
color: white;
|
|
49
|
+
font-size: 14px;
|
|
50
|
+
border-radius: 5%;
|
|
51
|
+
display: table-cell;
|
|
52
|
+
text-align: initial;
|
|
53
|
+
margin: 5px 0;
|
|
54
|
+
width: max-content;
|
|
55
|
+
display: block;
|
|
56
|
+
}
|
|
57
|
+
label {
|
|
58
|
+
padding: 10px;
|
|
59
|
+
display: block;
|
|
60
|
+
cursor: pointer;
|
|
61
|
+
margin: 2px;
|
|
62
|
+
background: #4e545a;
|
|
63
|
+
border-radius: 10px;
|
|
64
|
+
}
|
|
65
|
+
input[type="radio"], input[type="checkbox"] {
|
|
66
|
+
margin-top: 0;
|
|
67
|
+
vertical-align: middle;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.initial td {
|
|
71
|
+
float: left;
|
|
72
|
+
margin: 2px;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
body.modal-manager-open {
|
|
76
|
+
overflow: hidden;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
modal-manager[mode='closed'] {
|
|
80
|
+
display: none;
|
|
81
|
+
}
|
|
82
|
+
</style>
|
|
83
|
+
</head>
|
|
84
|
+
|
|
85
|
+
<body>
|
|
86
|
+
<ia-bookreader class="focus-on-child-only" signedin="" fullscreen="">
|
|
87
|
+
<div slot="header">
|
|
88
|
+
<ia-book-actions></ia-book-actions>
|
|
89
|
+
</div>
|
|
90
|
+
<div slot="main">
|
|
91
|
+
<div id="BookReader"></div>
|
|
92
|
+
</div>
|
|
93
|
+
</ia-bookreader>
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
<script type="module">
|
|
97
|
+
/* eslint-disable */
|
|
98
|
+
import '@internetarchive/bookreader';
|
|
99
|
+
import '@internetarchive/bookreader/BookReader/jquery-1.10.1.js';
|
|
100
|
+
import '@internetarchive/bookreader/BookReader/BookReader.js';
|
|
101
|
+
import '../src/ia-book-actions.js';
|
|
102
|
+
import {
|
|
103
|
+
defaultLendingStatus,
|
|
104
|
+
canBrowseAndBorrow,
|
|
105
|
+
} from '../src/assets/data/lending-get-status-service.js';
|
|
106
|
+
import { ModalConfig } from '@internetarchive/modal-manager';
|
|
107
|
+
|
|
108
|
+
const userid = '@neeraj-archive';
|
|
109
|
+
const identifier = 'naturalhistoryof00unse_4111';
|
|
110
|
+
let bwbPurchaseUrl = 'https://www.betterworldbooks.com/product/detail/cambridge-ancient-hist-v04-0521044863';
|
|
111
|
+
|
|
112
|
+
let iaBookActions = document.querySelector('ia-book-actions');
|
|
113
|
+
|
|
114
|
+
// for debugging
|
|
115
|
+
window.iaBookActions = iaBookActions;
|
|
116
|
+
|
|
117
|
+
const modalConfig = new ModalConfig();
|
|
118
|
+
modalConfig.headerColor = '#d9534f';
|
|
119
|
+
|
|
120
|
+
let lendingBarPostInit = function lendingBarPostInit() {
|
|
121
|
+
setTimeout(function() {
|
|
122
|
+
console.log('executed', 'br.init()');
|
|
123
|
+
}, 100);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// set defaultLendingStatus for unavailable (without borrowables) book
|
|
127
|
+
iaBookActions.userid = userid;
|
|
128
|
+
iaBookActions.identifier = identifier;
|
|
129
|
+
iaBookActions.bookTitle = 'Contemporary Black biography. Volume 39 : profiles from the interContemporary Black biography. Volume 39';
|
|
130
|
+
iaBookActions.lendingStatus = canBrowseAndBorrow;
|
|
131
|
+
iaBookActions.bwbPurchaseUrl = '';
|
|
132
|
+
iaBookActions.modalConfig = modalConfig;
|
|
133
|
+
iaBookActions.lendingBarPostInit = lendingBarPostInit;
|
|
134
|
+
iaBookActions.tokenDelay = 2000; // 2 seconds
|
|
135
|
+
iaBookActions.returnUrl = 'https://openlibrary.org';
|
|
136
|
+
|
|
137
|
+
let lendingStatus1 = iaBookActions.lendingStatus;
|
|
138
|
+
|
|
139
|
+
const manifest = await fetch('https://ia801302.us.archive.org/BookReader/BookReaderJSIA.php?id=goody&itemPath=/29/items/goody&server=ia801302.us.archive.org&format=jsonp&subPrefix=goody&requestUri=/details/goody/mode/1up%3Fview%3Dtheater%26ui%3Dembed%26wrapper%3Dfalse');
|
|
140
|
+
|
|
141
|
+
console.log('manifest ****', manifest).then(res => res.json());
|
|
142
|
+
</script>
|
|
143
|
+
|
|
144
|
+
</div>
|
|
145
|
+
</body>
|
|
146
|
+
</html>
|
package/package.json
CHANGED
|
File without changes
|
|
@@ -44,12 +44,15 @@ export default class TimerCountdown extends LitElement {
|
|
|
44
44
|
this.timerExecutionSeconds = 30;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
connectedCallback() {
|
|
48
|
+
super.connectedCallback();
|
|
49
|
+
console.log('connectedCallback - timerCountdown');
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
disconnectedCallback() {
|
|
53
|
+
console.log('disconnectedCallback - timerCountdown IN', window.IALendingIntervals);
|
|
54
|
+
window?.IALendingIntervals?.clearTimerCountdown();
|
|
55
|
+
console.log('disconnectedCallback - timerCountdown cleared', window.IALendingIntervals);
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
updated(changed) {
|
|
@@ -58,10 +61,39 @@ export default class TimerCountdown extends LitElement {
|
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
|
|
64
|
+
async timerInterval() {
|
|
65
|
+
let secondsLeft = this.secondsLeftOnLoan;
|
|
66
|
+
|
|
67
|
+
secondsLeft -= this.timerExecutionSeconds;
|
|
68
|
+
secondsLeft = Math.round(secondsLeft); // round number
|
|
69
|
+
|
|
70
|
+
// re-sync timer if gone off because of background window
|
|
71
|
+
|
|
72
|
+
// do we need a window.focus anywhere?
|
|
73
|
+
await this.reSyncTimerIfGoneOff(secondsLeft);
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* execute from last 10th minute to 0th minute // arbitrary?
|
|
77
|
+
* - 10th - to check if user has viewed
|
|
78
|
+
* - till 0th - to show warning msg with remaining time to auto expired
|
|
79
|
+
* @see IABookActions::bindLoanRenewEvents
|
|
80
|
+
*/
|
|
81
|
+
if (secondsLeft <= this.loanRenewAtLast) {
|
|
82
|
+
this.dispatchLoanRenewEvent(secondsLeft);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// clear interval in secondsLeft if less
|
|
86
|
+
if (secondsLeft <= this.timerExecutionSeconds) {
|
|
87
|
+
this.disconnectedCallback();
|
|
88
|
+
window?.Sentry?.captureMessage(sentryLogs.clearOneHourTimer);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
61
92
|
timerCountdown() {
|
|
93
|
+
console.log('TIMER COUNTDOWN', window.IALendingIntervals, this.timerExecutionSeconds );
|
|
62
94
|
this.disconnectedCallback();
|
|
63
95
|
|
|
64
|
-
|
|
96
|
+
|
|
65
97
|
|
|
66
98
|
// store current time
|
|
67
99
|
this.timeWhenTimerStart = new Date();
|
|
@@ -71,29 +103,10 @@ export default class TimerCountdown extends LitElement {
|
|
|
71
103
|
* set interval in window object
|
|
72
104
|
* @see ia-lending-intervals.js
|
|
73
105
|
*/
|
|
74
|
-
window.IALendingIntervals.timerCountdown = setInterval(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// re-sync timer if gone off because of background window
|
|
79
|
-
await this.reSyncTimerIfGoneOff(secondsLeft);
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* execute from last 10th minute to 0th minute
|
|
83
|
-
* - 10th - to check if user has viewed
|
|
84
|
-
* - till 0th - to show warning msg with remaining time to auto expired
|
|
85
|
-
* @see IABookActions::bindLoanRenewEvents
|
|
86
|
-
*/
|
|
87
|
-
if (secondsLeft <= this.loanRenewAtLast) {
|
|
88
|
-
this.dispatchLoanRenewEvent(secondsLeft);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// clear interval in secondsLeft if less
|
|
92
|
-
if (secondsLeft <= this.timerExecutionSeconds) {
|
|
93
|
-
this.disconnectedCallback();
|
|
94
|
-
window?.Sentry?.captureMessage(sentryLogs.clearOneHourTimer);
|
|
95
|
-
}
|
|
96
|
-
}, this.timerExecutionSeconds * 1000);
|
|
106
|
+
window.IALendingIntervals.timerCountdown = setInterval(
|
|
107
|
+
() => this.timerInterval(),
|
|
108
|
+
this.timerExecutionSeconds * 1000
|
|
109
|
+
);
|
|
97
110
|
}
|
|
98
111
|
|
|
99
112
|
/**
|
|
@@ -151,6 +164,9 @@ export default class TimerCountdown extends LitElement {
|
|
|
151
164
|
);
|
|
152
165
|
this.secondsLeftOnLoan = secondsShouldLeft; // the seconds should left in timer again
|
|
153
166
|
}
|
|
167
|
+
|
|
168
|
+
// when do we resync timer?
|
|
169
|
+
// return true or false?
|
|
154
170
|
}
|
|
155
171
|
|
|
156
172
|
/**
|
|
@@ -172,6 +188,7 @@ export default class TimerCountdown extends LitElement {
|
|
|
172
188
|
}
|
|
173
189
|
|
|
174
190
|
render() {
|
|
191
|
+
console.log("TIMER COUNTDOWN RENDER");
|
|
175
192
|
return html`
|
|
176
193
|
<svg
|
|
177
194
|
width="14"
|
|
@@ -179,7 +196,7 @@ export default class TimerCountdown extends LitElement {
|
|
|
179
196
|
viewBox="0 0 100 100"
|
|
180
197
|
xmlns="http://www.w3.org/2000/svg"
|
|
181
198
|
>
|
|
182
|
-
<circle class="circle" cx="50" cy="50" r="50" />
|
|
199
|
+
<circle id="timer-countdown" class="circle" cx="50" cy="50" r="50" />
|
|
183
200
|
</svg>
|
|
184
201
|
<span class="sr-only">${this.remainingTime} left</span>
|
|
185
202
|
`;
|
|
@@ -41,7 +41,13 @@ window.IALendingIntervals = {
|
|
|
41
41
|
* clear all intervals being used acros lending system
|
|
42
42
|
*/
|
|
43
43
|
clearAll: () => {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
try {
|
|
45
|
+
|
|
46
|
+
window.clearInterval(window?.IALendingIntervals.tokenPoller);
|
|
47
|
+
window.clearInterval(window?.IALendingIntervals.timerCountdown);
|
|
48
|
+
} catch(e) {
|
|
49
|
+
console.error(e);
|
|
50
|
+
}
|
|
51
|
+
|
|
46
52
|
},
|
|
47
53
|
};
|
|
@@ -164,7 +164,7 @@ export default class ActionsHandler extends LitElement {
|
|
|
164
164
|
/**
|
|
165
165
|
* excute function when loan is returning
|
|
166
166
|
*
|
|
167
|
-
* @param {
|
|
167
|
+
* @param {'returnNow' | ''} type
|
|
168
168
|
*/
|
|
169
169
|
handleReturnIt(type = '') {
|
|
170
170
|
const action = 'return_loan';
|
|
@@ -26,11 +26,14 @@ export class LoanRenewHelper {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
handleLoanRenew() {
|
|
29
|
+
console.log('handleLoanRenew', this.hasPageChanged);
|
|
29
30
|
try {
|
|
30
31
|
if (this.hasPageChanged) {
|
|
31
|
-
|
|
32
|
+
this.pageChanged(); // user clicked on page
|
|
33
|
+
return;
|
|
32
34
|
}
|
|
33
|
-
|
|
35
|
+
this.autoChecker(); // auto checker at last 10th minute
|
|
36
|
+
return;
|
|
34
37
|
} catch (error) {
|
|
35
38
|
console.log(error);
|
|
36
39
|
}
|
|
@@ -54,13 +57,16 @@ export class LoanRenewHelper {
|
|
|
54
57
|
|
|
55
58
|
const lastTimeFrame = this.changeTime(loanTime, loanRenewAtLast, 'sub');
|
|
56
59
|
|
|
60
|
+
console.log("PAGE CHANGED ~~~~~~~~~ lastTimeFram, loanTime", { lastTimeFrame, loanTime });
|
|
61
|
+
|
|
57
62
|
// if user viewed new page in last 10 minutes, renew immediately
|
|
58
63
|
if (lastTimeFrame !== null && currentTime >= lastTimeFrame) {
|
|
59
64
|
this.result.texts = this.loanRenewMessage;
|
|
60
65
|
this.result.renewNow = true;
|
|
61
66
|
}
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
console.log("PAGE CHANGED ~~~~~~~~~ ", this.result);
|
|
68
|
+
debugger;
|
|
69
|
+
await this.setPageChangedTime();
|
|
64
70
|
return this.result;
|
|
65
71
|
}
|
|
66
72
|
|
|
@@ -71,6 +77,7 @@ export class LoanRenewHelper {
|
|
|
71
77
|
* @returns {this.result}
|
|
72
78
|
*/
|
|
73
79
|
async autoChecker() {
|
|
80
|
+
console.log('autoChecker ***!!!!!');
|
|
74
81
|
const { pageChangedInLast } = this.loanRenewTimeConfig;
|
|
75
82
|
const pageChangedTime = await this.localCache.get(
|
|
76
83
|
`${this.identifier}-pageChangedTime`
|
package/src/ia-book-actions.js
CHANGED
|
@@ -45,6 +45,7 @@ export default class IABookActions extends LitElement {
|
|
|
45
45
|
userid: { type: String },
|
|
46
46
|
identifier: { type: String },
|
|
47
47
|
bookTitle: { type: String },
|
|
48
|
+
/** */
|
|
48
49
|
lendingStatus: { type: Object },
|
|
49
50
|
returnUrl: { type: String },
|
|
50
51
|
width: { type: Number },
|
|
@@ -77,7 +78,7 @@ export default class IABookActions extends LitElement {
|
|
|
77
78
|
this.barType = 'action'; // 'title'|'action'
|
|
78
79
|
this.sharedObserver = undefined;
|
|
79
80
|
this.disableActionGroup = false;
|
|
80
|
-
this.modal = undefined;
|
|
81
|
+
// this.modal = undefined;
|
|
81
82
|
this.tokenDelay = 120; // in seconds
|
|
82
83
|
|
|
83
84
|
// private props
|
|
@@ -128,6 +129,11 @@ export default class IABookActions extends LitElement {
|
|
|
128
129
|
this._shadowRoot = this.attachShadow({ mode: 'open' });
|
|
129
130
|
}
|
|
130
131
|
|
|
132
|
+
connectedCallback() {
|
|
133
|
+
super.connectedCallback();
|
|
134
|
+
console.log('connectedCallback - ia-book-actions');
|
|
135
|
+
}
|
|
136
|
+
|
|
131
137
|
disconnectedCallback() {
|
|
132
138
|
// clear all intervals for lending system
|
|
133
139
|
window?.IALendingIntervals?.clearAll();
|
|
@@ -137,21 +143,28 @@ export default class IABookActions extends LitElement {
|
|
|
137
143
|
}
|
|
138
144
|
|
|
139
145
|
firstUpdated() {
|
|
146
|
+
// window.focus => reset timer & also1w3w
|
|
147
|
+
window.addEventListener('focus', () => {
|
|
148
|
+
console.log('window focus ~~~~~~');
|
|
149
|
+
});
|
|
150
|
+
|
|
140
151
|
// bind auto loan renew events
|
|
141
152
|
this.bindLoanRenewEvents();
|
|
142
153
|
|
|
143
154
|
// localCache used for auto-loan-renew
|
|
144
155
|
this.localCache = new LocalCache({
|
|
145
|
-
namespace:
|
|
156
|
+
namespace: `loanRenew-${this.identifier || 'unknown_book'}`,
|
|
146
157
|
});
|
|
147
158
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
159
|
+
this.sharedObserver = new SharedResizeObserver();
|
|
160
|
+
this.setupResizeObserver();
|
|
161
|
+
|
|
162
|
+
const modal = this.modal;
|
|
163
|
+
console.log('modal', modal);
|
|
152
164
|
}
|
|
153
165
|
|
|
154
166
|
updated(changed) {
|
|
167
|
+
console.log('UPDATED', this.lendingStatus);
|
|
155
168
|
if (changed.has('lendingStatus') || changed.has('bwbPurchaseUrl')) {
|
|
156
169
|
this.setupLendingToolbarActions();
|
|
157
170
|
this.update();
|
|
@@ -163,6 +176,19 @@ export default class IABookActions extends LitElement {
|
|
|
163
176
|
}
|
|
164
177
|
}
|
|
165
178
|
|
|
179
|
+
render() {
|
|
180
|
+
console.log("RENDER IABookActions", this.barType);
|
|
181
|
+
if (this.barType === 'title') {
|
|
182
|
+
return html`<section class="lending-wrapper">
|
|
183
|
+
${this.bookTitleBar}
|
|
184
|
+
</section>`;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return html`<section class="lending-wrapper">
|
|
188
|
+
${this.bookActionBar}
|
|
189
|
+
</section>`;
|
|
190
|
+
}
|
|
191
|
+
|
|
166
192
|
/** SharedObserver resize handler */
|
|
167
193
|
handleResize(entry) {
|
|
168
194
|
// if you are observing multiple targets,
|
|
@@ -178,7 +204,8 @@ export default class IABookActions extends LitElement {
|
|
|
178
204
|
|
|
179
205
|
/** Removes observer */
|
|
180
206
|
disconnectResizeObserver() {
|
|
181
|
-
this.sharedObserver
|
|
207
|
+
if (!this.sharedObserver) return;
|
|
208
|
+
this.sharedObserver.removeObserver({
|
|
182
209
|
handler: this,
|
|
183
210
|
target: this.shadowRoot.host,
|
|
184
211
|
});
|
|
@@ -189,7 +216,9 @@ export default class IABookActions extends LitElement {
|
|
|
189
216
|
setupResizeObserver() {
|
|
190
217
|
if (!this.shadowRoot) return;
|
|
191
218
|
this.sharedObserver?.addObserver({
|
|
192
|
-
handler:
|
|
219
|
+
handler: {
|
|
220
|
+
handleResize: this.handleResize.bind(this),
|
|
221
|
+
},
|
|
193
222
|
target: this.shadowRoot.host,
|
|
194
223
|
});
|
|
195
224
|
}
|
|
@@ -259,6 +288,7 @@ export default class IABookActions extends LitElement {
|
|
|
259
288
|
setTimeout(() => {
|
|
260
289
|
this.resetTimerCountState();
|
|
261
290
|
}, 100);
|
|
291
|
+
return;
|
|
262
292
|
}
|
|
263
293
|
|
|
264
294
|
/**
|
|
@@ -281,6 +311,7 @@ export default class IABookActions extends LitElement {
|
|
|
281
311
|
* dispatched this event from bookreader page changed
|
|
282
312
|
*/
|
|
283
313
|
window.addEventListener('BookReader:userAction', () => {
|
|
314
|
+
console.log('BookReader:userAction **** , ', this.borrowType);
|
|
284
315
|
if (this.borrowType === 'browsed') {
|
|
285
316
|
this.autoLoanRenewChecker(true);
|
|
286
317
|
}
|
|
@@ -305,6 +336,9 @@ export default class IABookActions extends LitElement {
|
|
|
305
336
|
let secondsLeft = event?.detail?.secondsLeft;
|
|
306
337
|
if (secondsLeft < 50) {
|
|
307
338
|
this.suppressAutoRenew = true;
|
|
339
|
+
console.log("BROWSER TIMER IN secondsLeft < 50!!",secondsLeft, secondsLeft < 50);
|
|
340
|
+
console.log("BROWSER TIMER IN secondsLeft < 50!! this.loanRenewResult",this.loanRenewResult);
|
|
341
|
+
|
|
308
342
|
this.browseHasExpired();
|
|
309
343
|
}
|
|
310
344
|
|
|
@@ -329,12 +363,17 @@ export default class IABookActions extends LitElement {
|
|
|
329
363
|
* @param {Boolean} hasPageChanged
|
|
330
364
|
*/
|
|
331
365
|
async autoLoanRenewChecker(hasPageChanged = false) {
|
|
332
|
-
this.loanRenewHelper
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
this.
|
|
336
|
-
|
|
337
|
-
|
|
366
|
+
console.log('autoLoanRenewChecker &&&&', this.loanRenewHelper);
|
|
367
|
+
// something is up here
|
|
368
|
+
if (!this.loanRenewHelper) {
|
|
369
|
+
this.loanRenewHelper = new LoanRenewHelper(
|
|
370
|
+
hasPageChanged,
|
|
371
|
+
this.identifier,
|
|
372
|
+
this.localCache,
|
|
373
|
+
this.loanRenewTimeConfig
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
|
|
338
377
|
|
|
339
378
|
await this.loanRenewHelper.handleLoanRenew();
|
|
340
379
|
this.loanRenewResult = this.loanRenewHelper.result;
|
|
@@ -344,23 +383,27 @@ export default class IABookActions extends LitElement {
|
|
|
344
383
|
* create / select the modal-manager component on DOM
|
|
345
384
|
* @memberof IABookActions
|
|
346
385
|
*/
|
|
347
|
-
async useModalManager() {
|
|
348
|
-
|
|
349
|
-
|
|
386
|
+
// async useModalManager() {
|
|
387
|
+
// if (!this.modal) {
|
|
388
|
+
// this.modal = document.querySelector('modal-manager');
|
|
350
389
|
|
|
351
|
-
|
|
352
|
-
|
|
390
|
+
// if (!this.modal) this.modal = document.createElement('modal-manager');
|
|
391
|
+
// }
|
|
353
392
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
393
|
+
// this.modal.id = 'action-bar-modal';
|
|
394
|
+
// await document.body.appendChild(this.modal);
|
|
395
|
+
// }
|
|
357
396
|
|
|
358
397
|
/**
|
|
359
398
|
* Show the waring modal to ask user if they are still reading
|
|
360
399
|
*/
|
|
361
400
|
async showWarningModal() {
|
|
362
|
-
console.log('****** showWarningModal ******');
|
|
363
|
-
await this.useModalManager();
|
|
401
|
+
console.log('****** showWarningModal ****** clearing intervals');
|
|
402
|
+
// await this.useModalManager();
|
|
403
|
+
console.log('showWarningModal window?.IALendingInterval BEFORE', window?.IALendingIntervals);
|
|
404
|
+
|
|
405
|
+
window?.IALendingIntervals?.clearAll();
|
|
406
|
+
console.log('showWarningModal window?.IALendingIntervals AFTER', window?.IALendingIntervals);
|
|
364
407
|
|
|
365
408
|
// if secondsLeft < 60, consider it 1 minute
|
|
366
409
|
let { secondsLeft } = this.loanRenewResult;
|
|
@@ -430,7 +473,7 @@ export default class IABookActions extends LitElement {
|
|
|
430
473
|
* Show modal when book is auto returned
|
|
431
474
|
*/
|
|
432
475
|
async showExpiredModal() {
|
|
433
|
-
await this.useModalManager();
|
|
476
|
+
// await this.useModalManager();
|
|
434
477
|
|
|
435
478
|
const config = new ModalConfig();
|
|
436
479
|
config.headline = '';
|
|
@@ -542,6 +585,7 @@ export default class IABookActions extends LitElement {
|
|
|
542
585
|
* Execute when loan is expired
|
|
543
586
|
*/
|
|
544
587
|
async browseHasExpired() {
|
|
588
|
+
console.log('browseHasExpired', window?.IALendingIntervals);
|
|
545
589
|
window?.IALendingIntervals?.clearAll();
|
|
546
590
|
|
|
547
591
|
const currStatus = { ...this.lendingStatus, browsingExpired: true };
|
|
@@ -577,6 +621,7 @@ export default class IABookActions extends LitElement {
|
|
|
577
621
|
console.log('user browsed', this.lendingStatus);
|
|
578
622
|
|
|
579
623
|
this.browseTimer = setTimeout(() => {
|
|
624
|
+
console.log("BROWSER TIMER IN TIMEOUT!!");
|
|
580
625
|
this.browseHasExpired();
|
|
581
626
|
}, secondsLeftOnLoan * 1000);
|
|
582
627
|
}
|
|
@@ -608,16 +653,19 @@ export default class IABookActions extends LitElement {
|
|
|
608
653
|
}, 100);
|
|
609
654
|
}
|
|
610
655
|
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
656
|
+
get modal () {
|
|
657
|
+
let modal = document.querySelector('modal-manager');
|
|
658
|
+
if (!modal) {
|
|
659
|
+
const newModal = document.createElement('modal-manager');
|
|
660
|
+
document.body.appendChild(newModal);
|
|
661
|
+
modal = newModal;
|
|
616
662
|
}
|
|
617
663
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
664
|
+
if (modal && !modal.id !== 'action-bar-modal') {
|
|
665
|
+
modal.setAttribute('id', 'action-bar-modal');
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
return modal;
|
|
621
669
|
}
|
|
622
670
|
|
|
623
671
|
get bookTitleBar() {
|
|
@@ -628,6 +676,7 @@ export default class IABookActions extends LitElement {
|
|
|
628
676
|
}
|
|
629
677
|
|
|
630
678
|
get timerCountdownTemplate() {
|
|
679
|
+
console.log('timerCountdownTemplatetimerCountdownTemplate');
|
|
631
680
|
return this.borrowType === 'browsed'
|
|
632
681
|
? html`<timer-countdown
|
|
633
682
|
.secondsLeftOnLoan=${Number(this.lendingStatus.secondsLeftOnLoan)}
|
|
@@ -638,6 +687,7 @@ export default class IABookActions extends LitElement {
|
|
|
638
687
|
}
|
|
639
688
|
|
|
640
689
|
get bookActionBar() {
|
|
690
|
+
console.log('~~~~~');
|
|
641
691
|
return html`
|
|
642
692
|
<collapsible-action-group
|
|
643
693
|
.userid=${this.userid}
|
|
@@ -789,7 +839,7 @@ export default class IABookActions extends LitElement {
|
|
|
789
839
|
|
|
790
840
|
/* show error message if something went wrong */
|
|
791
841
|
async showErrorModal(errorMsg, action) {
|
|
792
|
-
await this.useModalManager();
|
|
842
|
+
// await this.useModalManager();
|
|
793
843
|
|
|
794
844
|
const modalConfig = new ModalConfig({
|
|
795
845
|
title: 'Lending error',
|