@internetarchive/ia-book-actions 0.0.29-alpha13 → 0.0.29-alpha15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/demo/index.html
CHANGED
|
@@ -105,10 +105,6 @@
|
|
|
105
105
|
const identifier = 'naturalhistoryof00unse_4111';
|
|
106
106
|
let bwbPurchaseUrl = 'https://www.betterworldbooks.com/product/detail/cambridge-ancient-hist-v04-0521044863';
|
|
107
107
|
|
|
108
|
-
let iaBookActions = document.querySelector('ia-book-actions');
|
|
109
|
-
|
|
110
|
-
// for debugging
|
|
111
|
-
window.iaBookActions = iaBookActions;
|
|
112
108
|
|
|
113
109
|
const modalConfig = new ModalConfig();
|
|
114
110
|
modalConfig.headerColor = '#d9534f';
|
|
@@ -118,6 +114,8 @@
|
|
|
118
114
|
}
|
|
119
115
|
|
|
120
116
|
// set defaultLendingStatus for unavailable (without borrowables) book
|
|
117
|
+
let iaBookActions = document.querySelector('ia-book-actions');
|
|
118
|
+
|
|
121
119
|
iaBookActions.userid = userid;
|
|
122
120
|
iaBookActions.identifier = identifier;
|
|
123
121
|
iaBookActions.bookTitle = 'Contemporary Black biography. Volume 39 : profiles from the interContemporary Black biography. Volume 39';
|
|
@@ -129,6 +127,7 @@
|
|
|
129
127
|
iaBookActions.returnUrl = 'https://openlibrary.org';
|
|
130
128
|
iaBookActions.localCache = localCache;
|
|
131
129
|
iaBookActions.loanRenewConfig = {
|
|
130
|
+
enable: false, // If loan renew is enabled
|
|
132
131
|
totalTime: 10, // 60 second = 1 min
|
|
133
132
|
autoCheckAt: 5, // totalTime - 10th minute
|
|
134
133
|
pageChangedInLast: 15, // within last 15 second/minute
|
|
@@ -278,6 +277,19 @@
|
|
|
278
277
|
iaBookActions.bwbPurchaseUrl = bwbPurchaseUrl;
|
|
279
278
|
})
|
|
280
279
|
});
|
|
280
|
+
|
|
281
|
+
document.querySelector('.pageChangedEvent').addEventListener('click', () => {
|
|
282
|
+
// dispatch event to say book page has flipped
|
|
283
|
+
document.querySelector('ia-book-actions').dispatchEvent(
|
|
284
|
+
new CustomEvent('BookReader:pageChanged', {
|
|
285
|
+
detail: { isPageChanged: true },
|
|
286
|
+
bubbles: true,
|
|
287
|
+
composed: true,
|
|
288
|
+
})
|
|
289
|
+
);
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
|
|
281
293
|
</script>
|
|
282
294
|
|
|
283
295
|
<div>
|
|
@@ -288,6 +300,9 @@
|
|
|
288
300
|
<td class="titleBar">
|
|
289
301
|
<label><input type="checkbox" name="title" value="title" />Title Bar</label>
|
|
290
302
|
</td>
|
|
303
|
+
<td>
|
|
304
|
+
<button class="pageChangedEvent">Page Change Event</button>
|
|
305
|
+
</td>
|
|
291
306
|
</tr>
|
|
292
307
|
</table>
|
|
293
308
|
</fieldset>
|
package/package.json
CHANGED
|
@@ -5,14 +5,12 @@ export class ToastMessage extends LitElement {
|
|
|
5
5
|
return {
|
|
6
6
|
texts: { type: String },
|
|
7
7
|
dismisOnClick: { type: Boolean },
|
|
8
|
-
clostAfter: { type: Number },
|
|
9
8
|
};
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
constructor() {
|
|
13
12
|
super();
|
|
14
13
|
this.texts = null;
|
|
15
|
-
this.clostAfter = 0;
|
|
16
14
|
}
|
|
17
15
|
|
|
18
16
|
render() {
|
|
@@ -22,7 +20,7 @@ export class ToastMessage extends LitElement {
|
|
|
22
20
|
class="toast-message fade-in"
|
|
23
21
|
title="Click/tap to close"
|
|
24
22
|
@click=${() => {
|
|
25
|
-
this.dismisOnClick ? this.texts = null : nothing;
|
|
23
|
+
this.dismisOnClick ? (this.texts = null) : nothing;
|
|
26
24
|
}}
|
|
27
25
|
>${this.texts}</span
|
|
28
26
|
>
|
|
@@ -5,12 +5,7 @@ import { nothing } from 'lit';
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
export class OneHourLoanRenew {
|
|
8
|
-
constructor(
|
|
9
|
-
isPageChanged,
|
|
10
|
-
identifier,
|
|
11
|
-
localCache,
|
|
12
|
-
loanRenewConfig
|
|
13
|
-
) {
|
|
8
|
+
constructor(isPageChanged, identifier, localCache, loanRenewConfig) {
|
|
14
9
|
this.isPageChanged = isPageChanged;
|
|
15
10
|
this.identifier = identifier;
|
|
16
11
|
this.localCache = localCache;
|
|
@@ -39,7 +34,7 @@ export class OneHourLoanRenew {
|
|
|
39
34
|
console.log('page changed!!');
|
|
40
35
|
return this.pageChanged(); // user clicked on page
|
|
41
36
|
}
|
|
42
|
-
|
|
37
|
+
|
|
43
38
|
return this.autoChecker(); // auto checker at 50th minute
|
|
44
39
|
} catch (error) {
|
|
45
40
|
console.log(error);
|
|
@@ -94,7 +89,7 @@ export class OneHourLoanRenew {
|
|
|
94
89
|
lastPageFlipTime <= lastFlipTimeFrame
|
|
95
90
|
) {
|
|
96
91
|
// not viewed
|
|
97
|
-
console.log(
|
|
92
|
+
console.log("Not viewed, don't borrow it!");
|
|
98
93
|
this.loanRenewResult.texts = this.loanReturnWarning;
|
|
99
94
|
this.loanRenewResult.renewNow = false;
|
|
100
95
|
} else if (lastPageFlipTime >= lastFlipTimeFrame) {
|
|
@@ -109,8 +104,7 @@ export class OneHourLoanRenew {
|
|
|
109
104
|
return this.loanRenewResult;
|
|
110
105
|
}
|
|
111
106
|
|
|
112
|
-
|
|
113
|
-
// save page changed time in indexedDB
|
|
107
|
+
// save page changed time in indexedDB
|
|
114
108
|
async setPageChangedTime() {
|
|
115
109
|
await this.localCache.set({
|
|
116
110
|
key: `${this.identifier}-pageChangedTime`,
|
package/src/ia-book-actions.js
CHANGED
|
@@ -73,7 +73,6 @@ export default class IABookActions extends LitElement {
|
|
|
73
73
|
renewNow: false,
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
|
|
77
76
|
// private props
|
|
78
77
|
this.primaryActions = [];
|
|
79
78
|
this.primaryTitle = '';
|
|
@@ -114,27 +113,19 @@ export default class IABookActions extends LitElement {
|
|
|
114
113
|
|
|
115
114
|
bindLoanRenewEvents() {
|
|
116
115
|
// dispatched this event from bookreader page changed
|
|
117
|
-
window.addEventListener(
|
|
118
|
-
console.log('window addEventListener!')
|
|
116
|
+
window.addEventListener('BookReader:pageChanged', () => {
|
|
119
117
|
// early return if book is not browsed (1 hour borrow)
|
|
120
|
-
if (this.borrowType
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
this.addEventListener('BookReader:pageChanged', e => {
|
|
127
|
-
console.log('this addEventListener!')
|
|
128
|
-
|
|
129
|
-
// early return if book is not browsed (1 hour borrow)
|
|
130
|
-
if (this.borrowType !== 'browsed') return nothing;
|
|
118
|
+
if (this.borrowType === 'browsed') {
|
|
119
|
+
this.isPageChanged = true;
|
|
120
|
+
this.executeLoanRenew();
|
|
121
|
+
}
|
|
131
122
|
|
|
132
|
-
this.
|
|
133
|
-
|
|
134
|
-
})
|
|
123
|
+
console.log(this.loanRenewResult)
|
|
124
|
+
return nothing;
|
|
125
|
+
});
|
|
135
126
|
|
|
136
127
|
// dispatched this event from timer-countdown
|
|
137
|
-
this.addEventListener('IABookActions:loanRenew',
|
|
128
|
+
this.addEventListener('IABookActions:loanRenew', () => {
|
|
138
129
|
this.isPageChanged = false;
|
|
139
130
|
this.executeLoanRenew();
|
|
140
131
|
});
|
|
@@ -148,7 +139,7 @@ export default class IABookActions extends LitElement {
|
|
|
148
139
|
this.loanRenewConfig
|
|
149
140
|
);
|
|
150
141
|
|
|
151
|
-
console.log(this.loanRenewResult)
|
|
142
|
+
console.log(this.loanRenewResult);
|
|
152
143
|
|
|
153
144
|
if (this.loanRenewResult.renewNow) {
|
|
154
145
|
this.tokenPoller.disconnectedInterval();
|
|
@@ -168,7 +159,8 @@ export default class IABookActions extends LitElement {
|
|
|
168
159
|
await this.localCache.delete(`${this.identifier}-pageChangedTime`);
|
|
169
160
|
|
|
170
161
|
// show message after browsed book is expired.
|
|
171
|
-
this.loanRenewResult.texts =
|
|
162
|
+
this.loanRenewResult.texts =
|
|
163
|
+
'This book has been auto-returned due to inactivity.';
|
|
172
164
|
this.update();
|
|
173
165
|
}
|
|
174
166
|
|
|
@@ -296,9 +288,12 @@ export default class IABookActions extends LitElement {
|
|
|
296
288
|
// - start token to poller around this.tokenDelay time until renew is completed
|
|
297
289
|
// else
|
|
298
290
|
// - start token poller immediately
|
|
299
|
-
setTimeout(
|
|
300
|
-
|
|
301
|
-
|
|
291
|
+
setTimeout(
|
|
292
|
+
() => {
|
|
293
|
+
this.startLoanTokenPoller();
|
|
294
|
+
},
|
|
295
|
+
this.loanRenewResult.renewNow ? this.tokenDelay : 100
|
|
296
|
+
);
|
|
302
297
|
}
|
|
303
298
|
|
|
304
299
|
render() {
|
|
@@ -340,7 +335,6 @@ export default class IABookActions extends LitElement {
|
|
|
340
335
|
|
|
341
336
|
get bookActionBar() {
|
|
342
337
|
return html`
|
|
343
|
-
<button @click=${() => this.pageChangedEvent()}>Page Change</button>
|
|
344
338
|
<collapsible-action-group
|
|
345
339
|
.userid=${this.userid}
|
|
346
340
|
.identifier=${this.identifier}
|
|
@@ -364,18 +358,6 @@ export default class IABookActions extends LitElement {
|
|
|
364
358
|
`;
|
|
365
359
|
}
|
|
366
360
|
|
|
367
|
-
// will move this function to bookreader...
|
|
368
|
-
pageChangedEvent() {
|
|
369
|
-
// dispatch event to say book page has flipped
|
|
370
|
-
document.querySelector('ia-book-actions').dispatchEvent(
|
|
371
|
-
new CustomEvent('BookReader:pageChanged', {
|
|
372
|
-
detail: { isPageChanged: true },
|
|
373
|
-
bubbles: true,
|
|
374
|
-
composed: true,
|
|
375
|
-
})
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
361
|
/**
|
|
380
362
|
* enable access of borrowed/browsed books
|
|
381
363
|
*/
|