@internetarchive/ia-book-actions 0.0.29-alpha12 → 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
@@ -129,8 +129,8 @@
129
129
  iaBookActions.returnUrl = 'https://openlibrary.org';
130
130
  iaBookActions.localCache = localCache;
131
131
  iaBookActions.loanRenewConfig = {
132
- totalTime: 60, // 60 second = 1 min
133
- autoCheckAt: 55, // totalTime - 10th minute
132
+ totalTime: 10, // 60 second = 1 min
133
+ autoCheckAt: 5, // totalTime - 10th minute
134
134
  pageChangedInLast: 15, // within last 15 second/minute
135
135
  };
136
136
 
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.29-alpha12",
3
+ "version": "0.0.29-alpha14",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -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('Not viewed, don\'t borrow it!');
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`,
@@ -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,17 +113,18 @@ export default class IABookActions extends LitElement {
114
113
 
115
114
  bindLoanRenewEvents() {
116
115
  // dispatched this event from bookreader page changed
117
- this.addEventListener('BookReader:pageChanged', e => {
118
-
116
+ window.addEventListener('BookReader:pageChanged', () => {
119
117
  // early return if book is not browsed (1 hour borrow)
120
- if (this.borrowType !== 'browsed') return nothing;
118
+ if (this.borrowType === 'browsed') {
119
+ this.isPageChanged = true;
120
+ this.executeLoanRenew();
121
+ }
121
122
 
122
- this.isPageChanged = true;
123
- this.executeLoanRenew();
124
- })
123
+ return nothing;
124
+ });
125
125
 
126
126
  // dispatched this event from timer-countdown
127
- this.addEventListener('IABookActions:loanRenew', e => {
127
+ this.addEventListener('IABookActions:loanRenew', () => {
128
128
  this.isPageChanged = false;
129
129
  this.executeLoanRenew();
130
130
  });
@@ -138,7 +138,7 @@ export default class IABookActions extends LitElement {
138
138
  this.loanRenewConfig
139
139
  );
140
140
 
141
- console.log(this.loanRenewResult)
141
+ console.log(this.loanRenewResult);
142
142
 
143
143
  if (this.loanRenewResult.renewNow) {
144
144
  this.tokenPoller.disconnectedInterval();
@@ -158,7 +158,9 @@ export default class IABookActions extends LitElement {
158
158
  await this.localCache.delete(`${this.identifier}-pageChangedTime`);
159
159
 
160
160
  // show message after browsed book is expired.
161
- this.loanRenewResult.texts = 'This book has been auto-returned due to inactivity.';
161
+ this.loanRenewResult.texts =
162
+ 'This book has been auto-returned due to inactivity.';
163
+ this.update();
162
164
  }
163
165
 
164
166
  async browseHasRenew() {
@@ -285,9 +287,12 @@ export default class IABookActions extends LitElement {
285
287
  // - start token to poller around this.tokenDelay time until renew is completed
286
288
  // else
287
289
  // - start token poller immediately
288
- setTimeout(() => {
289
- this.startLoanTokenPoller();
290
- }, this.loanRenewResult.renewNow ? this.tokenDelay : 100);
290
+ setTimeout(
291
+ () => {
292
+ this.startLoanTokenPoller();
293
+ },
294
+ this.loanRenewResult.renewNow ? this.tokenDelay : 100
295
+ );
291
296
  }
292
297
 
293
298
  render() {
@@ -329,7 +334,6 @@ export default class IABookActions extends LitElement {
329
334
 
330
335
  get bookActionBar() {
331
336
  return html`
332
- <button @click=${() => this.pageChangedEvent()}>Page Change</button>
333
337
  <collapsible-action-group
334
338
  .userid=${this.userid}
335
339
  .identifier=${this.identifier}
@@ -346,6 +350,7 @@ export default class IABookActions extends LitElement {
346
350
  ?renewNow=${this.loanRenewResult.renewNow}
347
351
  @lendingActionError=${this.handleLendingActionError}
348
352
  @toggleActionGroup=${this.handleToggleActionGroup}
353
+ @BookReader:pageChanged=${() => console.log('dfd')}
349
354
  >
350
355
  </collapsible-action-group>
351
356
  ${this.textGroupTemplate} ${this.infoIconTemplate}