@internetarchive/ia-book-actions 0.0.29-beta2 → 0.0.30-alpha1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.29-beta2",
3
+ "version": "0.0.30-alpha1",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -102,9 +102,9 @@ export class CollapsibleActionGroup extends ActionsHandler {
102
102
  return html`
103
103
  <div
104
104
  class="${classMap({
105
- actiongroup: true,
106
- disabled: this.disabled,
107
- })}"
105
+ actiongroup: true,
106
+ disabled: this.disabled,
107
+ })}"
108
108
  >
109
109
  ${this.getLoaderIcon}
110
110
  <section class="action-buttons primary">
@@ -163,8 +163,8 @@ export class CollapsibleActionGroup extends ActionsHandler {
163
163
  href="${action.url}"
164
164
  target=${action.target}
165
165
  @click=${() => {
166
- this.clickHandler(action.id, action.analyticsEvent);
167
- }}
166
+ this.clickHandler(action.id, action.analyticsEvent);
167
+ }}
168
168
  >
169
169
  ${action.id === 'purchaseBook' ? purchaseIcon : ''} ${action.text}
170
170
  <small>${action.subText}</small>
@@ -244,9 +244,9 @@ export class CollapsibleActionGroup extends ActionsHandler {
244
244
  get getLoaderIcon() {
245
245
  return html`<img
246
246
  class="${classMap({
247
- actionloader: true,
248
- disabled: this.disabled,
249
- })}"
247
+ actionloader: true,
248
+ disabled: this.disabled,
249
+ })}"
250
250
  alt=""
251
251
  src="${this.loaderIcon}"
252
252
  />`;
@@ -5,6 +5,7 @@ export class TextGroup extends LitElement {
5
5
  return {
6
6
  texts: { type: String },
7
7
  textClass: { type: String },
8
+ hasAdminBorrowedAccess: { type: Boolean },
8
9
  };
9
10
  }
10
11
 
@@ -12,11 +13,16 @@ export class TextGroup extends LitElement {
12
13
  super();
13
14
  this.texts = '';
14
15
  this.textClass = '';
16
+ this.hasAdminBorrowedAccess = false;
15
17
  }
16
18
 
17
19
  render() {
18
20
  return html`
19
- <span class="variable-texts ${this.textClass}">${this.texts}</span>
21
+ <span class="variable-texts ${this.textClass}">
22
+ ${this.hasAdminBorrowedAccess
23
+ ? html`<slot name="sticky-access-checkbox">${this.texts}</slot>`
24
+ : this.texts}
25
+ </span>
20
26
  `;
21
27
  }
22
28
 
@@ -29,12 +35,13 @@ export class TextGroup extends LitElement {
29
35
  margin-left: 10px;
30
36
  vertical-align: middle;
31
37
  font-size: 1.7rem;
38
+ align-items: center;
32
39
  }
33
40
  .hidden {
34
41
  display: none;
35
42
  }
36
43
  .visible {
37
- display: inline-block;
44
+ display: flex;
38
45
  }
39
46
  `;
40
47
  }
@@ -51,6 +51,7 @@ export const bookTitles = {
51
51
  on_waitlist: 'You are on the waitlist for this book.',
52
52
  session_expired: 'Your loan has expired.',
53
53
  unavailable: 'This book is not available at this time.',
54
+ admin_borrowed: 'Default to admin access mode',
54
55
  };
55
56
 
56
57
  export class GetLendingActions {
@@ -83,7 +84,7 @@ export class GetLendingActions {
83
84
 
84
85
  adminOrPrintDisabledReadingAction() {
85
86
  return {
86
- primaryTitle: '',
87
+ primaryTitle: bookTitles.admin_borrowed,
87
88
  primaryActions: [],
88
89
  secondaryActions: [this.actionsConfig.adminOrPrintDisabledExitConfig()],
89
90
  borrowType: 'adminBorrowed',
@@ -12,6 +12,7 @@ import './components/info-icon.js';
12
12
  import { GetLendingActions } from './core/services/get-lending-actions.js';
13
13
  import { mobileContainerWidth } from './core/config/constants.js';
14
14
  import { LoanTokenPoller } from './core/services/loan-token-poller.js';
15
+ import { getItem, setItem } from './core/services/doc-cookies.js';
15
16
 
16
17
  export const events = {
17
18
  browseExpired: 'IABookReader:BrowsingHasExpired',
@@ -48,7 +49,7 @@ export default class IABookActions extends LitElement {
48
49
  this.lendingStatus = {};
49
50
  this.width = 0;
50
51
  this.bwbPurchaseUrl = '';
51
- this.lendingBarPostInit = () => {};
52
+ this.lendingBarPostInit = () => { };
52
53
  this.barType = 'action'; // 'title'|'action'
53
54
  this.sharedObserver = undefined;
54
55
  this.disableActionGroup = false;
@@ -96,11 +97,8 @@ export default class IABookActions extends LitElement {
96
97
  }
97
98
 
98
99
  startBrowseTimer() {
99
- const {
100
- browsingExpired,
101
- user_has_browsed,
102
- secondsLeftOnLoan,
103
- } = this.lendingStatus;
100
+ const { browsingExpired, user_has_browsed, secondsLeftOnLoan } =
101
+ this.lendingStatus;
104
102
  if (!user_has_browsed || browsingExpired) {
105
103
  return;
106
104
  }
@@ -356,7 +354,7 @@ export default class IABookActions extends LitElement {
356
354
  Please ${refreshButton} to try again or send us an email to
357
355
  <a
358
356
  href="mailto:info@archive.org?subject=Help: cannot access my borrowed book: ${this
359
- .identifier}"
357
+ .identifier}"
360
358
  >info@archive.org</a
361
359
  >`;
362
360
  }
@@ -366,6 +364,12 @@ export default class IABookActions extends LitElement {
366
364
  });
367
365
  }
368
366
 
367
+ // eslint-disable-next-line class-methods-use-this
368
+ toggleStickyAdminAccess() {
369
+ const currentValue = getItem('sticky-admin-access') === 'true';
370
+ setItem('sticky-admin-access', !currentValue);
371
+ }
372
+
369
373
  get iconClass() {
370
374
  return this.width <= mobileContainerWidth ? 'mobile' : 'desktop';
371
375
  }
@@ -382,10 +386,36 @@ export default class IABookActions extends LitElement {
382
386
  return html`<text-group
383
387
  textClass=${this.textClass}
384
388
  texts=${this.primaryTitle}
389
+ ?hasAdminBorrowedAccess=${this.hasAdminBorrowedAccess}
385
390
  >
391
+ ${this.hasAdminBorrowedAccess
392
+ ? html`<div slot="sticky-access-checkbox">
393
+ ${this.stickyAdminAccess}
394
+ </div>`
395
+ : ''}
386
396
  </text-group>`;
387
397
  }
388
398
 
399
+ get stickyAdminAccess() {
400
+ return html`
401
+ <label class="stick-admin" for="sticky-admin-access">
402
+ <input
403
+ type="checkbox"
404
+ id="sticky-admin-access"
405
+ aria-label="Checkbox"
406
+ @click=${this.toggleStickyAdminAccess}
407
+ />
408
+ <span>${this.primaryTitle}</span>
409
+ </label>
410
+ `;
411
+ }
412
+
413
+ get hasAdminBorrowedAccess() {
414
+ return this.secondaryActions.some(
415
+ action => action.id === 'exitAdminAccess'
416
+ );
417
+ }
418
+
389
419
  get hasAdminAccess() {
390
420
  return !this.lendingStatus.userHasBorrowed && this.lendingStatus.isAdmin;
391
421
  }
@@ -405,6 +435,10 @@ export default class IABookActions extends LitElement {
405
435
  justify-content: center;
406
436
  flex-wrap: wrap;
407
437
  }
438
+ .stick-admin {
439
+ user-select: none;
440
+ cursor: pointer;
441
+ }
408
442
  `;
409
443
  }
410
444
  }