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

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
@@ -83,12 +83,7 @@
83
83
  import '../src/ia-book-actions.js';
84
84
  import {
85
85
  defaultLendingStatus,
86
- canBrowse,
87
- browsed,
88
86
  canBrowseAndBorrow,
89
- browsedAndBorrow,
90
- canBrowseAndBorrowod,
91
- canBrowseAndJoinWaitlistForBorrow,
92
87
  } from '../src/assets/data/lending-get-status-service.js';
93
88
 
94
89
  const userid = '@neeraj-archive';
@@ -139,6 +134,13 @@
139
134
  if (e.target.value === 'user_has_browsed') {
140
135
  lendingStatus1.user_has_browsed = true;
141
136
  lendingStatus1.available_to_browse = false;
137
+ lendingStatus1.secondsLeftOnLoan = 10;
138
+ lendingStatus1.browsingExpired = false;
139
+ } else if(e.target.value === 'browsingExpired') {
140
+ lendingStatus1.user_has_browsed = true;
141
+ lendingStatus1.available_to_browse = false;
142
+ lendingStatus1.secondsLeftOnLoan = 0;
143
+ lendingStatus1.browsingExpired = true;
142
144
  } else if (e.target.value === 'available_to_browse') {
143
145
  lendingStatus1.available_to_browse = true;
144
146
  lendingStatus1.user_has_browsed = false;
@@ -206,6 +208,7 @@
206
208
  <td class="availableToBrowse">
207
209
  <label><input type="radio" name="browse" value="available_to_browse" />available_to_browse</label>
208
210
  <label><input type="radio" name="browse" value="user_has_browsed" />user_has_browsed</label>
211
+ <label><input type="radio" name="browse" value="browsingExpired" />browsingExpired</label>
209
212
  </td>
210
213
  <td class="availableToBorrow">
211
214
  <label><input type="radio" name="borrow" value="available_to_borrow" />available_to_borrow</label>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.5-3",
3
+ "version": "0.0.5-4",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -34,6 +34,7 @@ export const defaultLendingStatus = {
34
34
  users_on_waitlist: 0,
35
35
  // userid: "",
36
36
  bookUrl: '/details/practicalorganic00plim',
37
+ browsingExpired: false,
37
38
  daysLeftOnLoan: 0,
38
39
  isAdmin: false,
39
40
  isArchiveOrgLending: true,
@@ -47,7 +48,7 @@ export const defaultLendingStatus = {
47
48
  loanRecord: [],
48
49
  loansUrl: '/details/@neeraj-archive?tab=loans#loans-on-loan',
49
50
  maxLoans: 10,
50
- secondsLeftOnLoan: 0,
51
+ secondsLeftOnLoan: 10,
51
52
  shouldProtectImages: true,
52
53
  totalWaitlistCount: 0,
53
54
  userHasBorrowed: false,
@@ -58,139 +59,6 @@ export const defaultLendingStatus = {
58
59
  userWaitlistPosition: -1,
59
60
  userid: '@neeraj-archive',
60
61
  };
61
-
62
- export const canBrowse = {
63
- active_borrows: 0,
64
- active_browses: 0,
65
- available_borrowable_copies: 0,
66
- available_browsable_copies: 1,
67
- available_lendable_copies: 1,
68
- available_to_borrow: false,
69
- available_to_browse: true,
70
- available_to_waitlist: false,
71
- copies_reserved_for_waitlist: 0,
72
- is_lendable: true,
73
- is_login_required: false,
74
- is_printdisabled: true,
75
- is_readable: false,
76
- last_borrow: null,
77
- last_browse: null,
78
- last_waitlist: null,
79
- max_borrowable_copies: 0,
80
- max_browsable_copies: 1,
81
- max_lendable_copies: 1,
82
- next_borrow_expiration: null,
83
- next_browse_expiration: null,
84
- orphaned_acs_loans: 0,
85
- upgradable_browses: 0,
86
- user_at_max_loans: false,
87
- user_can_claim_waitlist: false,
88
- user_has_acs_borrowed: false,
89
- user_has_borrowed: false,
90
- user_has_browsed: false,
91
- user_is_printdisabled: false,
92
- user_loan_count: 0,
93
- user_loan_record: [],
94
- user_on_waitlist: false,
95
- users_on_waitlist: 0,
96
- // userid: "",
97
- bookUrl: '/details/practicalorganic00plim',
98
- daysLeftOnLoan: 0,
99
- isAdmin: false,
100
- isArchiveOrgLending: true,
101
- isAvailable: false,
102
- isAvailableForBrowsing: true,
103
- isBrowserBorrowable: true,
104
- isLendingRequired: true,
105
- isOpenLibraryLending: false,
106
- isPrintDisabledOnly: false,
107
- loanCount: 0,
108
- loanRecord: [],
109
- loansUrl: '/details/@neeraj-archive?tab=loans#loans-on-loan',
110
- maxLoans: 10,
111
- secondsLeftOnLoan: 0,
112
- shouldProtectImages: true,
113
- totalWaitlistCount: 0,
114
- userHasBorrowed: false,
115
- userHasBrowsed: false,
116
- userHoldIsReady: false,
117
- userIsPrintDisabled: false,
118
- userOnWaitingList: false,
119
- userWaitlistPosition: -1,
120
- userid: '@neeraj-archive',
121
- };
122
-
123
- export const browsed = {
124
- active_borrows: 0,
125
- active_browses: 1,
126
- available_borrowable_copies: 0,
127
- available_browsable_copies: 0,
128
- available_lendable_copies: 0,
129
- available_to_borrow: false,
130
- available_to_browse: false,
131
- available_to_waitlist: false,
132
- copies_reserved_for_waitlist: 0,
133
- is_lendable: true,
134
- is_login_required: false,
135
- is_printdisabled: true,
136
- is_readable: false,
137
- last_borrow: null,
138
- last_browse: '2021-07-30 09:57:40',
139
- last_waitlist: null,
140
- max_borrowable_copies: 0,
141
- max_browsable_copies: 1,
142
- max_lendable_copies: 1,
143
- next_borrow_expiration: null,
144
- next_browse_expiration: '2021-07-30 10:57:40',
145
- orphaned_acs_loans: 0,
146
- upgradable_browses: 0,
147
- user_at_max_loans: false,
148
- user_can_claim_waitlist: false,
149
- user_has_acs_borrowed: false,
150
- user_has_borrowed: false,
151
- user_has_browsed: true,
152
- user_is_printdisabled: false,
153
- user_loan_count: 1,
154
- user_loan_record: {
155
- userid: '@neeraj-archive',
156
- listname: 'loan',
157
- identifier: 'practicalorganic00plim',
158
- },
159
- user_on_waitlist: false,
160
- users_on_waitlist: 0,
161
- // userid: "",
162
- bookUrl: '/details/practicalorganic00plim',
163
- daysLeftOnLoan: 0,
164
- isAdmin: false,
165
- isArchiveOrgLending: true,
166
- isAvailable: false,
167
- isAvailableForBrowsing: false,
168
- isBrowserBorrowable: true,
169
- isLendingRequired: true,
170
- isOpenLibraryLending: false,
171
- isPrintDisabledOnly: false,
172
- loanCount: 1,
173
- loanId: '1ca15f92d07dfdae3f7b1516084aec5d603800b8',
174
- loanRecord: {
175
- userid: '@neeraj-archive',
176
- listname: 'loan',
177
- identifier: 'practicalorganic00plim',
178
- },
179
- loanStartDate: '2021-07-30 09:57:40',
180
- loansUrl: '/details/@neeraj-archive?tab=loans#loans-on-loan',
181
- maxLoans: 10,
182
- secondsLeftOnLoan: 3591,
183
- shouldProtectImages: true,
184
- totalWaitlistCount: 0,
185
- userHasBorrowed: false,
186
- userHasBrowsed: true,
187
- userHoldIsReady: false,
188
- userIsPrintDisabled: false,
189
- userOnWaitingList: false,
190
- userWaitlistPosition: -1,
191
- userid: '@neeraj-archive',
192
- };
193
-
194
62
  export const canBrowseAndBorrow = {
195
63
  active_borrows: 0,
196
64
  active_browses: 1,
@@ -261,206 +129,3 @@ export const canBrowseAndBorrow = {
261
129
  userWaitlistPosition: -1,
262
130
  userid: '@neeraj-archive',
263
131
  };
264
-
265
- export const browsedAndBorrow = {
266
- active_borrows: 0,
267
- active_browses: 1,
268
- available_borrowable_copies: 0,
269
- available_browsable_copies: 0,
270
- available_lendable_copies: 0,
271
- available_to_borrow: true,
272
- available_to_browse: true,
273
- available_to_waitlist: false,
274
- copies_reserved_for_waitlist: 0,
275
- is_lendable: true,
276
- is_login_required: false,
277
- is_printdisabled: true,
278
- is_readable: false,
279
- last_borrow: null,
280
- last_browse: '2021-07-30 09:57:40',
281
- last_waitlist: null,
282
- max_borrowable_copies: 0,
283
- max_browsable_copies: 1,
284
- max_lendable_copies: 1,
285
- next_borrow_expiration: null,
286
- next_browse_expiration: '2021-07-30 10:57:40',
287
- orphaned_acs_loans: 0,
288
- upgradable_browses: 0,
289
- user_at_max_loans: false,
290
- user_can_claim_waitlist: false,
291
- user_has_acs_borrowed: false,
292
- user_has_borrowed: false,
293
- user_has_browsed: true,
294
- user_is_printdisabled: false,
295
- user_loan_count: 1,
296
- user_loan_record: {
297
- userid: '@neeraj-archive',
298
- listname: 'loan',
299
- identifier: 'practicalorganic00plim',
300
- },
301
- user_on_waitlist: false,
302
- users_on_waitlist: 0,
303
- // userid: "",
304
- bookUrl: '/details/practicalorganic00plim',
305
- daysLeftOnLoan: 0,
306
- isAdmin: false,
307
- isArchiveOrgLending: true,
308
- isAvailable: false,
309
- isAvailableForBrowsing: false,
310
- isBrowserBorrowable: true,
311
- isLendingRequired: true,
312
- isOpenLibraryLending: false,
313
- isPrintDisabledOnly: false,
314
- loanCount: 1,
315
- loanId: '1ca15f92d07dfdae3f7b1516084aec5d603800b8',
316
- loanRecord: {
317
- userid: '@neeraj-archive',
318
- listname: 'loan',
319
- identifier: 'practicalorganic00plim',
320
- },
321
- loanStartDate: '2021-07-30 09:57:40',
322
- loansUrl: '/details/@neeraj-archive?tab=loans#loans-on-loan',
323
- maxLoans: 10,
324
- secondsLeftOnLoan: 3591,
325
- shouldProtectImages: true,
326
- totalWaitlistCount: 0,
327
- userHasBorrowed: false,
328
- userHasBrowsed: true,
329
- userHoldIsReady: false,
330
- userIsPrintDisabled: false,
331
- userOnWaitingList: false,
332
- userWaitlistPosition: -1,
333
- userid: '@neeraj-archive',
334
- };
335
-
336
- export const canBrowseAndBorrowod = {
337
- active_borrows: 0,
338
- active_browses: 1,
339
- available_borrowable_copies: 0,
340
- available_browsable_copies: 0,
341
- available_lendable_copies: 0,
342
- available_to_borrow: true,
343
- available_to_browse: true,
344
- available_to_waitlist: false,
345
- copies_reserved_for_waitlist: 0,
346
- is_lendable: true,
347
- is_login_required: false,
348
- is_printdisabled: true,
349
- is_readable: false,
350
- last_borrow: null,
351
- last_browse: '2021-07-30 09:57:40',
352
- last_waitlist: null,
353
- max_borrowable_copies: 0,
354
- max_browsable_copies: 1,
355
- max_lendable_copies: 1,
356
- next_borrow_expiration: null,
357
- next_browse_expiration: '2021-07-30 10:57:40',
358
- orphaned_acs_loans: 0,
359
- upgradable_browses: 0,
360
- user_at_max_loans: false,
361
- user_can_claim_waitlist: false,
362
- user_has_acs_borrowed: false,
363
- user_has_borrowed: true,
364
- user_has_browsed: false,
365
- user_is_printdisabled: false,
366
- user_loan_count: 1,
367
- user_loan_record: {
368
- userid: '@neeraj-archive',
369
- listname: 'loan',
370
- identifier: 'practicalorganic00plim',
371
- },
372
- user_on_waitlist: false,
373
- users_on_waitlist: 0,
374
- // userid: "",
375
- bookUrl: '/details/practicalorganic00plim',
376
- daysLeftOnLoan: 0,
377
- isAdmin: false,
378
- isArchiveOrgLending: true,
379
- isAvailable: false,
380
- isAvailableForBrowsing: false,
381
- isBrowserBorrowable: true,
382
- isLendingRequired: true,
383
- isOpenLibraryLending: false,
384
- isPrintDisabledOnly: false,
385
- loanCount: 1,
386
- loanId: '1ca15f92d07dfdae3f7b1516084aec5d603800b8',
387
- loanRecord: {
388
- userid: '@neeraj-archive',
389
- listname: 'loan',
390
- identifier: 'practicalorganic00plim',
391
- },
392
- loanStartDate: '2021-07-30 09:57:40',
393
- loansUrl: '/details/@neeraj-archive?tab=loans#loans-on-loan',
394
- maxLoans: 10,
395
- secondsLeftOnLoan: 3591,
396
- shouldProtectImages: true,
397
- totalWaitlistCount: 0,
398
- userHasBorrowed: false,
399
- userHasBrowsed: true,
400
- userHoldIsReady: false,
401
- userIsPrintDisabled: false,
402
- userOnWaitingList: false,
403
- userWaitlistPosition: -1,
404
- userid: '@neeraj-archive',
405
- };
406
-
407
- export const canBrowseAndJoinWaitlistForBorrow = {
408
- active_borrows: 1,
409
- active_browses: 0,
410
- available_borrowable_copies: 0,
411
- available_browsable_copies: 1,
412
- available_lendable_copies: 1,
413
- available_to_borrow: false,
414
- available_to_browse: true,
415
- available_to_waitlist: true,
416
- copies_reserved_for_waitlist: 0,
417
- is_lendable: true,
418
- is_login_required: false,
419
- is_printdisabled: true,
420
- is_readable: false,
421
- last_borrow: '2021-07-24 18:17:46',
422
- last_browse: null,
423
- last_waitlist: '2021-07-27 11:03:23',
424
- max_borrowable_copies: 1,
425
- max_browsable_copies: 2,
426
- max_lendable_copies: 2,
427
- next_borrow_expiration: '2021-08-02 18:29:41',
428
- next_browse_expiration: null,
429
- orphaned_acs_loans: 0,
430
- upgradable_browses: 0,
431
- user_at_max_loans: false,
432
- user_can_claim_waitlist: false,
433
- user_has_acs_borrowed: false,
434
- user_has_borrowed: false,
435
- user_has_browsed: false,
436
- user_is_printdisabled: false,
437
- user_loan_count: 0,
438
- user_loan_record: [],
439
- user_on_waitlist: false,
440
- users_on_waitlist: 2,
441
- // userid: "",
442
- bookUrl: '/details/worldletitutio0000vish',
443
- daysLeftOnLoan: 0,
444
- isAdmin: false,
445
- isArchiveOrgLending: true,
446
- isAvailable: false,
447
- isAvailableForBrowsing: true,
448
- isBrowserBorrowable: true,
449
- isLendingRequired: true,
450
- isOpenLibraryLending: false,
451
- isPrintDisabledOnly: false,
452
- loanCount: 0,
453
- loanRecord: [],
454
- loansUrl: '/details/@neeraj-archive?tab=loans#loans-on-loan',
455
- maxLoans: 10,
456
- secondsLeftOnLoan: 0,
457
- shouldProtectImages: true,
458
- totalWaitlistCount: 2,
459
- userHasBorrowed: false,
460
- userHasBrowsed: false,
461
- userHoldIsReady: false,
462
- userIsPrintDisabled: false,
463
- userOnWaitingList: false,
464
- userWaitlistPosition: -1,
465
- userid: '@neeraj-archive',
466
- };
@@ -6,9 +6,8 @@ export const analyticsCategories = {
6
6
  browse: 'BookReader-ReadingBrowse',
7
7
  preview: 'BookReader-Preview',
8
8
  satisfactionMetric: 'DetailsPage-Book',
9
- purchase: 'BookReaderHeader',
10
- unavailable: 'BookReader-Preview',
11
- admin: 'Admin',
9
+ bookReaderHeader: 'BookReader-Header',
10
+ adminAccess: 'Admin-Access',
12
11
  };
13
12
 
14
13
  export const analyticsActions = {
@@ -21,4 +20,5 @@ export const analyticsActions = {
21
20
  login: 'LogIn',
22
21
  purchase: 'BWBPurchase',
23
22
  unavailable: 'Book-Unavailable',
23
+ printDisability: 'Print-Disability',
24
24
  };
@@ -33,7 +33,7 @@ export default class ActionsConfig {
33
33
  this.analyticsActions = analyticsActions;
34
34
  }
35
35
 
36
- browseBookConfig() {
36
+ firstBrowseConfig() {
37
37
  return {
38
38
  id: 'browseBook',
39
39
  text: 'Borrow for 1 hour',
@@ -45,10 +45,22 @@ export default class ActionsConfig {
45
45
  };
46
46
  }
47
47
 
48
+ browseAgainConfig() {
49
+ return {
50
+ id: 'browseBookAgain',
51
+ text: 'Borrow again',
52
+ className: 'primary',
53
+ analyticsEvent: {
54
+ category: this.analyticsCategories.browse,
55
+ action: this.analyticsActions.browseAgain,
56
+ },
57
+ };
58
+ }
59
+
48
60
  returnBookConfig() {
49
61
  const eventCategory = this.lendingStatus.user_has_browsed
50
- ? 'browse'
51
- : 'borrow';
62
+ ? this.analyticsCategories.browse
63
+ : this.analyticsCategories.borrow;
52
64
 
53
65
  return {
54
66
  id: 'returnNow',
@@ -77,7 +89,7 @@ export default class ActionsConfig {
77
89
  analyticsEvent: {
78
90
  category: this.lendingStatus.user_has_browsed
79
91
  ? this.analyticsCategories.browse
80
- : this.analyticsCategories.borrow,
92
+ : this.analyticsCategories.preview,
81
93
  action: this.analyticsActions.borrow,
82
94
  },
83
95
  };
@@ -161,7 +173,7 @@ export default class ActionsConfig {
161
173
  target: '_blank',
162
174
  className: 'purchase dark',
163
175
  analyticsEvent: {
164
- category: this.analyticsCategories.purchase,
176
+ category: this.analyticsCategories.bookReaderHeader,
165
177
  action: this.analyticsActions.purchase,
166
178
  },
167
179
  };
@@ -179,8 +191,8 @@ export default class ActionsConfig {
179
191
  target: '_self',
180
192
  className: 'print-disability',
181
193
  analyticsEvent: {
182
- category: this.analyticsCategories.purchase,
183
- action: this.analyticsActions.purchase,
194
+ category: this.analyticsCategories.bookReaderHeader,
195
+ action: this.analyticsActions.printDisability,
184
196
  },
185
197
  };
186
198
  }
@@ -198,7 +210,7 @@ export default class ActionsConfig {
198
210
  target: '_self',
199
211
  className: 'danger',
200
212
  analyticsEvent: {
201
- category: this.analyticsCategories.admin,
213
+ category: this.analyticsCategories.adminAccess,
202
214
  action: this.analyticsActions.borrow,
203
215
  },
204
216
  };
@@ -216,7 +228,7 @@ export default class ActionsConfig {
216
228
  target: '_self',
217
229
  className: 'ia-button',
218
230
  analyticsEvent: {
219
- category: this.analyticsCategories.admin,
231
+ category: this.analyticsCategories.adminAccess,
220
232
  action: this.analyticsActions.doneBorrowing,
221
233
  },
222
234
  };
@@ -229,7 +241,7 @@ export default class ActionsConfig {
229
241
  className: 'primary unavailable',
230
242
  disabled: true,
231
243
  analyticsEvent: {
232
- category: this.analyticsCategories.unavailable,
244
+ category: this.analyticsCategories.preview,
233
245
  action: this.analyticsActions.unavailable,
234
246
  },
235
247
  };
@@ -104,7 +104,7 @@ export default class GetLendingActions {
104
104
  const leaveWaitlist = this.actionsConfig.leaveWaitlistConfig();
105
105
  const borrowBook = this.actionsConfig.borrowBookConfig();
106
106
  const browseBook = lendingStatus.available_to_browse
107
- ? this.actionsConfig.browseBookConfig()
107
+ ? this.actionsConfig.firstBrowseConfig()
108
108
  : null;
109
109
 
110
110
  const dropdownOptions = browseBook ? [browseBook, borrowBook] : [];
@@ -150,7 +150,7 @@ export default class GetLendingActions {
150
150
  primaryTitle: 'You are on the waitlist for this book.',
151
151
  primaryActions: [
152
152
  this.actionsConfig.leaveWaitlistConfig(),
153
- this.actionsConfig.browseBookConfig(),
153
+ this.actionsConfig.firstBrowseConfig(),
154
154
  ],
155
155
  primaryColor: 'primary',
156
156
  secondaryActions: [
@@ -200,7 +200,9 @@ export default class GetLendingActions {
200
200
  borrow = this.actionsConfig.unavailableBookConfig();
201
201
  }
202
202
 
203
- const actions = [borrow, waitlist].filter(action => {
203
+ const printDisability = this.actionsConfig.printDisabilityConfig();
204
+
205
+ const actions = [borrow, waitlist, printDisability].filter(action => {
204
206
  return action !== null;
205
207
  });
206
208
 
@@ -263,25 +265,9 @@ export default class GetLendingActions {
263
265
  : possibleTitles.one_hour;
264
266
 
265
267
  // one hour borrow config
266
- const oneHrBorrowText = browsingHasExpired
267
- ? 'Borrow again'
268
- : 'Borrow for 1 hour';
269
- const browseAgainEvent = {
270
- category: this.analyticsCategories.browse,
271
- action: this.analyticsActions.browseAgain,
272
- };
273
- const firstBrowseEvent = {
274
- category: this.analyticsCategories.preview,
275
- action: this.analyticsActions.browse,
276
- };
277
- const oneHrBorrowEvent = browsingHasExpired
278
- ? browseAgainEvent
279
- : firstBrowseEvent;
280
-
281
- const oneHrBorrow = this.actionsConfig.browseBookConfig(
282
- oneHrBorrowText,
283
- oneHrBorrowEvent
284
- );
268
+ const oneHrBorrow = browsingHasExpired
269
+ ? this.actionsConfig.browseAgainConfig()
270
+ : this.actionsConfig.firstBrowseConfig();
285
271
 
286
272
  const borrow = this.actionsConfig.borrowBookConfig();
287
273
  const waitlist = this.actionsConfig.waitlistConfig();
@@ -316,10 +302,7 @@ export default class GetLendingActions {
316
302
  return this.loggedOutOptions();
317
303
  }
318
304
 
319
- const canBrowse =
320
- lendingStatus.available_to_browse ||
321
- (!lendingStatus.available_to_browse && lendingStatus.browsingExpired);
322
- if (canBrowse) {
305
+ if (lendingStatus.available_to_browse || lendingStatus.browsingExpired) {
323
306
  return this.borrow1HrAction();
324
307
  }
325
308
 
@@ -386,7 +369,8 @@ export default class GetLendingActions {
386
369
  lendingStatus.user_is_printdisabled;
387
370
 
388
371
  const patronIsReading =
389
- lendingStatus.user_has_borrowed || lendingStatus.user_has_browsed;
372
+ lendingStatus.user_has_borrowed ||
373
+ (lendingStatus.user_has_browsed && !lendingStatus.browsingExpired);
390
374
 
391
375
  const notBorrowed =
392
376
  !lendingStatus.user_has_borrowed && !lendingStatus.user_has_browsed;
@@ -422,7 +406,7 @@ export default class GetLendingActions {
422
406
  lendingActions = this.leaveWaitlistAction();
423
407
  } else if (userCanAccessPrintDisabled) {
424
408
  lendingActions = this.borrowPrintDisabledAction();
425
- } else if (canBorrow) {
409
+ } else if (canBorrow || lendingStatus.browsingExpired) {
426
410
  lendingActions = this.borrowAction();
427
411
  } else if (lendingStatus.isPrintDisabledOnly) {
428
412
  lendingActions = this.onlyPrintDisabledAction();
@@ -1,3 +1,4 @@
1
+ /* eslint-disable camelcase */
1
2
  import { html, css, LitElement } from 'lit-element';
2
3
 
3
4
  import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
@@ -32,7 +33,7 @@ export default class IABookActions extends LitElement {
32
33
  this.secondaryActions = [];
33
34
  this.width = 0;
34
35
  this.bwbPurchaseUrl = '';
35
- this.lendingOptions = [];
36
+ this.lendingOptions = {};
36
37
  this.sharedObserver = undefined;
37
38
  }
38
39
 
@@ -60,6 +61,28 @@ export default class IABookActions extends LitElement {
60
61
  }
61
62
  }
62
63
 
64
+ browseHasExpired() {
65
+ const browsingExpired = true;
66
+ const currStatus = { ...this.lendingStatus, browsingExpired };
67
+ this.lendingStatus = currStatus;
68
+ }
69
+
70
+ startBrowseTimer() {
71
+ const {
72
+ browsingExpired,
73
+ user_has_browsed,
74
+ secondsLeftOnLoan,
75
+ } = this.lendingStatus;
76
+ if (!user_has_browsed || browsingExpired) {
77
+ return;
78
+ }
79
+
80
+ const timeLeft = secondsLeftOnLoan * 1000;
81
+ setTimeout(() => {
82
+ this.browseHasExpired();
83
+ }, timeLeft);
84
+ }
85
+
63
86
  /** SharedObserver resize handler */
64
87
  handleResize(entry) {
65
88
  // if you are observing multiple targets,
@@ -111,6 +134,13 @@ export default class IABookActions extends LitElement {
111
134
  this.secondaryActions = actions.secondaryActions.filter(action => {
112
135
  return action != null;
113
136
  });
137
+
138
+ if (
139
+ this.lendingStatus.user_has_browsed &&
140
+ !this.lendingStatus.browseHasExpired
141
+ ) {
142
+ this.startBrowseTimer();
143
+ }
114
144
  }
115
145
 
116
146
  render() {
@@ -1,4 +1,5 @@
1
- import { html, fixture, expect } from '@open-wc/testing';
1
+ import { html, fixture, expect, aTimeout } from '@open-wc/testing';
2
+
2
3
  import '../src/ia-book-actions.js';
3
4
  import Sinon from 'sinon';
4
5
 
@@ -159,40 +160,79 @@ describe('Borrow status actions', () => {
159
160
  expect(el.primaryActions[0].text).to.equal(expectedPrimaryActions[0].text);
160
161
  expect(el.primaryActions[1].text).to.equal('Borrow for 14 days');
161
162
  });
163
+ });
162
164
 
163
- describe('Shared Resize Observer', () => {
164
- it('can receive a Shared Resize Observer', async () => {
165
- const sharedObserverStub = new SharedResizeObserver();
166
- const addObserverSpy = Sinon.spy(sharedObserverStub, 'addObserver');
167
- const component = await fixture(html` <ia-book-actions
168
- .userid=${'@userid'}
169
- .identifier=${'foo'}
170
- .lendingStatus=${{
165
+ describe('Browsing expired status', () => {
166
+ it('Book is browsed but not expired', async () => {
167
+ const el = await fixture(
168
+ container({
169
+ userid: '@userid',
170
+ lendingStatus: {
171
171
  is_lendable: true,
172
172
  user_has_browsed: true,
173
- available_to_browse: true,
174
- available_to_borrow: true,
175
- }}
176
- .sharedObserver=${sharedObserverStub}
177
- ></ia-book-actions>`);
178
- await component.updateComplete;
179
-
180
- expect(addObserverSpy.callCount).to.equal(1);
181
- });
182
- it('loads its own resize observer if it is not received', async () => {
183
- const component = await fixture(html` <ia-book-actions
184
- .userid=${'@userid'}
185
- .identifier=${'foo'}
186
- .lendingStatus=${{
173
+ browseHasExpired: false,
174
+ },
175
+ })
176
+ );
177
+ expect(el.primaryTitle).contains('Borrow ends at ');
178
+ expect(el.primaryActions[0].text).to.equal('Return now');
179
+ expect(el.primaryActions[1].text).to.equal('Print Disability Access');
180
+ });
181
+
182
+ it('Book is browsing and going to expire after 1 second', async () => {
183
+ const el = await fixture(
184
+ container({
185
+ userid: '@userid',
186
+ lendingStatus: {
187
187
  is_lendable: true,
188
188
  user_has_browsed: true,
189
- available_to_browse: true,
190
- available_to_borrow: true,
191
- }}
192
- ></ia-book-actions>`);
189
+ browseHasExpired: false,
190
+ secondsLeftOnLoan: 1,
191
+ },
192
+ })
193
+ );
194
+
195
+ await aTimeout(1500); // wait for 1.5 second
196
+ el.updateComplete;
197
+
198
+ expect(el.primaryTitle).contains('Your loan has expired.');
199
+ expect(el.primaryActions[0].text).to.equal('Borrow again');
200
+ });
201
+ });
202
+
203
+ describe('Shared Resize Observer', () => {
204
+ it('can receive a Shared Resize Observer', async () => {
205
+ const sharedObserverStub = new SharedResizeObserver();
206
+ const addObserverSpy = Sinon.spy(sharedObserverStub, 'addObserver');
207
+ const component = await fixture(html` <ia-book-actions
208
+ .userid=${'@userid'}
209
+ .identifier=${'foo'}
210
+ .lendingStatus=${{
211
+ is_lendable: true,
212
+ user_has_browsed: true,
213
+ available_to_browse: true,
214
+ available_to_borrow: true,
215
+ }}
216
+ .sharedObserver=${sharedObserverStub}
217
+ ></ia-book-actions>`);
218
+ await component.updateComplete;
219
+
220
+ expect(addObserverSpy.callCount).to.equal(1);
221
+ });
193
222
 
194
- await component.updateComplete;
195
- expect(component.sharedObserver).to.not.be.undefined;
196
- });
223
+ it('loads its own resize observer if it is not received', async () => {
224
+ const component = await fixture(html` <ia-book-actions
225
+ .userid=${'@userid'}
226
+ .identifier=${'foo'}
227
+ .lendingStatus=${{
228
+ is_lendable: true,
229
+ user_has_browsed: true,
230
+ available_to_browse: true,
231
+ available_to_borrow: true,
232
+ }}
233
+ ></ia-book-actions>`);
234
+
235
+ await component.updateComplete;
236
+ expect(component.sharedObserver).to.not.be.undefined;
197
237
  });
198
238
  });