@internetarchive/ia-book-actions 0.0.6-9-01 → 0.0.7-0
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@internetarchive/ia-book-actions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7-0",
|
|
4
4
|
"description": "Bookreader actions for borrowable book",
|
|
5
5
|
"author": "Internet Archive",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@internetarchive/icon-bookmark": "^1.1.3",
|
|
23
23
|
"@internetarchive/icon-close": "^1.1.3",
|
|
24
24
|
"@internetarchive/icon-info": "^1.2.6",
|
|
25
|
-
"@internetarchive/modal-manager": "^0.
|
|
25
|
+
"@internetarchive/modal-manager": "^0.1.0",
|
|
26
26
|
"@internetarchive/shared-resize-observer": "^0.0.1",
|
|
27
27
|
"lit-element": "^2.4.0",
|
|
28
28
|
"lit-html": "^1.3.0"
|
|
@@ -36,17 +36,11 @@ export default function ActionsHandlerService(options) {
|
|
|
36
36
|
'This book is not available to borrow at this time. Please try again later.';
|
|
37
37
|
|
|
38
38
|
// return error reponse if query param has ?error=true param...
|
|
39
|
-
|
|
39
|
+
const erroneousActions = ['browse_book', 'borrow_book', 'create_token'];
|
|
40
|
+
if (shouldReturnError && erroneousActions.includes(option.action)) {
|
|
40
41
|
return {
|
|
41
42
|
success: false,
|
|
42
|
-
error: tokenError,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (shouldReturnError) {
|
|
47
|
-
return {
|
|
48
|
-
status: true,
|
|
49
|
-
error: borrowError,
|
|
43
|
+
error: option.action === 'create_token' ? tokenError : borrowError,
|
|
50
44
|
};
|
|
51
45
|
}
|
|
52
46
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Helper function to fetch real-time lending status
|
|
3
|
+
*/
|
|
4
|
+
export default function getRealTimeLendingStatus(identifier) {
|
|
5
|
+
let url = `https://ia-petabox-neeraj.archive.org/services/book/lending-info.php?identifier=${identifier}`;
|
|
6
|
+
|
|
7
|
+
if (window.location.pathname === '/demo/') {
|
|
8
|
+
url = ''; // change URL to prevent error on localhost
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
fetch(url)
|
|
12
|
+
.then(response => {
|
|
13
|
+
// return { response_code: '400', data: 'error happened' };
|
|
14
|
+
return response.json();
|
|
15
|
+
})
|
|
16
|
+
.then(data => {
|
|
17
|
+
let newLendingInfo = data;
|
|
18
|
+
const newLendingStatus = data?.lendingStatus;
|
|
19
|
+
newLendingInfo = { ...newLendingInfo, ...newLendingStatus };
|
|
20
|
+
newLendingInfo.lendingStatus = '';
|
|
21
|
+
|
|
22
|
+
return newLendingInfo;
|
|
23
|
+
})
|
|
24
|
+
.catch(data => {
|
|
25
|
+
return data;
|
|
26
|
+
});
|
|
27
|
+
}
|
package/src/ia-book-actions.js
CHANGED
|
@@ -10,6 +10,8 @@ import './components/text-group.js';
|
|
|
10
10
|
import './components/info-icon.js';
|
|
11
11
|
|
|
12
12
|
import GetLendingActions from './core/services/get-lending-actions.js';
|
|
13
|
+
import getRealTimeLendingStatus from './core/services/get-realtime-lending-status.js';
|
|
14
|
+
|
|
13
15
|
import { mobileContainerWidth } from './core/config/constants.js';
|
|
14
16
|
|
|
15
17
|
export default class IABookActions extends LitElement {
|
|
@@ -45,6 +47,7 @@ export default class IABookActions extends LitElement {
|
|
|
45
47
|
this.lendingOptions = {};
|
|
46
48
|
this.disableActionGroup = false;
|
|
47
49
|
this.modalConfig = {};
|
|
50
|
+
this.realtimeInternal = 0; // store intervalID
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
disconnectedCallback() {
|
|
@@ -62,6 +65,20 @@ export default class IABookActions extends LitElement {
|
|
|
62
65
|
this.modalConfig.headerColor = '#d9534f';
|
|
63
66
|
}
|
|
64
67
|
this.setupLendingToolbarActions();
|
|
68
|
+
|
|
69
|
+
// fetch latest lending status after an internal
|
|
70
|
+
if (
|
|
71
|
+
this.lendingStatus.user_has_browsed ||
|
|
72
|
+
this.lendingStatus.user_has_borrowed
|
|
73
|
+
) {
|
|
74
|
+
this.realtimeInternal = setInterval(() => {
|
|
75
|
+
const latestLendingStatus = getRealTimeLendingStatus(
|
|
76
|
+
'naturalhistoryof00unse_4'
|
|
77
|
+
);
|
|
78
|
+
console.log(latestLendingStatus);
|
|
79
|
+
if (latestLendingStatus) this.lendingStatus = latestLendingStatus;
|
|
80
|
+
}, 30000); // 60000 ms = 1 min
|
|
81
|
+
}
|
|
65
82
|
}
|
|
66
83
|
|
|
67
84
|
updated(changed) {
|
|
@@ -236,7 +253,7 @@ export default class IABookActions extends LitElement {
|
|
|
236
253
|
}
|
|
237
254
|
|
|
238
255
|
this.disableActionGroup = false;
|
|
239
|
-
this.modalConfig.title = '
|
|
256
|
+
this.modalConfig.title = 'Lending error';
|
|
240
257
|
this.modalConfig.message = errorMsg;
|
|
241
258
|
|
|
242
259
|
this.modal.showModal({
|