@internetarchive/ia-book-actions 0.0.5-4 → 0.0.5-5

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.
@@ -0,0 +1,4 @@
1
+ <script>
2
+ return { error: 'ss' }
3
+
4
+ </script>
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", Helvetica, Arial, sans-serif;
15
+ font-family: "Helvetica Neue", Arial, Verdana, sans-serif;
16
16
  }
17
17
  #demo {
18
18
  height: 50px;
@@ -71,10 +71,21 @@
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
+ }
74
84
  </style>
75
85
  </head>
76
86
 
77
87
  <body>
88
+
78
89
  <ia-book-actions></ia-book-actions>
79
90
 
80
91
  <script type="module">
@@ -95,11 +106,23 @@
95
106
  // set defaultLendingStatus for unavailable (without borrowables) book
96
107
  iaBookActions.userid = '';
97
108
  iaBookActions.identifier = identifier;
98
- iaBookActions.lendingStatus = defaultLendingStatus;
109
+ iaBookActions.bookTitle = 'Contemporary Black biography. Volume 39 : profiles from the interContemporary Black biography. Volume 39';
110
+ iaBookActions.lendingStatus = canBrowseAndBorrow;
99
111
  iaBookActions.bwbPurchaseUrl = '';
112
+ iaBookActions.barType = '';
100
113
 
101
114
  let lendingStatus1 = iaBookActions.lendingStatus;
102
115
 
116
+ document.querySelectorAll('.titleBar input[type=checkbox]').forEach((item) => {
117
+ item.addEventListener('click', (e) => {
118
+ if (e.target.checked) {
119
+ iaBookActions.barType = 'title';
120
+ } else {
121
+ iaBookActions.barType = 'action';
122
+ }
123
+ });
124
+ });
125
+
103
126
  document.querySelectorAll('.userState input[type=checkbox]').forEach((item) => {
104
127
  item.addEventListener('click', (e) => {
105
128
  if (e.target.checked) {
@@ -191,10 +214,20 @@
191
214
  })
192
215
  });
193
216
  </script>
194
-
195
217
  <div>
196
218
  <fieldset>
197
- <legend>Dev try for lending banner</legend>
219
+ <legend>Dev testing for book title bar</legend>
220
+ <table class="initial">
221
+ <tr>
222
+ <td class="titleBar">
223
+ <label><input type="checkbox" name="title" value="title" />Title Bar</label>
224
+ </td>
225
+ </tr>
226
+ </table>
227
+ </fieldset>
228
+
229
+ <fieldset>
230
+ <legend>Dev testing for book action bar</legend>
198
231
  <table class="initial">
199
232
  <tr>
200
233
  <td class="userState">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.5-4",
3
+ "version": "0.0.5-5",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -21,6 +21,7 @@
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",
24
25
  "@internetarchive/shared-resize-observer": "^0.0.1",
25
26
  "lit-element": "^2.4.0",
26
27
  "lit-html": "^1.3.0"
@@ -0,0 +1,32 @@
1
+ import { html } from 'lit-element';
2
+
3
+ export const archiveLogo = html`
4
+ <svg
5
+ class="ia-logo"
6
+ width="26"
7
+ height="26"
8
+ viewBox="0 0 27 30"
9
+ xmlns="http://www.w3.org/2000/svg"
10
+ aria-labelledby="logoTitleID logoDescID"
11
+ >
12
+ <title id="logoTitleID">Internet Archive logo</title>
13
+ <desc id="logoDescID">
14
+ A line drawing of the Internet Archive headquarters building façade.
15
+ </desc>
16
+ <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
17
+ <mask id="mask-2" fill="white">
18
+ <path
19
+ d="M26.6666667,28.6046512 L26.6666667,30 L0,30 L0.000283687943,28.6046512 L26.6666667,28.6046512 Z M25.6140351,26.5116279 L25.6140351,28.255814 L1.05263158,28.255814 L1.05263158,26.5116279 L25.6140351,26.5116279 Z M3.62469203,7.6744186 L3.91746909,7.82153285 L4.0639977,10.1739544 L4.21052632,13.9963932 L4.21052632,17.6725617 L4.0639977,22.255044 L4.03962296,25.3421929 L3.62469203,25.4651163 L2.16024641,25.4651163 L1.72094074,25.3421929 L1.55031755,22.255044 L1.40350877,17.6970339 L1.40350877,14.0211467 L1.55031755,10.1739544 L1.68423854,7.80887484 L1.98962322,7.6744186 L3.62469203,7.6744186 Z M24.6774869,7.6744186 L24.9706026,7.82153285 L25.1168803,10.1739544 L25.2631579,13.9963932 L25.2631579,17.6725617 L25.1168803,22.255044 L25.0927809,25.3421929 L24.6774869,25.4651163 L23.2130291,25.4651163 L22.7736357,25.3421929 L22.602418,22.255044 L22.4561404,17.6970339 L22.4561404,14.0211467 L22.602418,10.1739544 L22.7369262,7.80887484 L23.0420916,7.6744186 L24.6774869,7.6744186 Z M9.94042303,7.6744186 L10.2332293,7.82153285 L10.3797725,10.1739544 L10.5263158,13.9963932 L10.5263158,17.6725617 L10.3797725,22.255044 L10.3556756,25.3421929 L9.94042303,25.4651163 L8.47583122,25.4651163 L8.0362015,25.3421929 L7.86556129,22.255044 L7.71929825,17.6970339 L7.71929825,14.0211467 L7.86556129,10.1739544 L8.00005604,7.80887484 L8.30491081,7.6744186 L9.94042303,7.6744186 Z M18.0105985,7.6744186 L18.3034047,7.82153285 L18.449948,10.1739544 L18.5964912,13.9963932 L18.5964912,17.6725617 L18.449948,22.255044 L18.425851,25.3421929 L18.0105985,25.4651163 L16.5460067,25.4651163 L16.1066571,25.3421929 L15.9357367,22.255044 L15.7894737,17.6970339 L15.7894737,14.0211467 L15.9357367,10.1739544 L16.0702315,7.80887484 L16.3753664,7.6744186 L18.0105985,7.6744186 Z M25.6140351,4.53488372 L25.6140351,6.97674419 L1.05263158,6.97674419 L1.05263158,4.53488372 L25.6140351,4.53488372 Z M13.0806755,0 L25.9649123,2.93331338 L25.4484139,3.8372093 L0.771925248,3.8372093 L0,3.1041615 L13.0806755,0 Z"
20
+ id="path-1"
21
+ ></path>
22
+ </mask>
23
+ <use fill="#FFFFFF" xlink:href="#path-1"></use>
24
+ <g mask="url(#mask-2)" fill="#FFFFFF">
25
+ <path
26
+ d="M0,0 L26.6666667,0 L26.6666667,30 L0,30 L0,0 Z"
27
+ id="swatch"
28
+ ></path>
29
+ </g>
30
+ </g>
31
+ </svg>
32
+ `;
@@ -3,6 +3,8 @@ import { css } from 'lit-element';
3
3
  export default css`
4
4
  :host {
5
5
  display: inline-flex;
6
+ height: 3.5rem;
7
+ padding: 1rem 0;
6
8
  }
7
9
  .action-buttons {
8
10
  display: inline-flex;
@@ -0,0 +1,93 @@
1
+ import { html, css } from 'lit-element';
2
+
3
+ import {
4
+ analyticsCategories,
5
+ analyticsActions,
6
+ } from '../core/config/analytics-event-and-category.js';
7
+ import ActionsHandler from '../core/services/actions-handler/actions-handler.js';
8
+
9
+ import { archiveLogo } from '../assets/data/archive-logo.js';
10
+
11
+ export class BookTitleBar extends ActionsHandler {
12
+ static get properties() {
13
+ return {
14
+ identifier: { type: String },
15
+ bookTitle: { type: String },
16
+ };
17
+ }
18
+
19
+ constructor() {
20
+ super();
21
+ this.identifier = '';
22
+ this.bookTitle = '';
23
+ this.analyticsCategories = analyticsCategories;
24
+ this.analyticsActions = analyticsActions;
25
+ }
26
+
27
+ /**
28
+ * Click handler to emit custom event on action click
29
+ */
30
+ clickHandler() {
31
+ const { category, action } = {
32
+ category: this.analyticsCategories.bookReaderHeader,
33
+ action: this.analyticsActions.titleBar,
34
+ };
35
+
36
+ this.dispatchEvent(
37
+ new CustomEvent('bookTitleBar', {
38
+ detail: {
39
+ event: { category, action },
40
+ },
41
+ })
42
+ );
43
+ }
44
+
45
+ render() {
46
+ return html`
47
+ <a
48
+ class="embed-link"
49
+ @click=${() => {
50
+ this.clickHandler();
51
+ }}
52
+ href="/details/${this.identifier}"
53
+ >
54
+ <span>${archiveLogo}</span>
55
+ <span class="title">${this.bookTitle}</span>
56
+ </a>
57
+ `;
58
+ }
59
+
60
+ static get styles() {
61
+ return css`
62
+ :host {
63
+ padding: 0 10px;
64
+ height: 3.4rem;
65
+ display: flex;
66
+ }
67
+ .embed-link {
68
+ display: inline-flex;
69
+ align-items: center;
70
+ text-decoration: none;
71
+ color: var(--primaryTextColor, #fff);
72
+ font-size: 1.4rem;
73
+ }
74
+ .embed-link .title {
75
+ display: -webkit-box;
76
+ -webkit-box-orient: vertical;
77
+ -webkit-line-clamp: 2;
78
+ overflow: hidden;
79
+ text-align: left;
80
+ line-height: initial;
81
+ }
82
+ .embed-link svg {
83
+ margin-right: 0.5rem;
84
+ display: block;
85
+ }
86
+ .embed-link:hover {
87
+ text-decoration: underline;
88
+ }
89
+ `;
90
+ }
91
+ }
92
+
93
+ window.customElements.define('book-title-bar', BookTitleBar);
@@ -0,0 +1,115 @@
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);
@@ -21,4 +21,5 @@ export const analyticsActions = {
21
21
  purchase: 'BWBPurchase',
22
22
  unavailable: 'Book-Unavailable',
23
23
  printDisability: 'Print-Disability',
24
+ titleBar: 'Book-Title-Bar',
24
25
  };
@@ -11,6 +11,7 @@ export default function ActionsHandlerService(options) {
11
11
  data: {},
12
12
  success() {},
13
13
  error: null,
14
+ callback() {},
14
15
  loader: true,
15
16
  type: 'POST',
16
17
  ...options,
@@ -22,7 +23,7 @@ export default function ActionsHandlerService(options) {
22
23
 
23
24
  let baseHost = '';
24
25
  if (window.location.pathname === '/demo/') {
25
- baseHost = `/demo/`;
26
+ baseHost = `/demo/`; // http://localhost:8000/demo/error.html
26
27
  } else {
27
28
  baseHost = `/services/loans/loan`;
28
29
  }
@@ -36,15 +37,90 @@ export default function ActionsHandlerService(options) {
36
37
  body: formData,
37
38
  })
38
39
  .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
+
39
55
  if (response.status === 200) {
40
56
  option.success.call();
41
57
  }
42
58
  })
43
59
  .catch(error => {
44
- console.log(error);
60
+ console.log('error', error);
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
+ }
45
72
  });
46
73
  }
47
74
 
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
+
48
124
  function showActionButtonLoader() {
49
125
  const collapsibleElement = document
50
126
  .querySelector('ia-book-actions')
@@ -82,6 +82,11 @@ export default class ActionsHandler extends LitElement {
82
82
  const { category, action } = detail.event;
83
83
  this.sendEvent(category, action);
84
84
  });
85
+
86
+ this.addEventListener('bookTitleBar', ({ detail }) => {
87
+ const { category, action } = detail.event;
88
+ this.sendEvent(category, action);
89
+ });
85
90
  }
86
91
 
87
92
  handleBrowseIt() {
@@ -0,0 +1,88 @@
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
+ }
@@ -2,7 +2,6 @@
2
2
  /* eslint no-console: "off" */
3
3
  /* eslint no-nested-ternary: "off" */
4
4
  /* eslint-disable */
5
- import { nothing } from 'lit-html';
6
5
  import { URLHelper } from '../config/url-helper.js';
7
6
  import {
8
7
  analyticsCategories,
@@ -1,13 +1,17 @@
1
- /* eslint-disable camelcase */
1
+ /* eslint-disable */
2
2
  import { html, css, LitElement } from 'lit-element';
3
3
 
4
4
  import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
5
5
 
6
6
  import './components/collapsible-action-group.js';
7
+ import './components/book-title-bar.js';
7
8
  import './components/text-group.js';
8
9
  import './components/info-icon.js';
10
+ import './components/show-dialog.js';
9
11
 
10
12
  import GetLendingActions from './core/services/get-lending-actions.js';
13
+ import ArchiveOrgTokenPoller from './core/services/archive-token-poller.js';
14
+
11
15
  import { mobileContainerWidth } from './core/config/constants.js';
12
16
 
13
17
  export default class IABookActions extends LitElement {
@@ -15,10 +19,13 @@ export default class IABookActions extends LitElement {
15
19
  return {
16
20
  userid: { type: String },
17
21
  identifier: { type: String },
22
+ bookTitle: { type: String },
18
23
  lendingStatus: { type: Object },
19
24
  width: { type: Number },
20
25
  bwbPurchaseUrl: { type: String },
26
+ barType: { type: String },
21
27
  sharedObserver: { attribute: false },
28
+ dialogVisible: { type: Boolean },
22
29
  };
23
30
  }
24
31
 
@@ -26,15 +33,18 @@ export default class IABookActions extends LitElement {
26
33
  super();
27
34
  this.userid = '';
28
35
  this.identifier = '';
36
+ this.bookTitle = '';
29
37
  this.lendingStatus = {};
38
+ this.width = 0;
39
+ this.bwbPurchaseUrl = '';
40
+ this.barType = 'action'; // 'title'|'action'
41
+ this.sharedObserver = undefined;
30
42
  this.primaryActions = [];
31
43
  this.primaryTitle = '';
32
44
  this.primaryColor = 'primary';
33
45
  this.secondaryActions = [];
34
- this.width = 0;
35
- this.bwbPurchaseUrl = '';
36
46
  this.lendingOptions = {};
37
- this.sharedObserver = undefined;
47
+ this.dialogVisible = true;
38
48
  }
39
49
 
40
50
  disconnectedCallback() {
@@ -140,24 +150,59 @@ export default class IABookActions extends LitElement {
140
150
  !this.lendingStatus.browseHasExpired
141
151
  ) {
142
152
  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;
143
161
  }
144
162
  }
145
163
 
146
164
  render() {
147
165
  return html`
148
166
  <section class="lending-wrapper">
149
- <collapsible-action-group
150
- .userid=${this.userid}
151
- .identifier=${this.identifier}
152
- .primaryColor=${this.primaryColor}
153
- .primaryActions=${this.primaryActions}
154
- .secondaryActions=${this.secondaryActions}
155
- .width=${this.width}
156
- .hasAdminAccess=${this.hasAdminAccess}
157
- >
158
- </collapsible-action-group>
159
- ${this.textGroupTemplate} ${this.infoIconTemplate}
167
+ ${this.barType === 'title' ? this.bookTitleBar : this.bookActionBar}
160
168
  </section>
169
+
170
+ <show-dialog
171
+ ?opened="${this.dialogVisible}"
172
+ @dialog.close="${() => this.closeDialog(this)}"
173
+ ></show-dialog>
174
+ `;
175
+ }
176
+
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
+ get bookTitleBar() {
187
+ return html`<book-title-bar
188
+ .identifier=${this.identifier}
189
+ .bookTitle=${this.bookTitle}
190
+ ></book-title-bar>`;
191
+ }
192
+
193
+ get bookActionBar() {
194
+ return html`
195
+ <collapsible-action-group
196
+ .userid=${this.userid}
197
+ .identifier=${this.identifier}
198
+ .primaryColor=${this.primaryColor}
199
+ .primaryActions=${this.primaryActions}
200
+ .secondaryActions=${this.secondaryActions}
201
+ .width=${this.width}
202
+ .hasAdminAccess=${this.hasAdminAccess}
203
+ >
204
+ </collapsible-action-group>
205
+ ${this.textGroupTemplate} ${this.infoIconTemplate}
161
206
  `;
162
207
  }
163
208
 
@@ -176,7 +221,7 @@ export default class IABookActions extends LitElement {
176
221
  get textGroupTemplate() {
177
222
  return html`<text-group
178
223
  textClass=${this.textClass}
179
- texts="${this.primaryTitle}"
224
+ texts=${this.primaryTitle}
180
225
  >
181
226
  </text-group>`;
182
227
  }
@@ -195,7 +240,6 @@ export default class IABookActions extends LitElement {
195
240
  .lending-wrapper {
196
241
  width: 100%;
197
242
  margin: 0 auto;
198
- padding: 10px 0;
199
243
  display: inline-flex;
200
244
  align-items: center;
201
245
  justify-content: center;
@@ -0,0 +1,39 @@
1
+ import { html, fixture, expect, oneEvent } from '@open-wc/testing';
2
+ import '../../src/components/book-title-bar.js';
3
+
4
+ const container = ({ identifier, bookTitle } = {}) =>
5
+ html`<book-title-bar
6
+ .identifier=${identifier}
7
+ .bookTitle=${bookTitle}
8
+ ></book-title-bar>`;
9
+
10
+ describe('<book-title-bar>', () => {
11
+ it('check inner texts of title bar', async () => {
12
+ const el = await fixture(
13
+ container({
14
+ identifier: 'goody',
15
+ bookTitle: 'this is test booktitle',
16
+ })
17
+ );
18
+ const link = el.shadowRoot.querySelector('a');
19
+ expect(link.innerText).to.equal('this is test booktitle');
20
+ expect(link.getAttribute('href')).to.equal('/details/goody');
21
+ });
22
+
23
+ it('check if event if firing on valid analytics category action', async () => {
24
+ const el = await fixture(
25
+ container({
26
+ identifier: 'goody',
27
+ bookTitle: 'this is test booktitle',
28
+ })
29
+ );
30
+
31
+ const clickButton = () =>
32
+ el.shadowRoot.querySelector('a').dispatchEvent(new Event('click'));
33
+ setTimeout(clickButton);
34
+
35
+ const { detail } = await oneEvent(el, 'bookTitleBar');
36
+ expect(detail.event.category).to.equal('BookReader-Header');
37
+ expect(detail.event.action).to.equal('Book-Title-Bar');
38
+ });
39
+ });
@@ -36,7 +36,7 @@ describe('Get Lending Actions', () => {
36
36
  );
37
37
  const actions = lendingOptions.getCurrentLendingActions();
38
38
 
39
- expect(actions.primaryActions.length).to.equal(1);
39
+ expect(actions.primaryActions.length).to.equal(2);
40
40
  expect(actions.primaryTitle).to.equal(
41
41
  'This book can be borrowed for 14 days.'
42
42
  );
@@ -127,7 +127,7 @@ describe('Borrow status actions', () => {
127
127
  expect(el.primaryTitle).to.equal(
128
128
  'Renewable every hour, pending availability.'
129
129
  );
130
- expect(el.primaryActions.length).to.equal(1);
130
+ expect(el.primaryActions.length).to.equal(2);
131
131
  expect(el.primaryActions[0].text).to.equal('Log In and Borrow');
132
132
  expect(el.primaryActions[0].text).to.equal(expectedPrimaryActions[0].text);
133
133
  });