@internetarchive/ia-book-actions 0.0.5-5 → 0.0.5-a1
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 +3 -13
- package/package.json +1 -2
- package/src/core/services/actions-handler/actions-handler-service.js +2 -78
- package/src/core/services/actions-handler/actions-handler.js +0 -3
- package/src/ia-book-actions.js +1 -28
- package/demo/error.html +0 -4
- package/src/components/show-dialog.js +0 -115
- package/src/core/services/archive-token-poller.js +0 -88
package/demo/index.html
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
body {
|
|
13
13
|
margin: 0;
|
|
14
14
|
text-align: center;
|
|
15
|
-
font-family: "Helvetica Neue",
|
|
15
|
+
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
16
16
|
}
|
|
17
17
|
#demo {
|
|
18
18
|
height: 50px;
|
|
@@ -71,21 +71,10 @@
|
|
|
71
71
|
float: left;
|
|
72
72
|
margin: 2px;
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
.ui-overlay {
|
|
76
|
-
position: fixed;
|
|
77
|
-
top: 0;
|
|
78
|
-
left: 0;
|
|
79
|
-
width: 100%;
|
|
80
|
-
height: 100%;
|
|
81
|
-
background: black;
|
|
82
|
-
opacity: 0.3;
|
|
83
|
-
}
|
|
84
74
|
</style>
|
|
85
75
|
</head>
|
|
86
76
|
|
|
87
77
|
<body>
|
|
88
|
-
|
|
89
78
|
<ia-book-actions></ia-book-actions>
|
|
90
79
|
|
|
91
80
|
<script type="module">
|
|
@@ -107,7 +96,7 @@
|
|
|
107
96
|
iaBookActions.userid = '';
|
|
108
97
|
iaBookActions.identifier = identifier;
|
|
109
98
|
iaBookActions.bookTitle = 'Contemporary Black biography. Volume 39 : profiles from the interContemporary Black biography. Volume 39';
|
|
110
|
-
iaBookActions.lendingStatus =
|
|
99
|
+
iaBookActions.lendingStatus = defaultLendingStatus;
|
|
111
100
|
iaBookActions.bwbPurchaseUrl = '';
|
|
112
101
|
iaBookActions.barType = '';
|
|
113
102
|
|
|
@@ -214,6 +203,7 @@
|
|
|
214
203
|
})
|
|
215
204
|
});
|
|
216
205
|
</script>
|
|
206
|
+
|
|
217
207
|
<div>
|
|
218
208
|
<fieldset>
|
|
219
209
|
<legend>Dev testing for book title bar</legend>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@internetarchive/ia-book-actions",
|
|
3
|
-
"version": "0.0.5-
|
|
3
|
+
"version": "0.0.5-a1",
|
|
4
4
|
"description": "Bookreader actions for borrowable book",
|
|
5
5
|
"author": "Internet Archive",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"@internetarchive/ia-icons": "^1.2.2",
|
|
22
22
|
"@internetarchive/icon-bookmark": "^1.1.3",
|
|
23
23
|
"@internetarchive/icon-info": "^1.2.6",
|
|
24
|
-
"@internetarchive/icon-close": "^1.1.3",
|
|
25
24
|
"@internetarchive/shared-resize-observer": "^0.0.1",
|
|
26
25
|
"lit-element": "^2.4.0",
|
|
27
26
|
"lit-html": "^1.3.0"
|
|
@@ -11,7 +11,6 @@ export default function ActionsHandlerService(options) {
|
|
|
11
11
|
data: {},
|
|
12
12
|
success() {},
|
|
13
13
|
error: null,
|
|
14
|
-
callback() {},
|
|
15
14
|
loader: true,
|
|
16
15
|
type: 'POST',
|
|
17
16
|
...options,
|
|
@@ -23,7 +22,7 @@ export default function ActionsHandlerService(options) {
|
|
|
23
22
|
|
|
24
23
|
let baseHost = '';
|
|
25
24
|
if (window.location.pathname === '/demo/') {
|
|
26
|
-
baseHost = `/demo/`;
|
|
25
|
+
baseHost = `/demo/`;
|
|
27
26
|
} else {
|
|
28
27
|
baseHost = `/services/loans/loan`;
|
|
29
28
|
}
|
|
@@ -37,90 +36,15 @@ export default function ActionsHandlerService(options) {
|
|
|
37
36
|
body: formData,
|
|
38
37
|
})
|
|
39
38
|
.then(response => {
|
|
40
|
-
console.log('response', response);
|
|
41
|
-
|
|
42
|
-
if (baseHost == '/demo/') {
|
|
43
|
-
// option.callback('{"result": true, "token": "token-response"}');
|
|
44
|
-
// option.callback('{"error": "Unexpected error. Please email this link to openlibrary@archive.org with the subject: Unexpected error. Thank you."}');
|
|
45
|
-
|
|
46
|
-
showDialog(
|
|
47
|
-
option.action,
|
|
48
|
-
'{"error": "Unexpected error. Please email this link to openlibrary@archive.org with the subject: Unexpected error. Thank you."}'
|
|
49
|
-
);
|
|
50
|
-
// showDialog('{"result": true, "token": "token-response"}');
|
|
51
|
-
}
|
|
52
|
-
// showDialog(option.action, response);
|
|
53
|
-
// option.callback(response);
|
|
54
|
-
|
|
55
39
|
if (response.status === 200) {
|
|
56
40
|
option.success.call();
|
|
57
41
|
}
|
|
58
42
|
})
|
|
59
43
|
.catch(error => {
|
|
60
|
-
console.log(
|
|
61
|
-
// option.callback(error);
|
|
62
|
-
|
|
63
|
-
if (baseHost == '/demo/') {
|
|
64
|
-
showDialog(
|
|
65
|
-
option.action,
|
|
66
|
-
'{"error": "Unexpected error. Please email this link to openlibrary@archive.org with the subject: Unexpected error. Thank you."}'
|
|
67
|
-
);
|
|
68
|
-
// showDialog('{"result": true, "token": "token-response"}');
|
|
69
|
-
} else {
|
|
70
|
-
showDialog(option.action, error);
|
|
71
|
-
}
|
|
44
|
+
console.log(error);
|
|
72
45
|
});
|
|
73
46
|
}
|
|
74
47
|
|
|
75
|
-
function showDialog(action, xhrResponse) {
|
|
76
|
-
const showDialog = document
|
|
77
|
-
.querySelector('ia-book-actions')
|
|
78
|
-
.shadowRoot.querySelector('show-dialog');
|
|
79
|
-
|
|
80
|
-
let title = 'Connection error';
|
|
81
|
-
let body = 'Please check internet connection.';
|
|
82
|
-
let actions = [
|
|
83
|
-
{
|
|
84
|
-
text: 'Okay',
|
|
85
|
-
callback: () => {
|
|
86
|
-
weAreBack();
|
|
87
|
-
this.updateToken();
|
|
88
|
-
},
|
|
89
|
-
className: 'ia-button primary',
|
|
90
|
-
},
|
|
91
|
-
];
|
|
92
|
-
|
|
93
|
-
// Specific error
|
|
94
|
-
const data = JSON.parse(xhrResponse);
|
|
95
|
-
console.log('data', data);
|
|
96
|
-
if (data.error) {
|
|
97
|
-
title = 'Sorry!';
|
|
98
|
-
body = data.error;
|
|
99
|
-
// Only go back to item button on error
|
|
100
|
-
actions = [
|
|
101
|
-
{
|
|
102
|
-
text: 'Back to item details',
|
|
103
|
-
callback: () => {
|
|
104
|
-
URLHelper.goToUrl(this.lendingStatus.bookUrl);
|
|
105
|
-
},
|
|
106
|
-
className: 'ia-button primary',
|
|
107
|
-
},
|
|
108
|
-
];
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
showDialog.opened = true;
|
|
112
|
-
showDialog.title = title;
|
|
113
|
-
showDialog.body = body;
|
|
114
|
-
if (action === 'create_token') {
|
|
115
|
-
showDialog.actions = actions;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const overlayElement = document.createElement('div');
|
|
119
|
-
overlayElement.className = 'ui-overlay';
|
|
120
|
-
console.log(overlayElement);
|
|
121
|
-
document.getElementsByTagName('body')[0].appendChild(overlayElement);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
48
|
function showActionButtonLoader() {
|
|
125
49
|
const collapsibleElement = document
|
|
126
50
|
.querySelector('ia-book-actions')
|
|
@@ -151,9 +151,6 @@ export default class ActionsHandler extends LitElement {
|
|
|
151
151
|
handleReadItNow(extraParam) {
|
|
152
152
|
const currentParams = new URLSearchParams(window.location.search);
|
|
153
153
|
|
|
154
|
-
// Delete the ?q= parameter just after borrow a book. see: WEBDEV-3979
|
|
155
|
-
currentParams.delete('q');
|
|
156
|
-
|
|
157
154
|
if (extraParam) {
|
|
158
155
|
// append extraParam key-value in currentParams
|
|
159
156
|
const extraParams = new URLSearchParams(extraParam);
|
package/src/ia-book-actions.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
2
|
import { html, css, LitElement } from 'lit-element';
|
|
3
3
|
|
|
4
4
|
import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
|
|
@@ -7,11 +7,8 @@ import './components/collapsible-action-group.js';
|
|
|
7
7
|
import './components/book-title-bar.js';
|
|
8
8
|
import './components/text-group.js';
|
|
9
9
|
import './components/info-icon.js';
|
|
10
|
-
import './components/show-dialog.js';
|
|
11
10
|
|
|
12
11
|
import GetLendingActions from './core/services/get-lending-actions.js';
|
|
13
|
-
import ArchiveOrgTokenPoller from './core/services/archive-token-poller.js';
|
|
14
|
-
|
|
15
12
|
import { mobileContainerWidth } from './core/config/constants.js';
|
|
16
13
|
|
|
17
14
|
export default class IABookActions extends LitElement {
|
|
@@ -25,7 +22,6 @@ export default class IABookActions extends LitElement {
|
|
|
25
22
|
bwbPurchaseUrl: { type: String },
|
|
26
23
|
barType: { type: String },
|
|
27
24
|
sharedObserver: { attribute: false },
|
|
28
|
-
dialogVisible: { type: Boolean },
|
|
29
25
|
};
|
|
30
26
|
}
|
|
31
27
|
|
|
@@ -44,7 +40,6 @@ export default class IABookActions extends LitElement {
|
|
|
44
40
|
this.primaryColor = 'primary';
|
|
45
41
|
this.secondaryActions = [];
|
|
46
42
|
this.lendingOptions = {};
|
|
47
|
-
this.dialogVisible = true;
|
|
48
43
|
}
|
|
49
44
|
|
|
50
45
|
disconnectedCallback() {
|
|
@@ -150,14 +145,6 @@ export default class IABookActions extends LitElement {
|
|
|
150
145
|
!this.lendingStatus.browseHasExpired
|
|
151
146
|
) {
|
|
152
147
|
this.startBrowseTimer();
|
|
153
|
-
|
|
154
|
-
// token poller start from here...
|
|
155
|
-
const tokenPoller = new ArchiveOrgTokenPoller(
|
|
156
|
-
this.identifier,
|
|
157
|
-
this.lendingStatus
|
|
158
|
-
);
|
|
159
|
-
tokenPoller.init();
|
|
160
|
-
return;
|
|
161
148
|
}
|
|
162
149
|
}
|
|
163
150
|
|
|
@@ -166,23 +153,9 @@ export default class IABookActions extends LitElement {
|
|
|
166
153
|
<section class="lending-wrapper">
|
|
167
154
|
${this.barType === 'title' ? this.bookTitleBar : this.bookActionBar}
|
|
168
155
|
</section>
|
|
169
|
-
|
|
170
|
-
<show-dialog
|
|
171
|
-
?opened="${this.dialogVisible}"
|
|
172
|
-
@dialog.close="${() => this.closeDialog(this)}"
|
|
173
|
-
></show-dialog>
|
|
174
156
|
`;
|
|
175
157
|
}
|
|
176
158
|
|
|
177
|
-
toggleDialog(e) {
|
|
178
|
-
this.dialogVisible = !this.dialogVisible;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
closeDialog(e) {
|
|
182
|
-
this.dialogVisible = false;
|
|
183
|
-
console.log('should close...', this.dialogVisible);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
159
|
get bookTitleBar() {
|
|
187
160
|
return html`<book-title-bar
|
|
188
161
|
.identifier=${this.identifier}
|
package/demo/error.html
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
import { LitElement, html, css } from 'lit-element';
|
|
3
|
-
import { classMap } from 'lit-html/directives/class-map';
|
|
4
|
-
|
|
5
|
-
import '@internetarchive/icon-close/icon-close.js';
|
|
6
|
-
import buttonBaseStyle from '../assets/styles/ia-button.js';
|
|
7
|
-
|
|
8
|
-
export class showDialog extends LitElement {
|
|
9
|
-
static get properties() {
|
|
10
|
-
return {
|
|
11
|
-
opened: { type: Boolean },
|
|
12
|
-
title: { type: Boolean },
|
|
13
|
-
body: { type: Boolean },
|
|
14
|
-
actions: { type: Array },
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
constructor() {
|
|
19
|
-
super();
|
|
20
|
-
this.opened = false;
|
|
21
|
-
this.title = 'Error';
|
|
22
|
-
this.body =
|
|
23
|
-
'Unexpected error: loan does not exist. Please try deleting your archive.org cookie.';
|
|
24
|
-
this.actions = [];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
render() {
|
|
28
|
-
return html`
|
|
29
|
-
<div
|
|
30
|
-
class="${classMap({
|
|
31
|
-
dialog: true,
|
|
32
|
-
opened: this.opened,
|
|
33
|
-
closed: !this.opened,
|
|
34
|
-
})}"
|
|
35
|
-
>
|
|
36
|
-
<div class="dialog-head">
|
|
37
|
-
${this.title}
|
|
38
|
-
<span
|
|
39
|
-
@click="${() =>
|
|
40
|
-
this.dispatchEvent(new CustomEvent('dialog.close'))}"
|
|
41
|
-
>
|
|
42
|
-
<ia-icon-close fill-color="blue"></ia-icon-close
|
|
43
|
-
></span>
|
|
44
|
-
</div>
|
|
45
|
-
<div class="dialog-body">${this.body}</div>
|
|
46
|
-
<div class="dialog-foot">${this.renderActionButton()}</div>
|
|
47
|
-
</div>
|
|
48
|
-
`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
renderActionButton() {
|
|
52
|
-
return this.actions.map(
|
|
53
|
-
action =>
|
|
54
|
-
html`<button class=${action.className} @click=${action.callback}>
|
|
55
|
-
${action.text}
|
|
56
|
-
</button>`
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
static get styles() {
|
|
61
|
-
const dialogStyle = css`
|
|
62
|
-
:host {
|
|
63
|
-
color: #343434;
|
|
64
|
-
font-size: 1.6rem;
|
|
65
|
-
}
|
|
66
|
-
.dialog {
|
|
67
|
-
position: absolute;
|
|
68
|
-
background: #fff;
|
|
69
|
-
border-radius: 1.2rem;
|
|
70
|
-
z-index: 3000;
|
|
71
|
-
flex-direction: column;
|
|
72
|
-
width: 400px;
|
|
73
|
-
max-width: 500px;
|
|
74
|
-
left: 50%;
|
|
75
|
-
transform: translateX(-50%);
|
|
76
|
-
|
|
77
|
-
border: 2px solid #ccc;
|
|
78
|
-
border-radius: 12px;
|
|
79
|
-
box-shadow: 0px 0px 27px 6px rgb(66 66 66 / 80%);
|
|
80
|
-
}
|
|
81
|
-
.dialog-head,
|
|
82
|
-
.dialog-body,
|
|
83
|
-
.dialog-foot {
|
|
84
|
-
padding: 1rem;
|
|
85
|
-
user-select: none;
|
|
86
|
-
text-align: left;
|
|
87
|
-
}
|
|
88
|
-
.dialog-body {
|
|
89
|
-
border: 1px solid #d8d8d8;
|
|
90
|
-
}
|
|
91
|
-
ia-icon-close {
|
|
92
|
-
float: right;
|
|
93
|
-
display: inline-block;
|
|
94
|
-
width: 2.5rem;
|
|
95
|
-
height: 2.5rem;
|
|
96
|
-
vertical-align: middle;
|
|
97
|
-
--iconFillColor: #333;
|
|
98
|
-
cursor: pointer;
|
|
99
|
-
}
|
|
100
|
-
.opened {
|
|
101
|
-
display: flex;
|
|
102
|
-
}
|
|
103
|
-
.closed {
|
|
104
|
-
display: none;
|
|
105
|
-
}
|
|
106
|
-
a {
|
|
107
|
-
text-decoration: none;
|
|
108
|
-
}
|
|
109
|
-
`;
|
|
110
|
-
|
|
111
|
-
return [buttonBaseStyle, dialogStyle];
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
customElements.define('show-dialog', showDialog);
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
import ActionsHandlerService from './actions-handler/actions-handler-service.js';
|
|
4
|
-
import { URLHelper } from '../config/url-helper.js';
|
|
5
|
-
|
|
6
|
-
import '../../components/show-dialog.js';
|
|
7
|
-
|
|
8
|
-
export default class ArchiveOrgTokenPoller {
|
|
9
|
-
constructor(identifier, lendingStatus) {
|
|
10
|
-
this.identifier = identifier;
|
|
11
|
-
this.lendingStatus = lendingStatus;
|
|
12
|
-
this.pollingDelay = 6000; // 60000 ms = 1 min
|
|
13
|
-
this.tokenInterval = null;
|
|
14
|
-
this.showDialog = document
|
|
15
|
-
.querySelector('ia-book-actions')
|
|
16
|
-
.shadowRoot.querySelector('show-dialog');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
init() {
|
|
20
|
-
console.log('ArchiveOrgTokenPoller started...');
|
|
21
|
-
// Do an initial token, then set an interval
|
|
22
|
-
this.tokenInterval = setInterval(() => {
|
|
23
|
-
this.updateToken();
|
|
24
|
-
}, this.pollingDelay);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
updateToken() {
|
|
28
|
-
ActionsHandlerService({
|
|
29
|
-
identifier: this.identifier,
|
|
30
|
-
action: 'create_token',
|
|
31
|
-
// callback: (xhrResponse) => {
|
|
32
|
-
// console.log('xhrResponse', xhrResponse);
|
|
33
|
-
// if (xhrResponse.status === true) {
|
|
34
|
-
// this.hideErrorDialog(); // remove overlay and message box...
|
|
35
|
-
// // this.showErrorDialog(xhrResponse);
|
|
36
|
-
// } else {
|
|
37
|
-
// this.showErrorDialog(xhrResponse);
|
|
38
|
-
// }
|
|
39
|
-
// },
|
|
40
|
-
loader: false,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
hideErrorDialog() {
|
|
45
|
-
this.showDialog.dialogVisible = false;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
showErrorDialog(xhrResponse) {
|
|
49
|
-
let title = 'Connection error';
|
|
50
|
-
let body = 'Please check internet connection.';
|
|
51
|
-
let actions = [
|
|
52
|
-
{
|
|
53
|
-
text: 'Okay',
|
|
54
|
-
callback: () => {
|
|
55
|
-
weAreBack();
|
|
56
|
-
this.updateToken();
|
|
57
|
-
},
|
|
58
|
-
className: 'ia-button primary',
|
|
59
|
-
},
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
// Specific error
|
|
63
|
-
const data = JSON.parse(xhrResponse);
|
|
64
|
-
if (data.error) {
|
|
65
|
-
title = 'Sorry!';
|
|
66
|
-
body = data.error;
|
|
67
|
-
// Only go back to item button on error
|
|
68
|
-
actions = [
|
|
69
|
-
{
|
|
70
|
-
text: 'Back to item details',
|
|
71
|
-
callback: () => {
|
|
72
|
-
URLHelper.goToUrl(this.lendingStatus.bookUrl);
|
|
73
|
-
},
|
|
74
|
-
className: 'ia-button primary',
|
|
75
|
-
},
|
|
76
|
-
];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const showDialog = document
|
|
80
|
-
.querySelector('ia-book-actions')
|
|
81
|
-
.shadowRoot.querySelector('show-dialog');
|
|
82
|
-
|
|
83
|
-
showDialog.opened = true;
|
|
84
|
-
showDialog.title = title;
|
|
85
|
-
showDialog.body = body;
|
|
86
|
-
showDialog.actions = actions;
|
|
87
|
-
}
|
|
88
|
-
}
|