@internetarchive/ia-book-actions 0.0.29-alpha15 → 0.0.29-alpha17

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 CHANGED
@@ -288,8 +288,6 @@
288
288
  })
289
289
  );
290
290
  })
291
-
292
-
293
291
  </script>
294
292
 
295
293
  <div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.29-alpha15",
3
+ "version": "0.0.29-alpha17",
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": [
@@ -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() {
@@ -120,7 +124,6 @@ export default class IABookActions extends LitElement {
120
124
  this.executeLoanRenew();
121
125
  }
122
126
 
123
- console.log(this.loanRenewResult)
124
127
  return nothing;
125
128
  });
126
129
 
@@ -149,6 +152,16 @@ export default class IABookActions extends LitElement {
149
152
  return nothing;
150
153
  }
151
154
 
155
+ showToastMessage() {
156
+ let toastManager = document.querySelector('toast-template');
157
+ if (!toastManager) {
158
+ toastManager = document.createElement('toast-template');
159
+ }
160
+ document.body.appendChild(toastManager);
161
+
162
+ toastManager.config = new ToastConfig(this.loanRenewResult);
163
+ }
164
+
152
165
  async browseHasExpired() {
153
166
  const currStatus = { ...this.lendingStatus, browsingExpired: true };
154
167
  this.lendingStatus = currStatus;
@@ -324,15 +337,6 @@ export default class IABookActions extends LitElement {
324
337
  : nothing;
325
338
  }
326
339
 
327
- get toastMessageTemplate() {
328
- return html`
329
- <toast-message
330
- .texts=${this.loanRenewResult.texts}
331
- ?dismisOnClick=${Boolean(true)}
332
- ></toast-message>
333
- `;
334
- }
335
-
336
340
  get bookActionBar() {
337
341
  return html`
338
342
  <collapsible-action-group
@@ -354,7 +358,7 @@ export default class IABookActions extends LitElement {
354
358
  >
355
359
  </collapsible-action-group>
356
360
  ${this.textGroupTemplate} ${this.infoIconTemplate}
357
- ${this.timerCountdownTemplate} ${this.toastMessageTemplate}
361
+ ${this.timerCountdownTemplate}
358
362
  `;
359
363
  }
360
364
 
@@ -523,8 +527,10 @@ export default class IABookActions extends LitElement {
523
527
  flex-wrap: wrap;
524
528
  }
525
529
 
526
- toast-message {
527
- --messageHeightFromTop: 17%;
530
+ toast-template {
531
+ --toastHeightFromTop: 50%;
532
+ --toastBGColor: #333333;
533
+ --toastFontColor: #ffffff;
528
534
  }
529
535
  `;
530
536
  }
@@ -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);