@internetarchive/ia-book-actions 0.0.29-alpha13 → 0.0.29-alpha14
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
|
@@ -278,6 +278,19 @@
|
|
|
278
278
|
iaBookActions.bwbPurchaseUrl = bwbPurchaseUrl;
|
|
279
279
|
})
|
|
280
280
|
});
|
|
281
|
+
|
|
282
|
+
document.querySelector('.pageChangedEvent').addEventListener('click', () => {
|
|
283
|
+
// dispatch event to say book page has flipped
|
|
284
|
+
document.querySelector('ia-book-actions').dispatchEvent(
|
|
285
|
+
new CustomEvent('BookReader:pageChanged', {
|
|
286
|
+
detail: { isPageChanged: true },
|
|
287
|
+
bubbles: true,
|
|
288
|
+
composed: true,
|
|
289
|
+
})
|
|
290
|
+
);
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
|
|
281
294
|
</script>
|
|
282
295
|
|
|
283
296
|
<div>
|
|
@@ -288,6 +301,9 @@
|
|
|
288
301
|
<td class="titleBar">
|
|
289
302
|
<label><input type="checkbox" name="title" value="title" />Title Bar</label>
|
|
290
303
|
</td>
|
|
304
|
+
<td>
|
|
305
|
+
<button class="pageChangedEvent">Page Change</button>
|
|
306
|
+
</td>
|
|
291
307
|
</tr>
|
|
292
308
|
</table>
|
|
293
309
|
</fieldset>
|
package/package.json
CHANGED
|
@@ -22,7 +22,7 @@ export class ToastMessage extends LitElement {
|
|
|
22
22
|
class="toast-message fade-in"
|
|
23
23
|
title="Click/tap to close"
|
|
24
24
|
@click=${() => {
|
|
25
|
-
this.dismisOnClick ? this.texts = null : nothing;
|
|
25
|
+
this.dismisOnClick ? (this.texts = null) : nothing;
|
|
26
26
|
}}
|
|
27
27
|
>${this.texts}</span
|
|
28
28
|
>
|
|
@@ -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,18 @@ 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!')
|
|
119
|
-
// early return if book is not browsed (1 hour borrow)
|
|
120
|
-
if (this.borrowType !== 'browsed') return nothing;
|
|
121
|
-
|
|
122
|
-
this.isPageChanged = true;
|
|
123
|
-
this.executeLoanRenew();
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
this.addEventListener('BookReader:pageChanged', e => {
|
|
127
|
-
console.log('this addEventListener!')
|
|
128
|
-
|
|
116
|
+
window.addEventListener('BookReader:pageChanged', () => {
|
|
129
117
|
// early return if book is not browsed (1 hour borrow)
|
|
130
|
-
if (this.borrowType
|
|
118
|
+
if (this.borrowType === 'browsed') {
|
|
119
|
+
this.isPageChanged = true;
|
|
120
|
+
this.executeLoanRenew();
|
|
121
|
+
}
|
|
131
122
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
})
|
|
123
|
+
return nothing;
|
|
124
|
+
});
|
|
135
125
|
|
|
136
126
|
// dispatched this event from timer-countdown
|
|
137
|
-
this.addEventListener('IABookActions:loanRenew',
|
|
127
|
+
this.addEventListener('IABookActions:loanRenew', () => {
|
|
138
128
|
this.isPageChanged = false;
|
|
139
129
|
this.executeLoanRenew();
|
|
140
130
|
});
|
|
@@ -148,7 +138,7 @@ export default class IABookActions extends LitElement {
|
|
|
148
138
|
this.loanRenewConfig
|
|
149
139
|
);
|
|
150
140
|
|
|
151
|
-
console.log(this.loanRenewResult)
|
|
141
|
+
console.log(this.loanRenewResult);
|
|
152
142
|
|
|
153
143
|
if (this.loanRenewResult.renewNow) {
|
|
154
144
|
this.tokenPoller.disconnectedInterval();
|
|
@@ -168,7 +158,8 @@ export default class IABookActions extends LitElement {
|
|
|
168
158
|
await this.localCache.delete(`${this.identifier}-pageChangedTime`);
|
|
169
159
|
|
|
170
160
|
// show message after browsed book is expired.
|
|
171
|
-
this.loanRenewResult.texts =
|
|
161
|
+
this.loanRenewResult.texts =
|
|
162
|
+
'This book has been auto-returned due to inactivity.';
|
|
172
163
|
this.update();
|
|
173
164
|
}
|
|
174
165
|
|
|
@@ -296,9 +287,12 @@ export default class IABookActions extends LitElement {
|
|
|
296
287
|
// - start token to poller around this.tokenDelay time until renew is completed
|
|
297
288
|
// else
|
|
298
289
|
// - start token poller immediately
|
|
299
|
-
setTimeout(
|
|
300
|
-
|
|
301
|
-
|
|
290
|
+
setTimeout(
|
|
291
|
+
() => {
|
|
292
|
+
this.startLoanTokenPoller();
|
|
293
|
+
},
|
|
294
|
+
this.loanRenewResult.renewNow ? this.tokenDelay : 100
|
|
295
|
+
);
|
|
302
296
|
}
|
|
303
297
|
|
|
304
298
|
render() {
|
|
@@ -340,7 +334,6 @@ export default class IABookActions extends LitElement {
|
|
|
340
334
|
|
|
341
335
|
get bookActionBar() {
|
|
342
336
|
return html`
|
|
343
|
-
<button @click=${() => this.pageChangedEvent()}>Page Change</button>
|
|
344
337
|
<collapsible-action-group
|
|
345
338
|
.userid=${this.userid}
|
|
346
339
|
.identifier=${this.identifier}
|
|
@@ -357,6 +350,7 @@ export default class IABookActions extends LitElement {
|
|
|
357
350
|
?renewNow=${this.loanRenewResult.renewNow}
|
|
358
351
|
@lendingActionError=${this.handleLendingActionError}
|
|
359
352
|
@toggleActionGroup=${this.handleToggleActionGroup}
|
|
353
|
+
@BookReader:pageChanged=${() => console.log('dfd')}
|
|
360
354
|
>
|
|
361
355
|
</collapsible-action-group>
|
|
362
356
|
${this.textGroupTemplate} ${this.infoIconTemplate}
|