@internetarchive/ia-book-actions 0.1.5-b2 → 0.1.6-a1

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,11 +131,11 @@
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: 280, pageChangedInLast: 15 };
136
- let loanTotalTime1Hour = { loanTotalTime: 3600, loanRenewAtLast: 600, pageChangedInLast: 900 };
134
+ let loanTotalTime2Min = { loanTotalTime: 60, loanRenewAtLast: 51, pageChangedInLast: 15 };
135
+ let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 180, pageChangedInLast: 15 };
136
+ let loanTotalTime1Hour = { loanTotalTime: 3600, loanRenewAtLast: 660, pageChangedInLast: 900 };
137
137
 
138
- iaBookActions.loanRenewTimeConfig = loanTotalTime5Min;
138
+ iaBookActions.loanRenewTimeConfig = loanTotalTime2Min;
139
139
 
140
140
  let lendingStatus1 = iaBookActions.lendingStatus;
141
141
  let secondsLeftOnLoan = iaBookActions.loanRenewTimeConfig.loanTotalTime;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.1.5-b2",
3
+ "version": "0.1.6-a1",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -9,10 +9,6 @@ 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';
16
12
  import {
17
13
  dropdownOpened,
18
14
  dropdownClosed,
@@ -76,25 +72,16 @@ export class CollapsibleActionGroup extends ActionsHandler {
76
72
 
77
73
  /**
78
74
  * dispatch event when book is auto renewed / returned
79
- * listen these events in action-handler.js
75
+ * listen these events in action-handler.js to execute ajax call on petabox.
80
76
  * @see ActionsHandler
81
77
  *
82
78
  * @param {string} event - autoRenew|autoReturn
83
79
  * @memberof CollapsibleActionGroup
84
80
  */
85
81
  dispatchLoanEvent(event) {
86
- const category = analyticsCategories.browse;
87
- const action =
88
- event === 'autoRenew'
89
- ? analyticsActions.browseAutoRenew
90
- : analyticsActions.browseAutoReturn;
91
-
92
- // listen in action-handler.js to execute ajax call on petabox.
93
82
  this.dispatchEvent(
94
83
  new CustomEvent(event, {
95
- detail: {
96
- event: { category, action },
97
- },
84
+ detail: {},
98
85
  })
99
86
  );
100
87
  }
@@ -74,7 +74,7 @@ export default class TimerCountdown extends LitElement {
74
74
  secondsLeft -= this.timerExecutionSeconds;
75
75
  secondsLeft = Math.round(secondsLeft); // round number
76
76
 
77
- // re-sync timer is gone off
77
+ // re-sync timer if gone off because of background window
78
78
  await this.reSyncTimerIfGoneOff(secondsLeft);
79
79
 
80
80
  /**
@@ -53,7 +53,7 @@ export default class ActionsHandler extends LitElement {
53
53
  });
54
54
 
55
55
  this.addEventListener('autoReturn', () => {
56
- this.deleteLoanCookies();
56
+ this.handleReturnIt();
57
57
  this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'autoreturn');
58
58
  });
59
59
 
@@ -63,7 +63,7 @@ export default class ActionsHandler extends LitElement {
63
63
  this.loanAnanlytics?.storeLoanStatsCount(this.identifier, 'return');
64
64
  }
65
65
 
66
- this.handleReturnIt();
66
+ this.handleReturnIt('returnNow');
67
67
 
68
68
  // send these events if 14-day borrow return
69
69
  if (detail?.borrowType === 'borrow') {
@@ -154,16 +154,23 @@ export default class ActionsHandler extends LitElement {
154
154
  });
155
155
  }
156
156
 
157
- handleReturnIt() {
157
+ /**
158
+ * excute function when loan is returning
159
+ *
160
+ * @param {string} type - loan return type returnNow|''
161
+ */
162
+ handleReturnIt(type = '') {
158
163
  const action = 'return_loan';
159
- this.dispatchToggleActionGroup();
164
+
165
+ if (type === 'returnNow') this.dispatchToggleActionGroup();
160
166
 
161
167
  ActionsHandlerService({
162
168
  action,
163
169
  identifier: this.identifier,
164
170
  success: () => {
165
171
  this.deleteLoanCookies();
166
- URLHelper.goToUrl(this.returnUrl, true);
172
+
173
+ if (type === 'returnNow') URLHelper.goToUrl(this.returnUrl, true);
167
174
  },
168
175
  error: data => {
169
176
  this.dispatchActionError(action, data);
@@ -40,7 +40,7 @@ import ActionsConfig from './actions-config.js';
40
40
  * @enum {string}
41
41
  */
42
42
  export const bookTitles = {
43
- available_1hr: '',
43
+ available_1hr: 'Renews each hour as long as pages are turned.',
44
44
  available_14d: 'This book can be borrowed for 14 days.',
45
45
  available_pd: 'Book available to patrons with print disabilities.',
46
46
  available_waitlist: 'A waitlist is available.',
@@ -98,7 +98,8 @@ export class GetLendingActions {
98
98
  let isBrowsing =
99
99
  lendingStatus.user_has_browsed && !lendingStatus.browsingExpired;
100
100
  if (isBrowsing) {
101
- primaryTitleText = '';
101
+ primaryTitleText =
102
+ 'Returns automatically after 25 minutes of inactivity.';
102
103
  } else {
103
104
  primaryTitleText = `Your loan of this book has ${lendingStatus.daysLeftOnLoan} days left.`;
104
105
  }
@@ -144,14 +144,14 @@ export default class LoanAnanlytics {
144
144
  * @memberof LoanAnanlytics
145
145
  */
146
146
  sendEvent(eventCategory, eventAction, label, extraParams) {
147
- // console.log(
148
- // 'eventCategory:-',
149
- // eventCategory,
150
- // '\t||\teventAction:-',
151
- // eventAction,
152
- // '\t||\tlabel:-',
153
- // label
154
- // );
147
+ console.log(
148
+ 'eventCategory:-',
149
+ eventCategory,
150
+ '\t||\teventAction:-',
151
+ eventAction,
152
+ '\t||\tlabel:-',
153
+ label
154
+ );
155
155
 
156
156
  window?.archive_analytics?.send_event_no_sampling(
157
157
  eventCategory,
@@ -126,13 +126,6 @@ export class LoanRenewHelper {
126
126
  // convert time from second to minute
127
127
  timeLeft = Math.ceil(timeLeft / 60);
128
128
 
129
- /**
130
- * reduce 1 min from the auto return warning texts
131
- * to compensate for the 50 second buffer we’ve introduced to handle the race condition
132
- * @see IABookActions:loanRenew addEventListener
133
- */
134
- if (timeLeft > 1) timeLeft = timeLeft - 1;
135
-
136
129
  // convert time from minute to hour
137
130
  if (timeLeft > 59) {
138
131
  timeLeft = 1; // 1 hour
@@ -301,16 +301,28 @@ export default class IABookActions extends LitElement {
301
301
  console.log('** IABookActions:loanRenew', event.detail);
302
302
  await this.autoLoanRenewChecker(false);
303
303
 
304
- // renew in last seconds (let say 50 second) not possible because,
305
- // - very short to renew on datanodes by hitting petabox API
306
- // - loading images by create loan token
307
- if (event?.detail?.secondsLeft < 50) {
304
+ /**
305
+ * renew in not possible in last seconds (let say 50 second) because,
306
+ * 1. less time to execute ajax call
307
+ * 2. less time to write loan on datanodes
308
+ * 3. less time to load images by create_token api
309
+ * so if seconds left is < 50, just expire the loan
310
+ */
311
+ let secondsLeft = event?.detail?.secondsLeft;
312
+ if (secondsLeft < 50) {
308
313
  this.suppressAutoRenew = true;
314
+ this.browseHasExpired();
309
315
  }
310
316
 
311
317
  // show warning message with remaining time to auto returned it.
312
318
  if (this.loanRenewResult.renewNow === false) {
313
- this.loanRenewResult.secondsLeft = event.detail.secondsLeft;
319
+ /**
320
+ * so compensate for the 50 second buffer to handle above race conditions
321
+ * let's reduce 1 min from warning texts and early return the book when 1 min left.
322
+ */
323
+ secondsLeft -= 60;
324
+
325
+ this.loanRenewResult.secondsLeft = secondsLeft;
314
326
  this.showToastMessage();
315
327
  }
316
328
  });
@@ -2,7 +2,11 @@ import { html, fixture, expect, aTimeout } from '@open-wc/testing';
2
2
  import '../../src/ia-book-actions.js';
3
3
  import '../../src/components/timer-countdown.js';
4
4
 
5
- const container = ({ secondsLeftOnLoan, loanTotalTime, loanRenewAtLast } = {}) =>
5
+ const container = ({
6
+ secondsLeftOnLoan,
7
+ loanTotalTime,
8
+ loanRenewAtLast,
9
+ } = {}) =>
6
10
  html`<timer-countdown
7
11
  .secondsLeftOnLoan=${secondsLeftOnLoan}
8
12
  .loanTotalTime=${loanTotalTime}
@@ -20,7 +24,7 @@ describe('<timer-countdown>', () => {
20
24
  );
21
25
 
22
26
  await el.updateComplete;
23
- // expect(el.timerCountdown).to.be.undefined;
27
+ // expect(window.IALendingIntervals.timerCountdown).to.be.undefined;
24
28
  });
25
29
 
26
30
  it('timer interval is not undefined when loan is active', async () => {
@@ -36,6 +40,6 @@ describe('<timer-countdown>', () => {
36
40
  await el.updateComplete;
37
41
 
38
42
  expect(el.secondsLeftOnLoan).to.equal(2);
39
- // expect(el.timerInterval).to.not.be.undefined;
43
+ // expect(el.timerCountdown).to.not.be.undefined;
40
44
  });
41
45
  });
@@ -79,9 +79,8 @@ describe('Loan Renew Determine', () => {
79
79
  '65' // in seconds
80
80
  );
81
81
 
82
- // we will get 1 min remaining since, we reduced 1 min from remaining time
83
82
  expect(toastMsg).to.be.equal(
84
- 'This book will be automatically returned in 1 minute unless you turn a page.'
83
+ 'This book will be automatically returned in 2 minutes unless you turn a page.'
85
84
  );
86
85
  });
87
86
  });