@internetarchive/ia-book-actions 0.0.6-1 → 0.0.6-2
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 +1 -1
- package/src/assets/styles/collapsible-action-group.js +7 -2
- package/src/components/collapsible-action-group.js +25 -8
- package/src/core/services/actions-handler/actions-handler-service.js +10 -27
- package/src/core/services/actions-handler/actions-handler.js +56 -5
- package/src/ia-book-actions.js +17 -2
- package/test/components/collapsible-action-group.test.js +16 -0
package/package.json
CHANGED
|
@@ -80,7 +80,7 @@ export default css`
|
|
|
80
80
|
padding: 0 0.6rem;
|
|
81
81
|
margin-left: 0;
|
|
82
82
|
}
|
|
83
|
-
.
|
|
83
|
+
.actionloader {
|
|
84
84
|
vertical-align: middle;
|
|
85
85
|
visibility: hidden;
|
|
86
86
|
padding: 0.9rem 0.2rem;
|
|
@@ -129,9 +129,14 @@ export default css`
|
|
|
129
129
|
display: initial;
|
|
130
130
|
font-size: 1.4rem;
|
|
131
131
|
}
|
|
132
|
-
|
|
133
132
|
.unavailable {
|
|
134
133
|
opacity: 0.7;
|
|
135
134
|
pointer-events: none;
|
|
136
135
|
}
|
|
136
|
+
|
|
137
|
+
.disabled {
|
|
138
|
+
opacity: 0.8;
|
|
139
|
+
pointer-events: none;
|
|
140
|
+
visibility: visible;
|
|
141
|
+
}
|
|
137
142
|
`;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { html } from 'lit-element';
|
|
2
2
|
import { nothing } from 'lit-html';
|
|
3
|
+
import { classMap } from 'lit-html/directives/class-map';
|
|
3
4
|
|
|
4
5
|
import ActionsHandler from '../core/services/actions-handler/actions-handler.js';
|
|
5
6
|
|
|
@@ -25,6 +26,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
25
26
|
width: { type: Number },
|
|
26
27
|
hasAdminAccess: { type: Boolean },
|
|
27
28
|
dropdownArrow: { type: String },
|
|
29
|
+
disabled: { type: Boolean },
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
32
|
|
|
@@ -42,6 +44,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
42
44
|
this.initialButton = false;
|
|
43
45
|
this.title = '';
|
|
44
46
|
this.loaderIcon = 'https://archive.org/upload/images/tree/loading.gif';
|
|
47
|
+
this.disabled = false;
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
updated(changed) {
|
|
@@ -94,13 +97,20 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
94
97
|
|
|
95
98
|
render() {
|
|
96
99
|
return html`
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
<div
|
|
101
|
+
class="${classMap({
|
|
102
|
+
actiongroup: true,
|
|
103
|
+
disabled: this.disabled,
|
|
104
|
+
})}"
|
|
105
|
+
>
|
|
106
|
+
${this.getLoaderIcon}
|
|
107
|
+
<section class="action-buttons primary">
|
|
108
|
+
${this.renderPrimaryActions}
|
|
109
|
+
</section>
|
|
110
|
+
<section class="action-buttons secondary">
|
|
111
|
+
${this.renderSecondaryActions}
|
|
112
|
+
</section>
|
|
113
|
+
</div>
|
|
104
114
|
`;
|
|
105
115
|
}
|
|
106
116
|
|
|
@@ -225,7 +235,14 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
225
235
|
* @returns { HTMLElement }
|
|
226
236
|
*/
|
|
227
237
|
get getLoaderIcon() {
|
|
228
|
-
return html`<img
|
|
238
|
+
return html`<img
|
|
239
|
+
class="${classMap({
|
|
240
|
+
actionloader: true,
|
|
241
|
+
disabled: this.disabled,
|
|
242
|
+
})}"
|
|
243
|
+
alt=""
|
|
244
|
+
src="${this.loaderIcon}"
|
|
245
|
+
/>`;
|
|
229
246
|
}
|
|
230
247
|
|
|
231
248
|
/**
|
|
@@ -10,19 +10,15 @@ export default function ActionsHandlerService(options) {
|
|
|
10
10
|
identifier: '',
|
|
11
11
|
data: {},
|
|
12
12
|
success() {},
|
|
13
|
-
error
|
|
13
|
+
error() {},
|
|
14
14
|
loader: true,
|
|
15
15
|
type: 'POST',
|
|
16
16
|
...options,
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
if (option.loader) {
|
|
20
|
-
showActionButtonLoader();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
19
|
let baseHost = '';
|
|
24
20
|
if (window.location.pathname === '/demo/') {
|
|
25
|
-
baseHost = `/demo
|
|
21
|
+
baseHost = `/demo/1`;
|
|
26
22
|
} else {
|
|
27
23
|
baseHost = `/services/loans/loan`;
|
|
28
24
|
}
|
|
@@ -34,25 +30,12 @@ export default function ActionsHandlerService(options) {
|
|
|
34
30
|
fetch(baseHost, {
|
|
35
31
|
method: 'POST',
|
|
36
32
|
body: formData,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function showActionButtonLoader() {
|
|
49
|
-
const collapsibleElement = document
|
|
50
|
-
.querySelector('ia-book-actions')
|
|
51
|
-
.shadowRoot.querySelector('collapsible-action-group');
|
|
52
|
-
collapsibleElement.setAttribute('style', 'opacity:0.8; pointer-events:none');
|
|
53
|
-
|
|
54
|
-
const actionLoader = collapsibleElement.shadowRoot.querySelector(
|
|
55
|
-
'.action-loader'
|
|
56
|
-
);
|
|
57
|
-
actionLoader.setAttribute('style', 'visibility: visible');
|
|
33
|
+
}).then(response => {
|
|
34
|
+
if (response.status === 200) {
|
|
35
|
+
option?.success(response);
|
|
36
|
+
} else {
|
|
37
|
+
option?.error(response);
|
|
38
|
+
}
|
|
39
|
+
return;
|
|
40
|
+
});
|
|
58
41
|
}
|
|
@@ -90,53 +90,93 @@ export default class ActionsHandler extends LitElement {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
handleBrowseIt() {
|
|
93
|
+
const context = 'browse_book';
|
|
94
|
+
this.toggleLoader(context);
|
|
95
|
+
|
|
93
96
|
ActionsHandlerService({
|
|
94
|
-
action:
|
|
97
|
+
action: context,
|
|
95
98
|
identifier: this.identifier,
|
|
96
99
|
success: () => {
|
|
97
100
|
this.handleReadItNow();
|
|
98
101
|
},
|
|
102
|
+
error: response => {
|
|
103
|
+
console.log(response);
|
|
104
|
+
alert(JSON.stringify(response.error));
|
|
105
|
+
this.toggleLoader(context);
|
|
106
|
+
},
|
|
99
107
|
});
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
handleReturnIt() {
|
|
111
|
+
const context = 'return_loan';
|
|
112
|
+
this.toggleLoader(context);
|
|
113
|
+
|
|
103
114
|
ActionsHandlerService({
|
|
104
|
-
action:
|
|
115
|
+
action: context,
|
|
105
116
|
identifier: this.identifier,
|
|
106
117
|
success: () => {
|
|
107
118
|
this.deleteLoanCookies();
|
|
108
119
|
URLHelper.goToUrl(`/details/${this.identifier}`, true);
|
|
109
120
|
},
|
|
121
|
+
error: response => {
|
|
122
|
+
console.log(response);
|
|
123
|
+
alert(JSON.stringify(response.error));
|
|
124
|
+
this.toggleLoader(context);
|
|
125
|
+
},
|
|
110
126
|
});
|
|
111
127
|
}
|
|
112
128
|
|
|
113
129
|
handleBorrowIt() {
|
|
130
|
+
const context = 'borrow_book';
|
|
131
|
+
this.toggleLoader(context);
|
|
132
|
+
|
|
114
133
|
ActionsHandlerService({
|
|
115
|
-
action:
|
|
134
|
+
action: context,
|
|
116
135
|
identifier: this.identifier,
|
|
117
136
|
success: () => {
|
|
118
137
|
this.handleReadItNow();
|
|
119
138
|
},
|
|
139
|
+
error: response => {
|
|
140
|
+
console.log(response);
|
|
141
|
+
alert(JSON.stringify(response.error));
|
|
142
|
+
this.toggleLoader(context);
|
|
143
|
+
},
|
|
120
144
|
});
|
|
121
145
|
}
|
|
122
146
|
|
|
123
147
|
handleReserveIt() {
|
|
148
|
+
const context = 'join_waitlist';
|
|
149
|
+
this.toggleLoader(context);
|
|
150
|
+
|
|
124
151
|
ActionsHandlerService({
|
|
125
|
-
action:
|
|
152
|
+
action: context,
|
|
126
153
|
identifier: this.identifier,
|
|
127
154
|
success: () => {
|
|
128
155
|
URLHelper.goToUrl(URLHelper.getRedirectUrl(), true);
|
|
129
156
|
},
|
|
157
|
+
error: response => {
|
|
158
|
+
console.log(response);
|
|
159
|
+
alert(JSON.stringify(response.error));
|
|
160
|
+
this.toggleLoader(context);
|
|
161
|
+
},
|
|
130
162
|
});
|
|
131
163
|
}
|
|
132
164
|
|
|
133
165
|
handleRemoveFromWaitingList() {
|
|
166
|
+
const context = 'leave_waitlist';
|
|
167
|
+
this.toggleLoader(context);
|
|
168
|
+
|
|
134
169
|
ActionsHandlerService({
|
|
135
|
-
action:
|
|
170
|
+
action: context,
|
|
136
171
|
identifier: this.identifier,
|
|
137
172
|
success: () => {
|
|
138
173
|
URLHelper.goToUrl(URLHelper.getRedirectUrl(), true);
|
|
139
174
|
},
|
|
175
|
+
error: response => {
|
|
176
|
+
console.log(response);
|
|
177
|
+
alert(JSON.stringify(response.error));
|
|
178
|
+
this.toggleLoader(context);
|
|
179
|
+
},
|
|
140
180
|
});
|
|
141
181
|
}
|
|
142
182
|
|
|
@@ -151,6 +191,9 @@ export default class ActionsHandler extends LitElement {
|
|
|
151
191
|
handleReadItNow(extraParam) {
|
|
152
192
|
const currentParams = new URLSearchParams(window.location.search);
|
|
153
193
|
|
|
194
|
+
// Delete the ?q= parameter just after borrow a book. see: WEBDEV-3979
|
|
195
|
+
currentParams.delete('q');
|
|
196
|
+
|
|
154
197
|
if (extraParam) {
|
|
155
198
|
// append extraParam key-value in currentParams
|
|
156
199
|
const extraParams = new URLSearchParams(extraParam);
|
|
@@ -186,4 +229,12 @@ export default class ActionsHandler extends LitElement {
|
|
|
186
229
|
cookie += '; path=/; domain=.archive.org;';
|
|
187
230
|
document.cookie = cookie;
|
|
188
231
|
}
|
|
232
|
+
|
|
233
|
+
toggleLoader(context) {
|
|
234
|
+
this.dispatchEvent(
|
|
235
|
+
new CustomEvent('toggle-loader', {
|
|
236
|
+
detail: context,
|
|
237
|
+
})
|
|
238
|
+
);
|
|
239
|
+
}
|
|
189
240
|
}
|
package/src/ia-book-actions.js
CHANGED
|
@@ -22,6 +22,7 @@ export default class IABookActions extends LitElement {
|
|
|
22
22
|
bwbPurchaseUrl: { type: String },
|
|
23
23
|
barType: { type: String },
|
|
24
24
|
sharedObserver: { attribute: false },
|
|
25
|
+
disable: { type: Boolean },
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -40,6 +41,7 @@ export default class IABookActions extends LitElement {
|
|
|
40
41
|
this.primaryColor = 'primary';
|
|
41
42
|
this.secondaryActions = [];
|
|
42
43
|
this.lendingOptions = {};
|
|
44
|
+
this.disable = false;
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
disconnectedCallback() {
|
|
@@ -67,8 +69,7 @@ export default class IABookActions extends LitElement {
|
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
browseHasExpired() {
|
|
70
|
-
const
|
|
71
|
-
const currStatus = { ...this.lendingStatus, browsingExpired };
|
|
72
|
+
const currStatus = { ...this.lendingStatus, browsingExpired: true };
|
|
72
73
|
this.lendingStatus = currStatus;
|
|
73
74
|
}
|
|
74
75
|
|
|
@@ -173,12 +174,26 @@ export default class IABookActions extends LitElement {
|
|
|
173
174
|
.secondaryActions=${this.secondaryActions}
|
|
174
175
|
.width=${this.width}
|
|
175
176
|
.hasAdminAccess=${this.hasAdminAccess}
|
|
177
|
+
.disabled=${this.disable}
|
|
178
|
+
@toggle-loader=${this.toggleLoader}
|
|
176
179
|
>
|
|
177
180
|
</collapsible-action-group>
|
|
178
181
|
${this.textGroupTemplate} ${this.infoIconTemplate}
|
|
179
182
|
`;
|
|
180
183
|
}
|
|
181
184
|
|
|
185
|
+
toggleLoader(e) {
|
|
186
|
+
// if activity loader is disabled and action is browse or borrow,
|
|
187
|
+
// just change the lendingStatus to dynamic update action buttons
|
|
188
|
+
if (this.disable && ['browse_book', 'borrow_book'].includes(e.detail)) {
|
|
189
|
+
console.log('lendingStatus is changed to redraw action-buttons');
|
|
190
|
+
const currStatus = { ...this.lendingStatus, available_to_browse: false };
|
|
191
|
+
this.lendingStatus = currStatus;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
this.disable = !this.disable;
|
|
195
|
+
}
|
|
196
|
+
|
|
182
197
|
get iconClass() {
|
|
183
198
|
return this.width <= mobileContainerWidth ? 'mobile' : 'desktop';
|
|
184
199
|
}
|
|
@@ -39,6 +39,22 @@ describe('<collapsible-action-group>', () => {
|
|
|
39
39
|
const primaryButton = primaryActionContainer.querySelector('.ia-button');
|
|
40
40
|
expect(primaryButton.innerText).to.equal('Borrow for 1 hour');
|
|
41
41
|
});
|
|
42
|
+
|
|
43
|
+
it('check if loader is active and action-group is disabled', async () => {
|
|
44
|
+
const el = await fixture(container());
|
|
45
|
+
|
|
46
|
+
const primaryActionContainer = el.shadowRoot.querySelector('.primary');
|
|
47
|
+
primaryActionContainer
|
|
48
|
+
.querySelector('.ia-button')
|
|
49
|
+
.dispatchEvent(new CustomEvent('toggle-loader'));
|
|
50
|
+
el.disabled = true;
|
|
51
|
+
await el.updateComplete;
|
|
52
|
+
|
|
53
|
+
expect(el.disabled).to.be.true;
|
|
54
|
+
expect(el.shadowRoot.querySelector('div').classList.contains('disabled')).to
|
|
55
|
+
.be.true;
|
|
56
|
+
});
|
|
57
|
+
|
|
42
58
|
it('fires analytics events', async () => {
|
|
43
59
|
const el = await fixture(container());
|
|
44
60
|
const primaryActionContainer = el.shadowRoot.querySelector('.primary');
|