@internetarchive/ia-book-actions 0.0.6-2 → 0.0.6-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
|
@@ -30,12 +30,23 @@ export default function ActionsHandlerService(options) {
|
|
|
30
30
|
fetch(baseHost, {
|
|
31
31
|
method: 'POST',
|
|
32
32
|
body: formData,
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
})
|
|
34
|
+
.then(response => {
|
|
35
|
+
if (baseHost == '/demo/1' || baseHost == '/demo/') {
|
|
36
|
+
return { error: 'There was an error.' };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// The response is a Response instance.
|
|
40
|
+
// You parse the data into a useable format using `.json()`
|
|
41
|
+
return response.json();
|
|
42
|
+
})
|
|
43
|
+
.then(data => {
|
|
44
|
+
// `data` is the parsed version of the JSON returned from the above endpoint.
|
|
45
|
+
console.log(data.error);
|
|
46
|
+
if (!data.error) {
|
|
47
|
+
option?.success(data);
|
|
48
|
+
} else {
|
|
49
|
+
option?.error(data);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
41
52
|
}
|
|
@@ -7,10 +7,7 @@ import ActionsHandlerService from './actions-handler-service.js';
|
|
|
7
7
|
*
|
|
8
8
|
* ActionsHandlerService is a function being used to execute
|
|
9
9
|
* APIs based of the request made by user. It consist some parameters are as follows:-
|
|
10
|
-
* 1.
|
|
11
|
-
* 2. identifier: book name.
|
|
12
|
-
* 3. success: This is callback function which will be executed after the API request
|
|
13
|
-
* return reponse as a success.
|
|
10
|
+
* 1. identifier: book name.
|
|
14
11
|
*/
|
|
15
12
|
|
|
16
13
|
export default class ActionsHandler extends LitElement {
|
|
@@ -97,11 +94,11 @@ export default class ActionsHandler extends LitElement {
|
|
|
97
94
|
action: context,
|
|
98
95
|
identifier: this.identifier,
|
|
99
96
|
success: () => {
|
|
100
|
-
this.handleReadItNow();
|
|
97
|
+
// this.handleReadItNow();
|
|
101
98
|
},
|
|
102
|
-
error:
|
|
103
|
-
console.log(
|
|
104
|
-
alert(
|
|
99
|
+
error: data => {
|
|
100
|
+
console.log(data);
|
|
101
|
+
alert(data.error);
|
|
105
102
|
this.toggleLoader(context);
|
|
106
103
|
},
|
|
107
104
|
});
|
|
@@ -118,9 +115,9 @@ export default class ActionsHandler extends LitElement {
|
|
|
118
115
|
this.deleteLoanCookies();
|
|
119
116
|
URLHelper.goToUrl(`/details/${this.identifier}`, true);
|
|
120
117
|
},
|
|
121
|
-
error:
|
|
122
|
-
console.log(
|
|
123
|
-
alert(
|
|
118
|
+
error: data => {
|
|
119
|
+
console.log(data);
|
|
120
|
+
alert(data.error);
|
|
124
121
|
this.toggleLoader(context);
|
|
125
122
|
},
|
|
126
123
|
});
|
|
@@ -136,9 +133,9 @@ export default class ActionsHandler extends LitElement {
|
|
|
136
133
|
success: () => {
|
|
137
134
|
this.handleReadItNow();
|
|
138
135
|
},
|
|
139
|
-
error:
|
|
140
|
-
console.log(
|
|
141
|
-
alert(
|
|
136
|
+
error: data => {
|
|
137
|
+
console.log(data);
|
|
138
|
+
alert(data.error);
|
|
142
139
|
this.toggleLoader(context);
|
|
143
140
|
},
|
|
144
141
|
});
|
|
@@ -154,9 +151,9 @@ export default class ActionsHandler extends LitElement {
|
|
|
154
151
|
success: () => {
|
|
155
152
|
URLHelper.goToUrl(URLHelper.getRedirectUrl(), true);
|
|
156
153
|
},
|
|
157
|
-
error:
|
|
158
|
-
console.log(
|
|
159
|
-
alert(
|
|
154
|
+
error: data => {
|
|
155
|
+
console.log(data);
|
|
156
|
+
alert(data.error);
|
|
160
157
|
this.toggleLoader(context);
|
|
161
158
|
},
|
|
162
159
|
});
|
|
@@ -172,9 +169,9 @@ export default class ActionsHandler extends LitElement {
|
|
|
172
169
|
success: () => {
|
|
173
170
|
URLHelper.goToUrl(URLHelper.getRedirectUrl(), true);
|
|
174
171
|
},
|
|
175
|
-
error:
|
|
176
|
-
console.log(
|
|
177
|
-
alert(
|
|
172
|
+
error: data => {
|
|
173
|
+
console.log(data);
|
|
174
|
+
alert(data.error);
|
|
178
175
|
this.toggleLoader(context);
|
|
179
176
|
},
|
|
180
177
|
});
|
package/src/ia-book-actions.js
CHANGED
|
@@ -184,7 +184,7 @@ export default class IABookActions extends LitElement {
|
|
|
184
184
|
|
|
185
185
|
toggleLoader(e) {
|
|
186
186
|
// if activity loader is disabled and action is browse or borrow,
|
|
187
|
-
// just change the lendingStatus to
|
|
187
|
+
// just change the lendingStatus to update action buttons
|
|
188
188
|
if (this.disable && ['browse_book', 'borrow_book'].includes(e.detail)) {
|
|
189
189
|
console.log('lendingStatus is changed to redraw action-buttons');
|
|
190
190
|
const currStatus = { ...this.lendingStatus, available_to_browse: false };
|