@internetarchive/ia-book-actions 0.0.29-alpha16 → 0.0.29-alpha18
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 +0 -2
- package/package.json +3 -3
- package/src/ia-book-actions.js +23 -15
- package/src/components/toast-message.js +0 -76
package/demo/index.html
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@internetarchive/ia-book-actions",
|
|
3
|
-
"version": "0.0.29-
|
|
3
|
+
"version": "0.0.29-alpha18",
|
|
4
4
|
"description": "Bookreader actions for borrowable book",
|
|
5
5
|
"author": "Internet Archive",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"@internetarchive/local-cache": "^0.2.0",
|
|
23
23
|
"@internetarchive/modal-manager": "^0.2.1",
|
|
24
24
|
"@internetarchive/shared-resize-observer": "^0.2.0",
|
|
25
|
+
"@internetarchive/toast-manager": "0.0.1-alpha1",
|
|
25
26
|
"lit": "^2.2.1"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
@@ -59,8 +60,7 @@
|
|
|
59
60
|
"arrowParens": "avoid"
|
|
60
61
|
},
|
|
61
62
|
"husky": {
|
|
62
|
-
"hooks": {
|
|
63
|
-
}
|
|
63
|
+
"hooks": {}
|
|
64
64
|
},
|
|
65
65
|
"lint-staged": {
|
|
66
66
|
"*.js": [
|
package/src/ia-book-actions.js
CHANGED
|
@@ -3,6 +3,7 @@ import { html, css, LitElement, nothing } from 'lit';
|
|
|
3
3
|
|
|
4
4
|
import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
|
|
5
5
|
import { ModalConfig } from '@internetarchive/modal-manager';
|
|
6
|
+
import { ToastConfig } from '@internetarchive/toast-manager';
|
|
6
7
|
import { LocalCache } from '@internetarchive/local-cache';
|
|
7
8
|
|
|
8
9
|
import './components/collapsible-action-group.js';
|
|
@@ -10,7 +11,6 @@ import './components/book-title-bar.js';
|
|
|
10
11
|
import './components/text-group.js';
|
|
11
12
|
import './components/info-icon.js';
|
|
12
13
|
import './components/timer-countdown.js';
|
|
13
|
-
import './components/toast-message.js';
|
|
14
14
|
|
|
15
15
|
import { mobileContainerWidth } from './core/config/constants.js';
|
|
16
16
|
import { GetLendingActions } from './core/services/get-lending-actions.js';
|
|
@@ -109,6 +109,10 @@ export default class IABookActions extends LitElement {
|
|
|
109
109
|
this.disconnectResizeObserver();
|
|
110
110
|
this.setupResizeObserver();
|
|
111
111
|
}
|
|
112
|
+
|
|
113
|
+
if (changed.has('loanRenewResult')) {
|
|
114
|
+
this.showToastMessage();
|
|
115
|
+
}
|
|
112
116
|
}
|
|
113
117
|
|
|
114
118
|
bindLoanRenewEvents() {
|
|
@@ -148,19 +152,30 @@ export default class IABookActions extends LitElement {
|
|
|
148
152
|
return nothing;
|
|
149
153
|
}
|
|
150
154
|
|
|
155
|
+
async showToastMessage() {
|
|
156
|
+
let toastManager = document.querySelector('toast-template');
|
|
157
|
+
if (!toastManager) {
|
|
158
|
+
toastManager = document.createElement('toast-template');
|
|
159
|
+
}
|
|
160
|
+
await document.body.appendChild(toastManager);
|
|
161
|
+
|
|
162
|
+
toastManager.config = new ToastConfig(this.loanRenewResult);
|
|
163
|
+
}
|
|
164
|
+
|
|
151
165
|
async browseHasExpired() {
|
|
152
166
|
const currStatus = { ...this.lendingStatus, browsingExpired: true };
|
|
153
167
|
this.lendingStatus = currStatus;
|
|
154
|
-
this.loanRenewResult.renewNow = false;
|
|
155
168
|
|
|
156
169
|
// remove respected key:value
|
|
157
170
|
await this.localCache.delete(`${this.identifier}-loanTime`);
|
|
158
171
|
await this.localCache.delete(`${this.identifier}-pageChangedTime`);
|
|
159
172
|
|
|
160
173
|
// show message after browsed book is expired.
|
|
174
|
+
this.loanRenewResult.renewNow = false;
|
|
161
175
|
this.loanRenewResult.texts =
|
|
162
176
|
'This book has been auto-returned due to inactivity.';
|
|
163
|
-
|
|
177
|
+
|
|
178
|
+
this.showToastMessage();
|
|
164
179
|
}
|
|
165
180
|
|
|
166
181
|
async browseHasRenew() {
|
|
@@ -323,15 +338,6 @@ export default class IABookActions extends LitElement {
|
|
|
323
338
|
: nothing;
|
|
324
339
|
}
|
|
325
340
|
|
|
326
|
-
get toastMessageTemplate() {
|
|
327
|
-
return html`
|
|
328
|
-
<toast-message
|
|
329
|
-
.texts=${this.loanRenewResult.texts}
|
|
330
|
-
?dismisOnClick=${Boolean(true)}
|
|
331
|
-
></toast-message>
|
|
332
|
-
`;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
341
|
get bookActionBar() {
|
|
336
342
|
return html`
|
|
337
343
|
<collapsible-action-group
|
|
@@ -353,7 +359,7 @@ export default class IABookActions extends LitElement {
|
|
|
353
359
|
>
|
|
354
360
|
</collapsible-action-group>
|
|
355
361
|
${this.textGroupTemplate} ${this.infoIconTemplate}
|
|
356
|
-
${this.timerCountdownTemplate}
|
|
362
|
+
${this.timerCountdownTemplate}
|
|
357
363
|
`;
|
|
358
364
|
}
|
|
359
365
|
|
|
@@ -522,8 +528,10 @@ export default class IABookActions extends LitElement {
|
|
|
522
528
|
flex-wrap: wrap;
|
|
523
529
|
}
|
|
524
530
|
|
|
525
|
-
toast-
|
|
526
|
-
--
|
|
531
|
+
toast-template {
|
|
532
|
+
--toastHeightFromTop: 15%;
|
|
533
|
+
--toastBGColor: #333333;
|
|
534
|
+
--toastFontColor: #ffffff;
|
|
527
535
|
}
|
|
528
536
|
`;
|
|
529
537
|
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { html, css, LitElement, nothing } from 'lit';
|
|
2
|
-
|
|
3
|
-
export class ToastMessage extends LitElement {
|
|
4
|
-
static get properties() {
|
|
5
|
-
return {
|
|
6
|
-
texts: { type: String },
|
|
7
|
-
dismisOnClick: { type: Boolean },
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
constructor() {
|
|
12
|
-
super();
|
|
13
|
-
this.texts = null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
render() {
|
|
17
|
-
return this.texts
|
|
18
|
-
? html`
|
|
19
|
-
<span
|
|
20
|
-
class="toast-message fade-in"
|
|
21
|
-
title="Click/tap to close"
|
|
22
|
-
@click=${() => {
|
|
23
|
-
this.dismisOnClick ? (this.texts = null) : nothing;
|
|
24
|
-
}}
|
|
25
|
-
>${this.texts}</span
|
|
26
|
-
>
|
|
27
|
-
`
|
|
28
|
-
: nothing;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
static get styles() {
|
|
32
|
-
const heightFromTop = css`var(--messageHeightFromTop, 15%)`;
|
|
33
|
-
|
|
34
|
-
return css`
|
|
35
|
-
:host {
|
|
36
|
-
display: inline-block;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
.toast-message {
|
|
40
|
-
z-index: 2;
|
|
41
|
-
position: absolute;
|
|
42
|
-
top: ${heightFromTop};
|
|
43
|
-
font-size: 1.4rem;
|
|
44
|
-
font-family: 'Helvetica Neue';
|
|
45
|
-
color: #fff;
|
|
46
|
-
left: 50%;
|
|
47
|
-
background: #333;
|
|
48
|
-
border: 1px solid #fff;
|
|
49
|
-
border-radius: 5px;
|
|
50
|
-
box-shadow: 1px 1px 2px;
|
|
51
|
-
padding: 10px;
|
|
52
|
-
width: fit-content;
|
|
53
|
-
transform: translate(-50%, -50%);
|
|
54
|
-
cursor: pointer;
|
|
55
|
-
animation: fadeIn 5s;
|
|
56
|
-
@keyframes fadeIn {
|
|
57
|
-
0% {
|
|
58
|
-
opacity: 0;
|
|
59
|
-
}
|
|
60
|
-
100% {
|
|
61
|
-
opacity: 1;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
.hidden {
|
|
67
|
-
display: none;
|
|
68
|
-
}
|
|
69
|
-
.visible {
|
|
70
|
-
display: inline-block;
|
|
71
|
-
}
|
|
72
|
-
`;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
window.customElements.define('toast-message', ToastMessage);
|