@internetarchive/ia-book-actions 0.0.7-2 → 0.0.7-3
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/package.json
CHANGED
|
@@ -63,7 +63,11 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Handles events when user is borrowing book and wants to have access to read
|
|
68
|
+
*
|
|
69
|
+
* @fires CollapsibleActionGroup#enableBookAccess
|
|
70
|
+
*/
|
|
67
71
|
emitEnableBookAccess() {
|
|
68
72
|
// send consecutiveLoanCounts for browsed books only.
|
|
69
73
|
if (this.borrowType === 'browsing') {
|
|
@@ -222,11 +226,13 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
222
226
|
}
|
|
223
227
|
|
|
224
228
|
/**
|
|
225
|
-
*
|
|
226
|
-
* @param { string } eventName
|
|
227
|
-
* @param { object } gaEvent
|
|
229
|
+
* Handles click events when user click on action buttons
|
|
230
|
+
* @param { string } eventName - actions like 'browseBook', 'borrowBook' etc...
|
|
231
|
+
* @param { object } gaEvent - contains analytics event action and category
|
|
228
232
|
* @param { string } gaEvent.category
|
|
229
233
|
* @param { string } gaEvent.action
|
|
234
|
+
*
|
|
235
|
+
* @fires CollapsibleActionGroup#{eventName} - (will be browseBook, borrowBook etc...)
|
|
230
236
|
*/
|
|
231
237
|
clickHandler(eventName, gaEvent) {
|
|
232
238
|
this.dropdownState = 'close';
|
|
@@ -14,7 +14,7 @@ export default class ActionsHandler extends LitElement {
|
|
|
14
14
|
constructor(identifier) {
|
|
15
15
|
super();
|
|
16
16
|
this.identifier = identifier;
|
|
17
|
-
this.ajaxTimeout =
|
|
17
|
+
this.ajaxTimeout = 7000;
|
|
18
18
|
this.loanTokenPollingDelay =
|
|
19
19
|
window.location.pathname === '/demo/' ? 2000 : 120000; // 120000 ms = 2 min
|
|
20
20
|
this.loanTokenInterval = undefined;
|
|
@@ -119,102 +119,102 @@ export default class ActionsHandler extends LitElement {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
handleBrowseIt() {
|
|
122
|
-
const
|
|
122
|
+
const action = 'browse_book';
|
|
123
123
|
this.dispatchToggleActionGroup();
|
|
124
124
|
|
|
125
125
|
ActionsHandlerService({
|
|
126
|
-
action
|
|
126
|
+
action,
|
|
127
127
|
identifier: this.identifier,
|
|
128
128
|
success: () => {
|
|
129
129
|
this.handleReadItNow();
|
|
130
130
|
},
|
|
131
131
|
error: data => {
|
|
132
|
-
this.dispatchActionError(
|
|
132
|
+
this.dispatchActionError(action, data);
|
|
133
133
|
},
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
handleReturnIt() {
|
|
138
|
-
const
|
|
138
|
+
const action = 'return_loan';
|
|
139
139
|
this.dispatchToggleActionGroup();
|
|
140
140
|
|
|
141
141
|
ActionsHandlerService({
|
|
142
|
-
action
|
|
142
|
+
action,
|
|
143
143
|
identifier: this.identifier,
|
|
144
144
|
success: () => {
|
|
145
145
|
this.deleteLoanCookies();
|
|
146
146
|
URLHelper.goToUrl(`/details/${this.identifier}`, true);
|
|
147
147
|
},
|
|
148
148
|
error: data => {
|
|
149
|
-
this.dispatchActionError(
|
|
149
|
+
this.dispatchActionError(action, data);
|
|
150
150
|
},
|
|
151
151
|
});
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
handleBorrowIt() {
|
|
155
|
-
const
|
|
155
|
+
const action = 'borrow_book';
|
|
156
156
|
this.dispatchToggleActionGroup();
|
|
157
157
|
|
|
158
158
|
ActionsHandlerService({
|
|
159
|
-
action
|
|
159
|
+
action,
|
|
160
160
|
identifier: this.identifier,
|
|
161
161
|
success: () => {
|
|
162
162
|
this.handleReadItNow();
|
|
163
163
|
},
|
|
164
164
|
error: data => {
|
|
165
|
-
this.dispatchActionError(
|
|
165
|
+
this.dispatchActionError(action, data);
|
|
166
166
|
},
|
|
167
167
|
});
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
handleReserveIt() {
|
|
171
|
-
const
|
|
171
|
+
const action = 'join_waitlist';
|
|
172
172
|
this.dispatchToggleActionGroup();
|
|
173
173
|
|
|
174
174
|
ActionsHandlerService({
|
|
175
|
-
action
|
|
175
|
+
action,
|
|
176
176
|
identifier: this.identifier,
|
|
177
177
|
success: () => {
|
|
178
178
|
URLHelper.goToUrl(URLHelper.getRedirectUrl(), true);
|
|
179
179
|
},
|
|
180
180
|
error: data => {
|
|
181
|
-
this.dispatchActionError(
|
|
181
|
+
this.dispatchActionError(action, data);
|
|
182
182
|
},
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
handleRemoveFromWaitingList() {
|
|
187
|
-
const
|
|
187
|
+
const action = 'leave_waitlist';
|
|
188
188
|
this.dispatchToggleActionGroup();
|
|
189
189
|
|
|
190
190
|
ActionsHandlerService({
|
|
191
|
-
action
|
|
191
|
+
action,
|
|
192
192
|
identifier: this.identifier,
|
|
193
193
|
success: () => {
|
|
194
194
|
URLHelper.goToUrl(URLHelper.getRedirectUrl(), true);
|
|
195
195
|
},
|
|
196
196
|
error: data => {
|
|
197
|
-
this.dispatchActionError(
|
|
197
|
+
this.dispatchActionError(action, data);
|
|
198
198
|
},
|
|
199
199
|
});
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
handleLoanTokenPoller() {
|
|
203
|
-
const
|
|
203
|
+
const action = 'create_token';
|
|
204
204
|
ActionsHandlerService({
|
|
205
205
|
identifier: this.identifier,
|
|
206
|
-
action
|
|
206
|
+
action,
|
|
207
207
|
error: data => {
|
|
208
|
-
this.dispatchActionError(
|
|
208
|
+
this.dispatchActionError(action, data);
|
|
209
209
|
clearInterval(this.loanTokenInterval); // stop token fetch api
|
|
210
210
|
},
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
dispatchActionError(
|
|
214
|
+
dispatchActionError(action, data = {}) {
|
|
215
215
|
this.dispatchEvent(
|
|
216
216
|
new CustomEvent('lendingActionError', {
|
|
217
|
-
detail: {
|
|
217
|
+
detail: { action, data },
|
|
218
218
|
})
|
|
219
219
|
);
|
|
220
220
|
}
|
package/src/ia-book-actions.js
CHANGED
|
@@ -201,28 +201,27 @@ export default class IABookActions extends LitElement {
|
|
|
201
201
|
*
|
|
202
202
|
* @event IABookActions#lendingActionError
|
|
203
203
|
* @param {Object} event - The employee who is responsible for the project
|
|
204
|
-
*
|
|
205
|
-
*
|
|
204
|
+
* @param {string} event.detail.action - action when error occurred like 'browseBook', 'borrowBook'
|
|
205
|
+
* @param {string} event.detail.data.error - error message
|
|
206
206
|
*/
|
|
207
207
|
handleLendingActionError(event) {
|
|
208
|
-
console.log(event?.detail?.data);
|
|
209
208
|
// toggle activity loader
|
|
210
209
|
this.handleToggleActionGroup();
|
|
211
210
|
|
|
212
|
-
const
|
|
211
|
+
const action = event?.detail?.action;
|
|
213
212
|
const errorMsg = event?.detail?.data?.error;
|
|
214
213
|
|
|
215
|
-
if (errorMsg) this.showErrorModal(errorMsg);
|
|
214
|
+
if (errorMsg) this.showErrorModal(errorMsg, action);
|
|
216
215
|
|
|
217
216
|
// update action bar state if book is not available to browse or borrow.
|
|
218
217
|
if (errorMsg && errorMsg.match(/not available to borrow/gm)) {
|
|
219
218
|
let currStatus = this.lendingStatus;
|
|
220
|
-
if (
|
|
219
|
+
if (action === 'browse_book') {
|
|
221
220
|
currStatus = {
|
|
222
221
|
...this.lendingStatus,
|
|
223
222
|
available_to_browse: false,
|
|
224
223
|
};
|
|
225
|
-
} else if (
|
|
224
|
+
} else if (action === 'borrow_book') {
|
|
226
225
|
currStatus = {
|
|
227
226
|
...this.lendingStatus,
|
|
228
227
|
available_to_borrow: false,
|
|
@@ -233,7 +232,7 @@ export default class IABookActions extends LitElement {
|
|
|
233
232
|
}
|
|
234
233
|
|
|
235
234
|
/* show error message if something went wrong */
|
|
236
|
-
async showErrorModal(errorMsg) {
|
|
235
|
+
async showErrorModal(errorMsg, action) {
|
|
237
236
|
this.disableActionGroup = false;
|
|
238
237
|
|
|
239
238
|
this.modal = document.querySelector('#action-bar-modal');
|
|
@@ -243,12 +242,27 @@ export default class IABookActions extends LitElement {
|
|
|
243
242
|
}
|
|
244
243
|
await document.body.appendChild(this.modal);
|
|
245
244
|
|
|
245
|
+
const modalConfig = new ModalConfig({
|
|
246
|
+
title: 'Lending error',
|
|
247
|
+
message: errorMsg,
|
|
248
|
+
headerColor: '#d9534f',
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
if (action === 'create_token') {
|
|
252
|
+
modalConfig.closeOnBackdropClick = false;
|
|
253
|
+
modalConfig.showCloseButton = false;
|
|
254
|
+
modalConfig.message = html` Uh oh, something went wrong trying to access
|
|
255
|
+
this book.<br />
|
|
256
|
+
Please <a href="/">refresh</a> to try again or send us an email to
|
|
257
|
+
<a
|
|
258
|
+
href="mailto:info@archive.org?subject=Help: cannot access my borrowed book: ${this
|
|
259
|
+
.identifier}"
|
|
260
|
+
>info@archive.org</a
|
|
261
|
+
>`;
|
|
262
|
+
}
|
|
263
|
+
|
|
246
264
|
this.modal.showModal({
|
|
247
|
-
config:
|
|
248
|
-
title: 'Lending error',
|
|
249
|
-
message: errorMsg,
|
|
250
|
-
headerColor: '#d9534f',
|
|
251
|
-
}),
|
|
265
|
+
config: modalConfig,
|
|
252
266
|
});
|
|
253
267
|
}
|
|
254
268
|
|
|
@@ -87,7 +87,7 @@ describe('<collapsible-action-group>', () => {
|
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
describe('fetch loan token and localStorage for browsed/borrowsed book', () => {
|
|
90
|
-
|
|
90
|
+
beforeEach(() => {
|
|
91
91
|
const localStorageMock = {
|
|
92
92
|
getItem: Sinon.spy(),
|
|
93
93
|
setItem: Sinon.spy(),
|
|
@@ -97,14 +97,14 @@ describe('fetch loan token and localStorage for browsed/borrowsed book', () => {
|
|
|
97
97
|
});
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
it('test localStorage function when borrowType is
|
|
101
|
-
await fixture(container({ borrowType: '
|
|
100
|
+
it('test localStorage function when borrowType is browsing', async () => {
|
|
101
|
+
await fixture(container({ borrowType: 'browsing' }));
|
|
102
102
|
expect(localStorage.getItem).to.be.calledOnce;
|
|
103
103
|
expect(localStorage.getItem).to.be.calledWith('consecutive-loan-count');
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
-
it('test localStorage function when borrowType is
|
|
107
|
-
await fixture(container({ borrowType: '
|
|
106
|
+
it('test localStorage function when borrowType is borrowing', async () => {
|
|
107
|
+
await fixture(container({ borrowType: 'borrowing' }));
|
|
108
108
|
expect(localStorage.getItem).to.not.be.calledOnce;
|
|
109
109
|
expect(localStorage.getItem).to.not.be.calledWith('consecutive-loan-count');
|
|
110
110
|
});
|
|
@@ -122,7 +122,7 @@ describe('Borrow status actions', () => {
|
|
|
122
122
|
el.addEventListener('lendingActionError', () => {
|
|
123
123
|
el.handleLendingActionError({
|
|
124
124
|
detail: {
|
|
125
|
-
|
|
125
|
+
action: 'browse_book',
|
|
126
126
|
data: { error: 'not available to borrow' },
|
|
127
127
|
},
|
|
128
128
|
});
|
|
@@ -151,7 +151,7 @@ describe('Borrow status actions', () => {
|
|
|
151
151
|
el.addEventListener('lendingActionError', () => {
|
|
152
152
|
el.handleLendingActionError({
|
|
153
153
|
detail: {
|
|
154
|
-
|
|
154
|
+
action: 'borrow_book',
|
|
155
155
|
data: { error: 'not available to borrow' },
|
|
156
156
|
},
|
|
157
157
|
});
|