@internetarchive/ia-book-actions 0.0.29-alpha9 → 0.1.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/demo/index.html CHANGED
@@ -15,7 +15,7 @@
15
15
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
16
16
  }
17
17
  #demo {
18
- height: 50px;
18
+ height: 100px;
19
19
  }
20
20
  ia-book-actions {
21
21
  --white: #fff;
@@ -72,6 +72,10 @@
72
72
  margin: 2px;
73
73
  }
74
74
 
75
+ fieldset {
76
+ display: inline-grid;
77
+ }
78
+
75
79
  body.modal-manager-open {
76
80
  overflow: hidden;
77
81
  }
@@ -87,6 +91,7 @@
87
91
 
88
92
  <script type="module">
89
93
  /* eslint-disable */
94
+
90
95
  import '../src/ia-book-actions.js';
91
96
  import {
92
97
  defaultLendingStatus,
@@ -96,7 +101,7 @@
96
101
  import { LocalCache } from '@internetarchive/local-cache';
97
102
 
98
103
  const localCache = new LocalCache({
99
- namespace: '1HourLoanStorage',
104
+ namespace: 'loanRenew',
100
105
  defaultTTL: 1 * 60, // 1 minute
101
106
  });
102
107
 
@@ -104,10 +109,6 @@
104
109
  const identifier = 'naturalhistoryof00unse_4111';
105
110
  let bwbPurchaseUrl = 'https://www.betterworldbooks.com/product/detail/cambridge-ancient-hist-v04-0521044863';
106
111
 
107
- let iaBookActions = document.querySelector('ia-book-actions');
108
-
109
- // for debugging
110
- window.iaBookActions = iaBookActions;
111
112
 
112
113
  const modalConfig = new ModalConfig();
113
114
  modalConfig.headerColor = '#d9534f';
@@ -117,6 +118,8 @@
117
118
  }
118
119
 
119
120
  // set defaultLendingStatus for unavailable (without borrowables) book
121
+ let iaBookActions = document.querySelector('ia-book-actions');
122
+
120
123
  iaBookActions.userid = userid;
121
124
  iaBookActions.identifier = identifier;
122
125
  iaBookActions.bookTitle = 'Contemporary Black biography. Volume 39 : profiles from the interContemporary Black biography. Volume 39';
@@ -124,17 +127,18 @@
124
127
  iaBookActions.bwbPurchaseUrl = '';
125
128
  iaBookActions.modalConfig = modalConfig;
126
129
  iaBookActions.lendingBarPostInit = lendingBarPostInit;
127
- iaBookActions.tokenDelay = 2000; // 2 seconds
130
+ iaBookActions.tokenDelay = 2; // 2 seconds
128
131
  iaBookActions.returnUrl = 'https://openlibrary.org';
129
132
  iaBookActions.localCache = localCache;
130
- iaBookActions.autoRenewConfig = {
131
- totalTime: 60, // 60 second = 1 min
132
- autoCheckAt: 55, // totalTime - 10th minute
133
- FlippedInLast: 15, // within last 15 second/minute
134
- };
133
+
134
+ let loanTotalTime2Min = { loanTotalTime: 20, loanRenewAtLast: 15, pageChangedInLast: 15 };
135
+ let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 180, pageChangedInLast: 15 };
136
+ let loanTotalTime1Hour = { loanTotalTime: 3600, loanRenewAtLast: 600, pageChangedInLast: 900 };
137
+
138
+ iaBookActions.loanRenewTimeConfig = loanTotalTime2Min;
135
139
 
136
140
  let lendingStatus1 = iaBookActions.lendingStatus;
137
- let secondsLeftOnLoan = iaBookActions.autoRenewConfig.totalTime;
141
+ let secondsLeftOnLoan = iaBookActions.loanRenewTimeConfig.loanTotalTime;
138
142
 
139
143
  document.querySelectorAll('.titleBar input[type=checkbox]').forEach((item) => {
140
144
  item.addEventListener('click', (e) => {
@@ -146,21 +150,6 @@
146
150
  });
147
151
  });
148
152
 
149
- document.querySelectorAll('.autoRenew input[type=checkbox]').forEach((item) => {
150
- item.addEventListener('click', (e) => {
151
- if (e.target.checked) {
152
- iaBookActions.autoRenew = true;
153
- iaBookActions.resetTimerCountdown = true;
154
- lendingStatus1.secondsLeftOnLoan = secondsLeftOnLoan;
155
- } else {
156
- iaBookActions.autoRenew = false;
157
- }
158
-
159
- let lending = {...defaultLendingStatus, ...lendingStatus1};
160
- iaBookActions.lendingStatus = lending;
161
- });
162
- });
163
-
164
153
  document.querySelectorAll('.errorEnable input[type=checkbox]').forEach((item) => {
165
154
  if (window.location.href.indexOf('?error=true') !== -1) {
166
155
  item.checked = true;
@@ -226,10 +215,10 @@
226
215
  await localCache.set({
227
216
  key: `${identifier}-loanTime`,
228
217
  value: new Date(), // current time
229
- ttl: Number(iaBookActions.autoRenewConfig.totalTime),
230
- })
218
+ ttl: Number(iaBookActions.loanRenewTimeConfig.loanTotalTime),
219
+ });
231
220
 
232
- await localCache.delete(`${identifier}-pageFlipTime`);
221
+ await localCache.delete(`${identifier}-pageChangedTime`);
233
222
  } catch (error) {}
234
223
 
235
224
  } else if(e.target.value === 'browsingExpired') {
@@ -242,8 +231,11 @@
242
231
  lendingStatus1.user_has_browsed = false;
243
232
  }
244
233
 
245
- let lending = {...defaultLendingStatus, ...lendingStatus1};
246
- iaBookActions.lendingStatus = lending;
234
+ // wait for a while
235
+ setTimeout(() => {
236
+ let lending = {...defaultLendingStatus, ...lendingStatus1};
237
+ iaBookActions.lendingStatus = lending;
238
+ }, 10);
247
239
  });
248
240
  });
249
241
 
@@ -292,6 +284,17 @@
292
284
  iaBookActions.bwbPurchaseUrl = bwbPurchaseUrl;
293
285
  })
294
286
  });
287
+
288
+ document.querySelector('.pageChangedEvent').addEventListener('click', () => {
289
+ // dispatch event to say book page has flipped
290
+ document.querySelector('ia-book-actions').dispatchEvent(
291
+ new CustomEvent('BookReader:userAction', {
292
+ detail: {},
293
+ bubbles: true,
294
+ composed: true,
295
+ })
296
+ );
297
+ })
295
298
  </script>
296
299
 
297
300
  <div>
@@ -302,6 +305,9 @@
302
305
  <td class="titleBar">
303
306
  <label><input type="checkbox" name="title" value="title" />Title Bar</label>
304
307
  </td>
308
+ <td>
309
+ <button class="pageChangedEvent">Page Change Event</button>
310
+ </td>
305
311
  </tr>
306
312
  </table>
307
313
  </fieldset>
@@ -311,7 +317,6 @@
311
317
  <table class="initial">
312
318
  <tr colspan='5'>
313
319
  <td class="errorEnable"><label><input type="checkbox" name="errorEnable" value="errorEnable" />Do you want to see error response?</label></td>
314
- <td class="autoRenew"><label><input type="checkbox" name="autoRenew" value="autoRenew" />Do you want to auto-renew 1 hour</label></td>
315
320
  </tr>
316
321
  <tr>
317
322
  <td class="userState">
@@ -0,0 +1,146 @@
1
+ <!doctype html>
2
+ <html lang="en-GB">
3
+
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
7
+ <style>
8
+ html {
9
+ font-size: 10px;
10
+ /* This is to match petabox's base font size */
11
+ }
12
+ body {
13
+ margin: 0;
14
+ text-align: center;
15
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
16
+ }
17
+ #demo {
18
+ height: 50px;
19
+ }
20
+ ia-book-actions {
21
+ --white: #fff;
22
+ --black: #000;
23
+ --primaryBGColor: var(--black);
24
+ --secondaryBGColor: #222;
25
+ --tertiaryBGColor: #333;
26
+ --primaryTextColor: var(--white);
27
+ --primaryCTAFill: #194880;
28
+ --primaryCTABorder: #c5d1df;
29
+ --secondaryCTAFill: #333;
30
+ --secondaryCTABorder: #999;
31
+ --secondaryCTAFillRGB: 51, 51, 51;
32
+ --primaryErrorCTAFill: #e51c26;
33
+ --primaryErrorCTABorder: #f8c6c8;
34
+ --primaryCTAFillRGB: 25, 72, 128;
35
+ --primaryErrorCTAFillRGB: 229, 28, 38;
36
+ --primaryDisableCTAFill: #767676;
37
+ }
38
+
39
+ fieldset {
40
+ width: fit-content;
41
+ margin-top: 50px;
42
+ }
43
+ fieldset legend {
44
+ text-align: left;
45
+ font-size: 12px;
46
+ }
47
+ td {
48
+ color: white;
49
+ font-size: 14px;
50
+ border-radius: 5%;
51
+ display: table-cell;
52
+ text-align: initial;
53
+ margin: 5px 0;
54
+ width: max-content;
55
+ display: block;
56
+ }
57
+ label {
58
+ padding: 10px;
59
+ display: block;
60
+ cursor: pointer;
61
+ margin: 2px;
62
+ background: #4e545a;
63
+ border-radius: 10px;
64
+ }
65
+ input[type="radio"], input[type="checkbox"] {
66
+ margin-top: 0;
67
+ vertical-align: middle;
68
+ }
69
+
70
+ .initial td {
71
+ float: left;
72
+ margin: 2px;
73
+ }
74
+
75
+ body.modal-manager-open {
76
+ overflow: hidden;
77
+ }
78
+
79
+ modal-manager[mode='closed'] {
80
+ display: none;
81
+ }
82
+ </style>
83
+ </head>
84
+
85
+ <body>
86
+ <ia-bookreader class="focus-on-child-only" signedin="" fullscreen="">
87
+ <div slot="header">
88
+ <ia-book-actions></ia-book-actions>
89
+ </div>
90
+ <div slot="main">
91
+ <div id="BookReader"></div>
92
+ </div>
93
+ </ia-bookreader>
94
+
95
+
96
+ <script type="module">
97
+ /* eslint-disable */
98
+ import '@internetarchive/bookreader';
99
+ import '@internetarchive/bookreader/BookReader/jquery-1.10.1.js';
100
+ import '@internetarchive/bookreader/BookReader/BookReader.js';
101
+ import '../src/ia-book-actions.js';
102
+ import {
103
+ defaultLendingStatus,
104
+ canBrowseAndBorrow,
105
+ } from '../src/assets/data/lending-get-status-service.js';
106
+ import { ModalConfig } from '@internetarchive/modal-manager';
107
+
108
+ const userid = '@neeraj-archive';
109
+ const identifier = 'naturalhistoryof00unse_4111';
110
+ let bwbPurchaseUrl = 'https://www.betterworldbooks.com/product/detail/cambridge-ancient-hist-v04-0521044863';
111
+
112
+ let iaBookActions = document.querySelector('ia-book-actions');
113
+
114
+ // for debugging
115
+ window.iaBookActions = iaBookActions;
116
+
117
+ const modalConfig = new ModalConfig();
118
+ modalConfig.headerColor = '#d9534f';
119
+
120
+ let lendingBarPostInit = function lendingBarPostInit() {
121
+ setTimeout(function() {
122
+ console.log('executed', 'br.init()');
123
+ }, 100);
124
+ }
125
+
126
+ // set defaultLendingStatus for unavailable (without borrowables) book
127
+ iaBookActions.userid = userid;
128
+ iaBookActions.identifier = identifier;
129
+ iaBookActions.bookTitle = 'Contemporary Black biography. Volume 39 : profiles from the interContemporary Black biography. Volume 39';
130
+ iaBookActions.lendingStatus = canBrowseAndBorrow;
131
+ iaBookActions.bwbPurchaseUrl = '';
132
+ iaBookActions.modalConfig = modalConfig;
133
+ iaBookActions.lendingBarPostInit = lendingBarPostInit;
134
+ iaBookActions.tokenDelay = 2000; // 2 seconds
135
+ iaBookActions.returnUrl = 'https://openlibrary.org';
136
+
137
+ let lendingStatus1 = iaBookActions.lendingStatus;
138
+
139
+ const manifest = await fetch('https://ia801302.us.archive.org/BookReader/BookReaderJSIA.php?id=goody&itemPath=/29/items/goody&server=ia801302.us.archive.org&format=jsonp&subPrefix=goody&requestUri=/details/goody/mode/1up%3Fview%3Dtheater%26ui%3Dembed%26wrapper%3Dfalse');
140
+
141
+ console.log('manifest ****', manifest).then(res => res.json());
142
+ </script>
143
+
144
+ </div>
145
+ </body>
146
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.29-alpha9",
3
+ "version": "0.1.0",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -19,10 +19,11 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@internetarchive/icon-info": "^1.2.6",
22
- "@internetarchive/local-cache": "^0.2.0",
23
- "@internetarchive/modal-manager": "^0.2.1",
22
+ "@internetarchive/local-cache": "^0.2.1",
23
+ "@internetarchive/modal-manager": "^0.2.8",
24
24
  "@internetarchive/shared-resize-observer": "^0.2.0",
25
- "lit": "^2.2.1"
25
+ "@internetarchive/toast-manager": "0.1.0",
26
+ "lit": "^2.5.0"
26
27
  },
27
28
  "devDependencies": {
28
29
  "@open-wc/eslint-config": "^4.2.0",
@@ -43,12 +44,6 @@
43
44
  "sinon": "^13.0.2"
44
45
  },
45
46
  "eslintConfig": {
46
- "rules": {
47
- "no-console": "off",
48
- "no-unused-expressions": "off",
49
- "class-methods-use-this": "off",
50
- "lit-a11y/click-events-have-key-events": "off"
51
- },
52
47
  "extends": [
53
48
  "@open-wc/eslint-config",
54
49
  "eslint-config-prettier"
@@ -60,6 +55,7 @@
60
55
  },
61
56
  "husky": {
62
57
  "hooks": {
58
+ "pre-commit": "lint-staged"
63
59
  }
64
60
  },
65
61
  "lint-staged": {
@@ -100,7 +100,7 @@ export const canBrowseAndBorrow = {
100
100
  // userid: "",
101
101
  bookUrl: '/details/practicalorganic00plim',
102
102
  daysLeftOnLoan: 0,
103
- isAdmin: false,
103
+ isAdmin: true,
104
104
  isArchiveOrgLending: true,
105
105
  isAvailable: false,
106
106
  isAvailableForBrowsing: false,
@@ -12,6 +12,7 @@ export default css`
12
12
  }
13
13
  .actiongroup {
14
14
  display: flex;
15
+ margin-right: 10px;
15
16
  }
16
17
  .action-buttons {
17
18
  display: inline-flex;
@@ -33,12 +34,12 @@ export default css`
33
34
  }
34
35
  .primary {
35
36
  background-color: ${whiteColor};
37
+ margin-right: 4px;
36
38
  }
37
39
  .primary,
38
40
  .secondary {
39
41
  position: relative;
40
42
  border-radius: 5px;
41
- margin: 0 3px;
42
43
  }
43
44
  .primary .initial {
44
45
  border-radius: 4px 0 0 4px;
@@ -9,6 +9,10 @@ import CollapsibleActionGroupStyle from '../assets/styles/collapsible-action-gro
9
9
 
10
10
  import { tabletContainerWidth } from '../core/config/constants.js';
11
11
  import { purchaseIcon } from '../assets/data/purchase.js';
12
+ import {
13
+ analyticsCategories,
14
+ analyticsActions,
15
+ } from '../core/config/analytics-event-and-category.js';
12
16
  import {
13
17
  dropdownOpened,
14
18
  dropdownClosed,
@@ -28,8 +32,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
28
32
  dropdownArrow: { type: String },
29
33
  disabled: { type: Boolean },
30
34
  returnUrl: { type: String },
31
- localCache: { type: Function },
32
- browseAgainNow: { type: Boolean },
35
+ renewNow: { type: Boolean },
33
36
  };
34
37
  }
35
38
 
@@ -49,8 +52,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
49
52
  this.loaderIcon = 'https://archive.org/upload/images/tree/loading.gif';
50
53
  this.disabled = false;
51
54
  this.returnUrl = '';
52
- this.localCache = undefined;
53
- this.browseAgainNow = false;
55
+ this.renewNow = false;
54
56
  }
55
57
 
56
58
  updated(changed) {
@@ -61,17 +63,28 @@ export class CollapsibleActionGroup extends ActionsHandler {
61
63
  this.resetActions();
62
64
  }
63
65
 
64
- if (changed.has('browseAgainNow') && this.browseAgainNow === true) {
65
- this.dispatchEvent(
66
- new CustomEvent('autoBrowseBook', {
67
- detail: {
68
- event: { autoRenewed1Hour: 'browseBook' },
69
- },
70
- })
71
- );
66
+ if (changed.has('renewNow') && this.renewNow === true) {
67
+ this.dispatchLoanRenewEvent();
72
68
  }
73
69
  }
74
70
 
71
+ // dispatch this event to loan renew handler
72
+ dispatchLoanRenewEvent() {
73
+ const { category, action } = {
74
+ category: analyticsCategories.browse,
75
+ action: analyticsActions.browseLoanRenew,
76
+ };
77
+
78
+ // listen in action-handler.js to execute ajax call on petabox.
79
+ this.dispatchEvent(
80
+ new CustomEvent('loanRenew', {
81
+ detail: {
82
+ event: { category, action },
83
+ },
84
+ })
85
+ );
86
+ }
87
+
75
88
  /**
76
89
  * merge primaryActions and secondaryActions into dropdown
77
90
  */
@@ -43,21 +43,12 @@ export class InfoIcon extends LitElement {
43
43
  vertical-align: middle;
44
44
  --iconFillColor: white;
45
45
  }
46
- .more-info-icon {
47
- margin-left: 10px;
48
- }
49
46
  .more-info-icon img {
50
47
  width: 24px;
51
48
  height: 24px;
52
49
  vertical-align: middle;
53
50
  background: white;
54
51
  }
55
- .more-info-icon.mobile {
56
- position: absolute;
57
- top: 4px;
58
- right: 55px;
59
- margin-top: 15px;
60
- }
61
52
  .hidden {
62
53
  display: none;
63
54
  }
@@ -26,7 +26,7 @@ export class TextGroup extends LitElement {
26
26
  display: inline-block;
27
27
  }
28
28
  .variable-texts {
29
- margin-left: 10px;
29
+ margin-right: 10px;
30
30
  vertical-align: middle;
31
31
  font-size: 1.7rem;
32
32
  }