@internetarchive/ia-book-actions 0.1.5-alpha2 → 0.1.5-b1

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
@@ -131,8 +131,8 @@
131
131
  iaBookActions.returnUrl = '';
132
132
  iaBookActions.localCache = localCache;
133
133
 
134
- let loanTotalTime2Min = { loanTotalTime: 10, loanRenewAtLast: 5, pageChangedInLast: 5 };
135
- let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 290, pageChangedInLast: 15 };
134
+ let loanTotalTime2Min = { loanTotalTime: 70, loanRenewAtLast: 65, pageChangedInLast: 5 };
135
+ let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 180, pageChangedInLast: 15 };
136
136
  let loanTotalTime1Hour = { loanTotalTime: 3600, loanRenewAtLast: 600, pageChangedInLast: 900 };
137
137
 
138
138
  iaBookActions.loanRenewTimeConfig = loanTotalTime2Min;
@@ -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.1.5-alpha2",
3
+ "version": "0.1.5-b1",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -204,7 +204,11 @@ export class CollapsibleActionGroup extends ActionsHandler {
204
204
  href="${action.url}"
205
205
  target=${action.target}
206
206
  @click=${() => {
207
- this.clickHandler(action.id, action.analyticsEvent);
207
+ this.clickHandler(
208
+ action.id,
209
+ action.analyticsEvent,
210
+ action?.borrowType
211
+ );
208
212
  }}
209
213
  >
210
214
  ${action.id === 'purchaseBook' ? purchaseIcon : ''} ${action.text}
@@ -225,7 +229,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
225
229
  return html`<button
226
230
  class="ia-button ${action.className} ${initialButton ? 'initial' : ''}"
227
231
  @click=${() => {
228
- this.clickHandler(action.id, analyticsEvent);
232
+ this.clickHandler(action.id, analyticsEvent, action?.borrowType);
229
233
  }}
230
234
  >
231
235
  ${action.text}
@@ -238,10 +242,10 @@ export class CollapsibleActionGroup extends ActionsHandler {
238
242
  * @param { object } gaEvent - contains analytics event action and category
239
243
  * @param { string } gaEvent.category
240
244
  * @param { string } gaEvent.action
241
- *
245
+ * @param { string } borrowType browse|borrow
242
246
  * @fires CollapsibleActionGroup#{eventName} - (will be browseBook, borrowBook etc...)
243
247
  */
244
- clickHandler(eventName, gaEvent) {
248
+ clickHandler(eventName, gaEvent, borrowType = '') {
245
249
  this.dropdownState = 'close';
246
250
  this.dropdownArrow = dropdownClosed;
247
251
 
@@ -251,6 +255,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
251
255
  new CustomEvent(eventName, {
252
256
  detail: {
253
257
  event: { category, action },
258
+ borrowType,
254
259
  },
255
260
  })
256
261
  );
@@ -70,6 +70,7 @@ export default class ActionsConfig {
70
70
  category: eventCategory,
71
71
  action: this.analyticsActions.doneBorrowing,
72
72
  },
73
+ borrowType: this.lendingStatus.user_has_browsed ? 'browse' : 'borrow',
73
74
  };
74
75
  }
75
76
 
@@ -37,134 +37,83 @@ export default class ActionsHandler extends LitElement {
37
37
  }
38
38
 
39
39
  bindEvents() {
40
- this.addEventListener('browseBook', ({ detail }) => {
40
+ this.addEventListener('browseBook', () => {
41
41
  this.handleBrowseIt();
42
42
  this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'browse');
43
- const { category, action } = detail.event;
44
- this.loanAnanlytics?.sendEvent(
45
- category,
46
- action,
47
- `identifier=${this.identifier}`
48
- );
49
43
  });
50
44
 
51
- this.addEventListener('browseBookAgain', ({ detail }) => {
45
+ this.addEventListener('browseBookAgain', () => {
52
46
  this.handleBrowseIt();
53
47
  this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'browseagain');
54
- const { category, action } = detail.event;
55
- this.loanAnanlytics?.sendEvent(
56
- category,
57
- action,
58
- `identifier=${this.identifier}`
59
- );
60
48
  });
61
49
 
62
- this.addEventListener('autoRenew', ({ detail }) => {
50
+ this.addEventListener('autoRenew', () => {
63
51
  this.handleLoanRenewNow();
64
52
  this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'autorenew');
65
- const { category, action } = detail.event;
66
- this.loanAnanlytics?.sendEvent(
67
- category,
68
- action,
69
- `identifier=${this.identifier}`
70
- );
71
53
  });
72
54
 
73
- this.addEventListener('autoReturn', ({ detail }) => {
55
+ this.addEventListener('autoReturn', () => {
56
+ this.deleteLoanCookies();
74
57
  this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'autoreturn');
75
- const { category, action } = detail.event;
76
- this.loanAnanlytics?.sendEvent(
77
- category,
78
- action,
79
- `identifier=${this.identifier}`
80
- );
81
58
  });
82
59
 
83
60
  this.addEventListener('returnNow', ({ detail }) => {
84
- this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'return');
61
+ // use loan stats count when 1-hour borrow is active
62
+ if (detail?.borrowType === 'browse') {
63
+ this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'return');
64
+ }
65
+
85
66
  this.handleReturnIt();
86
- const { category, action } = detail.event;
87
- this.loanAnanlytics?.sendEvent(
88
- category,
89
- action,
90
- `identifier=${this.identifier}`
91
- );
67
+
68
+ // send these events if 14-day borrow return
69
+ if (detail?.borrowType === 'borrow') {
70
+ const { category, action } = detail.event;
71
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
72
+ }
92
73
  });
93
74
 
94
75
  this.addEventListener('borrowBook', ({ detail }) => {
95
76
  this.handleBorrowIt();
96
77
  const { category, action } = detail.event;
97
- this.loanAnanlytics?.sendEvent(
98
- category,
99
- action,
100
- `identifier=${this.identifier}`
101
- );
78
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
102
79
  });
103
80
 
104
81
  this.addEventListener('loginAndBorrow', ({ detail }) => {
105
82
  this.handleLoginOk();
106
83
  const { category, action } = detail.event;
107
- this.loanAnanlytics?.sendEvent(
108
- category,
109
- action,
110
- `identifier=${this.identifier}`
111
- );
84
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
112
85
  });
113
86
 
114
87
  this.addEventListener('leaveWaitlist', ({ detail }) => {
115
88
  this.handleRemoveFromWaitingList();
116
89
  const { category, action } = detail.event;
117
- this.loanAnanlytics?.sendEvent(
118
- category,
119
- action,
120
- `identifier=${this.identifier}`
121
- );
90
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
122
91
  });
123
92
 
124
93
  this.addEventListener('joinWaitlist', ({ detail }) => {
125
94
  this.handleReserveIt();
126
95
  const { category, action } = detail.event;
127
- this.loanAnanlytics?.sendEvent(
128
- category,
129
- action,
130
- `identifier=${this.identifier}`
131
- );
96
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
132
97
  });
133
98
 
134
99
  this.addEventListener('purchaseBook', ({ detail }) => {
135
100
  const { category, action } = detail.event;
136
- this.loanAnanlytics?.sendEvent(
137
- category,
138
- action,
139
- `identifier=${this.identifier}`
140
- );
101
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
141
102
  });
142
103
 
143
104
  this.addEventListener('adminAccess', ({ detail }) => {
144
105
  const { category, action } = detail.event;
145
- this.loanAnanlytics?.sendEvent(
146
- category,
147
- action,
148
- `identifier=${this.identifier}`
149
- );
106
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
150
107
  });
151
108
 
152
109
  this.addEventListener('exitAdminAccess', ({ detail }) => {
153
110
  const { category, action } = detail.event;
154
- this.loanAnanlytics?.sendEvent(
155
- category,
156
- action,
157
- `identifier=${this.identifier}`
158
- );
111
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
159
112
  });
160
113
 
161
114
  this.addEventListener('bookTitleBar', ({ detail }) => {
162
115
  const { category, action } = detail.event;
163
- this.loanAnanlytics?.sendEvent(
164
- category,
165
- action,
166
- `identifier=${this.identifier}`
167
- );
116
+ this.loanAnanlytics?.sendEvent(category, action, this.identifier);
168
117
  });
169
118
  }
170
119
 
@@ -214,7 +163,10 @@ export default class ActionsHandler extends LitElement {
214
163
  identifier: this.identifier,
215
164
  success: () => {
216
165
  this.deleteLoanCookies();
217
- URLHelper.goToUrl(this.returnUrl, true);
166
+ // URLHelper.goToUrl(this.returnUrl, true);
167
+ setTimeout(() => {
168
+ URLHelper.goToUrl(this.returnUrl, true);
169
+ }, this.waitUntillBorrowComplete * 1000);
218
170
  },
219
171
  error: data => {
220
172
  this.dispatchActionError(action, data);
@@ -46,11 +46,7 @@ export default class LoanAnanlytics {
46
46
  );
47
47
  } catch (error) {
48
48
  console.log(error);
49
- this.sendEvent(
50
- 'Cookies-Error-Actions',
51
- error,
52
- `identifier=${this.identifier}`
53
- );
49
+ this.sendEvent('Cookies-Error-Actions', error, this.identifier);
54
50
  }
55
51
  }
56
52
 
@@ -78,7 +74,7 @@ export default class LoanAnanlytics {
78
74
  browse = browse ? Number(browse) + 1 : 1;
79
75
  this.gaStats.browse = browse;
80
76
 
81
- // reset renew and expire count when browse
77
+ // reset renew and expire count
82
78
  renew = 0;
83
79
  expire = 0;
84
80
  break;
@@ -92,7 +88,7 @@ export default class LoanAnanlytics {
92
88
  expire = expire ? Number(expire) + 1 : 1;
93
89
  this.gaStats.expire = expire;
94
90
 
95
- // reset renew and expire count when browse
91
+ // reset renew and expire count
96
92
  renew = 0;
97
93
  expire = 0;
98
94
  break;
@@ -104,37 +100,13 @@ export default class LoanAnanlytics {
104
100
  this.lendingEventCounts = { browse, renew, expire };
105
101
 
106
102
  // obtain GA category, event
107
- // const { category, event } = await this.getGACategoryAction(action);
108
103
  const category = analyticsCategories.browse;
109
104
  const event = `browse${this.paddedNumber(
110
105
  this.gaStats?.browse
111
106
  )}-autorenew${this.paddedNumber(this.gaStats?.renew)}:${action}`;
112
107
 
113
108
  // send google analytics events
114
- this.sendEvent(category, event, `identifier=${this.identifier}`, {
115
- browse: this.gaStats?.browse,
116
- renew: this.gaStats?.renew,
117
- expire: this.gaStats?.expire,
118
- });
119
- }
120
-
121
- /**
122
- *
123
- *
124
- * @param {string} action - like 'browse|autorenew|etc...'
125
- * @return {object} - contains GA category and event
126
- * - @param {string}
127
- * - @param {string}
128
- *
129
- * @memberof LoanAnanlytics
130
- */
131
- getGACategoryAction(action) {
132
- const GACategory = analyticsCategories.browse;
133
- const GAAction = `browse${this.paddedNumber(
134
- this.gaStats?.browse
135
- )}-autorenew${this.paddedNumber(this.gaStats?.renew)}:${action}`;
136
-
137
- return { GACategory, GAAction };
109
+ this.sendEvent(category, event, this.identifier);
138
110
  }
139
111
 
140
112
  /**
@@ -168,21 +140,19 @@ export default class LoanAnanlytics {
168
140
  * @memberof LoanAnanlytics
169
141
  */
170
142
  sendEvent(eventCategory, eventAction, label, extraParams) {
171
- console.debug(
172
- 'eventCategory:- ',
143
+ console.log(
144
+ 'eventCategory:-',
173
145
  eventCategory,
174
- '\neventAction:- ',
146
+ '\t||\teventAction:-',
175
147
  eventAction,
176
- '\nlabel:- ',
177
- label,
178
- '\nextraParams:- ',
179
- extraParams
148
+ '\t||\tlabel:-',
149
+ label
180
150
  );
181
151
 
182
152
  window?.archive_analytics?.send_event_no_sampling(
183
153
  eventCategory,
184
154
  eventAction,
185
- label || `identifier=${this.identifier}`,
155
+ label || this.identifier,
186
156
  extraParams
187
157
  );
188
158
  }
@@ -89,6 +89,7 @@ export class LoanRenewHelper {
89
89
  ) {
90
90
  this.result.texts = this.loanReturnWarning;
91
91
  this.result.renewNow = false; // not viewed
92
+ console.log('warning msg appears');
92
93
  } else if (pageChangedTime >= pageChangeTimeFrame) {
93
94
  this.result.texts = '';
94
95
  this.result.renewNow = true; // viewed in last time frame
@@ -2,8 +2,6 @@ import ActionsHandlerService from './actions-handler/actions-handler-service.js'
2
2
  import LoanAnanlytics from './loan-analytics.js';
3
3
  import { sentryLogs } from '../config/sentry-events.js';
4
4
 
5
- import * as Cookies from './doc-cookies.js';
6
-
7
5
  /**
8
6
  * This class is used to create loan token for borrowed books
9
7
  *
@@ -33,22 +31,22 @@ export class LoanTokenPoller {
33
31
  }
34
32
 
35
33
  async bookAccessed() {
36
- let consecutiveLoanCounts = 1;
34
+ // let consecutiveLoanCounts = 1;
37
35
 
38
36
  if (this.borrowType) {
39
37
  // send consecutiveLoanCounts for browsed books only.
40
- if (this.borrowType === 'browsed') {
41
- try {
42
- const existingCount = Cookies.getItem(
43
- `loan-count-${this.identifier}`
44
- );
45
- consecutiveLoanCounts = existingCount ?? 1;
46
- } catch (error) {
47
- window?.Sentry?.captureException(
48
- `${sentryLogs.enableBookAcces} - CookieError: ${error}`
49
- );
50
- }
51
- }
38
+ // if (this.borrowType === 'browsed') {
39
+ // try {
40
+ // const existingCount = Cookies.getItem(
41
+ // `loan-count-${this.identifier}`
42
+ // );
43
+ // consecutiveLoanCounts = existingCount ?? 1;
44
+ // } catch (error) {
45
+ // window?.Sentry?.captureException(
46
+ // `${sentryLogs.enableBookAcces} - CookieError: ${error}`
47
+ // );
48
+ // }
49
+ // }
52
50
 
53
51
  // Do an initial token, then set an interval
54
52
  this.handleLoanTokenPoller(true);
@@ -67,16 +65,12 @@ export class LoanTokenPoller {
67
65
  }
68
66
 
69
67
  // event category and action for browsing book access
70
- const category = `${this.borrowType}BookAccess`;
71
- const action = `${
72
- this.borrowType === 'browsed' ? 'BrowseCounts-' : 'Counts-'
73
- }${consecutiveLoanCounts}`;
68
+ // const category = `${this.borrowType}BookAccess`;
69
+ // const action = `${
70
+ // this.borrowType === 'browsed' ? 'BrowseCounts-' : 'Counts-'
71
+ // }${consecutiveLoanCounts}`;
74
72
 
75
- this.loanAnalytics?.sendEvent(
76
- category,
77
- action,
78
- `identifier=${this.identifier}`
79
- );
73
+ // this.loanAnalytics?.sendEvent(category, action, this.identifier);
80
74
  } else {
81
75
  window?.Sentry?.captureMessage(
82
76
  `${sentryLogs.bookAccessed} - not borrowed`
@@ -104,7 +98,7 @@ export class LoanTokenPoller {
104
98
  this.loanAnalytics?.sendEvent(
105
99
  'LendingServiceLoanError',
106
100
  action,
107
- `identifier=${this.identifier}`
101
+ this.identifier
108
102
  );
109
103
  },
110
104
  success: () => {
@@ -11,6 +11,7 @@ import './components/book-title-bar.js';
11
11
  import './components/text-group.js';
12
12
  import './components/info-icon.js';
13
13
  import './components/timer-countdown.js';
14
+ import './core/config/ia-lending-intervals.js';
14
15
 
15
16
  import { GetLendingActions } from './core/services/get-lending-actions.js';
16
17
  import { mobileContainerWidth } from './core/config/constants.js';
@@ -18,9 +19,6 @@ import { sentryLogs } from './core/config/sentry-events.js';
18
19
  import { LoanTokenPoller } from './core/services/loan-token-poller.js';
19
20
  import { LoanRenewHelper } from './core/services/loan-renew-helper.js';
20
21
 
21
- import './core/config/ia-lending-intervals.js';
22
- import * as Cookies from './core/services/doc-cookies.js';
23
-
24
22
  export const events = {
25
23
  browseExpired: 'IABookReader:BrowsingHasExpired',
26
24
  };
@@ -75,6 +73,7 @@ export default class IABookActions extends LitElement {
75
73
  this.borrowType = ''; // (browsed|borrowed)
76
74
  this.consecutiveLoanCounts = 1; // consecutive loan count
77
75
  this.suppressToast = false;
76
+ this.suppressAutoRenew = false;
78
77
  this.browseTimer = undefined;
79
78
 
80
79
  /**
@@ -173,6 +172,7 @@ export default class IABookActions extends LitElement {
173
172
 
174
173
  async setupLendingToolbarActions() {
175
174
  this.suppressToast = false;
175
+ this.suppressAutoRenew = false;
176
176
 
177
177
  this.lendingOptions = new GetLendingActions(
178
178
  this.userid,
@@ -256,9 +256,18 @@ export default class IABookActions extends LitElement {
256
256
  * dispatched this event from bookreader page changed
257
257
  */
258
258
  window.addEventListener('BookReader:userAction', () => {
259
+ console.log('** BR user Action', {
260
+ suppressAutoRenew: this.suppressAutoRenew,
261
+ borrowType: this.borrowType,
262
+ });
263
+
259
264
  this.suppressToast = true;
260
265
  this.closeToastManager();
261
266
 
267
+ if (this.suppressAutoRenew) {
268
+ return;
269
+ }
270
+
262
271
  if (this.borrowType === 'browsed') {
263
272
  this.autoLoanRenewChecker(true);
264
273
  }
@@ -268,6 +277,7 @@ export default class IABookActions extends LitElement {
268
277
  * detect click-event on document to close toast-template
269
278
  */
270
279
  document.addEventListener('click', e => {
280
+ console.log('*** top level click handler to remove toast on click');
271
281
  if (this.loanRenewHelper && this.loanRenewResult.secondsLeft > 0) {
272
282
  this.suppressToast = true;
273
283
  }
@@ -288,11 +298,18 @@ export default class IABookActions extends LitElement {
288
298
  * @see TimerCountdown::timerCountdown
289
299
  */
290
300
  this.addEventListener('IABookActions:loanRenew', async event => {
301
+ console.log('** IABookActions:loanRenew', event.detail);
291
302
  await this.autoLoanRenewChecker(false);
292
303
 
304
+ // maybe the renew with-in last 1 minute is too short of a transition time between xhr, loading images etc... let NOT renew in last 50 seconds.
305
+ if (event?.detail?.secondsLeft < 50) {
306
+ this.suppressAutoRenew = true;
307
+ }
308
+
293
309
  // show warning message with remaining time to auto returned it.
294
310
  if (this.loanRenewResult.renewNow === false) {
295
311
  this.loanRenewResult.secondsLeft = event.detail.secondsLeft;
312
+ this.suppressToast = false;
296
313
  this.showToastMessage();
297
314
  }
298
315
  });
@@ -320,6 +337,7 @@ export default class IABookActions extends LitElement {
320
337
  * close/hide toast message
321
338
  */
322
339
  async closeToastManager() {
340
+ console.log('** closeToastManager');
323
341
  const toastTemplate = this.shadowRoot.querySelector('toast-template');
324
342
  if (toastTemplate) {
325
343
  toastTemplate?.remove();
@@ -333,6 +351,10 @@ export default class IABookActions extends LitElement {
333
351
  * - show message having remaining time when book is about to auto returned
334
352
  */
335
353
  async showToastMessage() {
354
+ console.log('** showToastMessage', {
355
+ suppressToast: this.suppressToast,
356
+ loanRenewResult: this.loanRenewResult,
357
+ });
336
358
  if (this.suppressToast) return;
337
359
 
338
360
  let toastTemplate = this.shadowRoot.querySelector('toast-template');
@@ -405,9 +427,6 @@ export default class IABookActions extends LitElement {
405
427
  await this.localCache.delete(`${this.identifier}-loanTime`);
406
428
  await this.localCache.delete(`${this.identifier}-pageChangedTime`);
407
429
 
408
- // remove loan-renew-count-<identifier> cookie
409
- Cookies.removeItem(`loan-renew-count-${this.identifier}`);
410
-
411
430
  // show message after browsed book is expired.
412
431
  this.loanRenewResult.renewNow = false;
413
432
  this.loanRenewResult.texts =
@@ -507,8 +526,10 @@ export default class IABookActions extends LitElement {
507
526
  * - show success message
508
527
  * - then change the remaining time
509
528
  * - reset timer state
529
+ * @param {object} event
510
530
  */
511
- async handleLoanAutoRenewed() {
531
+ async handleLoanAutoRenewed(event) {
532
+ // TODO: just read DATA variable here to apply security { action, data }
512
533
  if (this.loanRenewResult.renewNow) {
513
534
  window?.IALendingIntervals?.clearAll();
514
535
 
@@ -518,12 +539,12 @@ export default class IABookActions extends LitElement {
518
539
  await this.resetTimerCountState();
519
540
 
520
541
  window?.Sentry?.captureMessage(`${sentryLogs.bookHasRenewed}`);
521
- // TODO: analytics?? for consecutive renew.....
522
542
 
523
543
  // testing console....
524
- console.log(sentryLogs.bookHasRenewed, {
544
+ console.log('IABookActions: AutoRenewed:- ', {
545
+ ajaxResponse: event?.detail?.data,
525
546
  loanRenewResult: this.loanRenewResult,
526
- browseHasRenew: this.lendingStatus.secondsLeftOnLoan,
547
+ secondsLeftOnLoan: Math.round(this.lendingStatus.secondsLeftOnLoan),
527
548
  resetTimerCountState: this._shadowRoot.querySelector('timer-countdown'),
528
549
  });
529
550
  }