@internetarchive/ia-book-actions 0.0.7-11 → 0.0.7-12

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
@@ -106,16 +106,17 @@
106
106
 
107
107
  let lendingBarPostInit = function lendingBarPostInit() {
108
108
  setTimeout(function() {
109
- console.log('executed');
109
+ console.log('executed', 'br.init()');
110
110
  }, 100);
111
111
  }
112
+
112
113
  // set defaultLendingStatus for unavailable (without borrowables) book
113
114
  iaBookActions.userid = userid;
114
115
  iaBookActions.identifier = identifier;
115
116
  iaBookActions.bookTitle = 'Contemporary Black biography. Volume 39 : profiles from the interContemporary Black biography. Volume 39';
116
117
  iaBookActions.lendingStatus = canBrowseAndBorrow;
117
118
  iaBookActions.bwbPurchaseUrl = '';
118
- iaBookActions.barType = '';
119
+ // iaBookActions.barType = '';
119
120
  iaBookActions.modalConfig = modalConfig;
120
121
  iaBookActions.lendingBarPostInit = lendingBarPostInit;
121
122
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.7-11",
3
+ "version": "0.0.7-12",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -178,7 +178,6 @@ export default class ActionsHandler extends LitElement {
178
178
  });
179
179
  }
180
180
 
181
-
182
181
  /**
183
182
  * Dispatches event when an error occured on action
184
183
  * Notes:- toggle <collapsible-action-group> visibility (enable/disable).
@@ -12,8 +12,9 @@ export class LoanTokenPoller extends LitElement {
12
12
  constructor() {
13
13
  super();
14
14
  this.identifier = '';
15
- this.callback = () => {};
16
- this.loanTokenPollingDelay = window.location.pathname === '/demo/' ? 2000 : 120000; // 120000 ms = 2 min
15
+ this.callback = () => {}; // callback function to be called after loan token is created
16
+ this.loanTokenPollingDelay =
17
+ window.location.pathname === '/demo/' ? 2000 : 120000; // 120000 ms = 2 min
17
18
  this.loanTokenInterval = undefined;
18
19
  this.localCache = new LocalCache();
19
20
  }
@@ -23,7 +24,7 @@ export class LoanTokenPoller extends LitElement {
23
24
  }
24
25
 
25
26
  async enableBookAccess(identifier, borrowType, callback) {
26
- this.identifier = identifier
27
+ this.identifier = identifier;
27
28
  this.callback = callback;
28
29
  let consecutiveLoanCounts = 1;
29
30
 
@@ -52,7 +53,7 @@ export class LoanTokenPoller extends LitElement {
52
53
  const action = `${
53
54
  borrowType === 'browsed' ? 'BrowseCounts-' : 'Counts-'
54
55
  }${consecutiveLoanCounts}`;
55
- console.log(consecutiveLoanCounts)
56
+
56
57
  this.sendEvent(category, action);
57
58
  } else {
58
59
  // if book is not browsed, just clear token polling interval
@@ -72,39 +73,17 @@ export class LoanTokenPoller extends LitElement {
72
73
 
73
74
  async handleLoanTokenPoller() {
74
75
  const action = 'create_token';
75
- // await new Promise(r => setTimeout(r, 3000));
76
- console.log(this.callback)
77
76
  ActionsHandlerService({
78
77
  identifier: this.identifier,
79
78
  action,
80
79
  error: data => {
81
- console.log('error', data);
82
- this.handleLendingActionError({detail: { action, data }})
83
- // this.dispatchActionError(action, data);
80
+ this.handleLendingActionError({ detail: { action, data } });
84
81
  clearInterval(this.loanTokenInterval); // stop token fetch api
85
82
  this.callback();
86
83
  },
87
84
  success: () => {
88
85
  this.callback();
89
- }
86
+ },
90
87
  });
91
88
  }
92
-
93
- /**
94
- * Dispatches event when an error occured on action
95
- * Notes:- toggle <collapsible-action-group> visibility (enable/disable).
96
- *
97
- * @param { String } action - name of action like browse_book, borrow_book
98
- * @param { Object } data - erroneous response from api call
99
- *
100
- * @fires ActionsHandler#lendingActionError
101
- */
102
- dispatchActionError(action, data = {}) {
103
- console.log('disptaced');
104
- this.dispatchEvent(
105
- new CustomEvent('lendingActionError', {
106
- detail: { action, data },
107
- })
108
- );
109
- }
110
89
  }
@@ -66,7 +66,6 @@ export default class IABookActions extends LoanTokenPoller {
66
66
  }
67
67
 
68
68
  updated(changed) {
69
- // console.log(changed)
70
69
  if (changed.has('lendingStatus') || changed.has('bwbPurchaseUrl')) {
71
70
  this.setupLendingToolbarActions();
72
71
  this.update();
@@ -158,27 +157,32 @@ export default class IABookActions extends LoanTokenPoller {
158
157
  this.startBrowseTimer();
159
158
  }
160
159
 
161
- console.log('this.borrowType', this.borrowType);
162
-
163
160
  /**
161
+ * enable access of borrowed/browsed books
162
+ *
164
163
  * this.lendingBarPostInit() callback function use to:-
165
164
  * - disptach lendingFlow::PostInit event
166
165
  * - initialize bookreader using br.init()
167
166
  */
168
- if (this.borrowType) {
169
- // enable access of borrowed/browsed books
170
- this.enableBookAccess(this.identifier, this.borrowType, this.lendingBarPostInit);
171
- } else {
172
- this.lendingBarPostInit();
167
+ if (this.barType === 'action') {
168
+ this.enableBookAccess(
169
+ this.identifier,
170
+ this.borrowType,
171
+ this.lendingBarPostInit
172
+ );
173
173
  }
174
174
  }
175
175
 
176
176
  render() {
177
177
  if (this.barType === 'title') {
178
- return html`<section class="lending-wrapper">${this.bookTitleBar}</section>`;
178
+ return html`<section class="lending-wrapper">
179
+ ${this.bookTitleBar}
180
+ </section>`;
179
181
  }
180
182
 
181
- return html`<section class="lending-wrapper">${this.bookActionBar}</section>`;
183
+ return html`<section class="lending-wrapper">
184
+ ${this.bookActionBar}
185
+ </section>`;
182
186
  }
183
187
 
184
188
  get bookTitleBar() {
@@ -279,8 +283,7 @@ export default class IABookActions extends LoanTokenPoller {
279
283
  modalConfig.showCloseButton = false;
280
284
  modalConfig.message = html` Uh oh, something went wrong trying to access
281
285
  this book.<br />
282
- Please <a href="${() => window.location.reload(true)}">refresh</a> to
283
- try again or send us an email to
286
+ Please <a href="/">refresh</a> to try again or send us an email to
284
287
  <a
285
288
  href="mailto:info@archive.org?subject=Help: cannot access my borrowed book: ${this
286
289
  .identifier}"