@internetarchive/ia-book-actions 1.4.2 → 1.4.3-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.
@@ -0,0 +1,12 @@
1
+ import { html } from 'lit';
2
+
3
+ export const infoIcon = html`<svg
4
+ height="20"
5
+ width="20"
6
+ viewBox="0 0 100 100"
7
+ xmlns="http://www.w3.org/2000/svg">
8
+ <g fill="none" fill-rule="evenodd"><path d="m0 0h100v100h-100z" fill="#fff"/>
9
+ <path d="m49.8315487 0h.1702245c6.7356878 0 13.1853038 1.31117332 19.3488483 3.93351997 6.1635444 2.62234664 11.4854233 6.15778963 15.9656369 10.60632903 4.4802135 4.4485394 8.0478347 9.7522946 10.7028636 15.9112655 2.655029 6.1589709 3.980878 12.6038012 3.9789971 19.3344909.0567419 6.6716279-1.1702933 13.0585776-3.6811042 19.1608491-2.510811 6.1022715-6.106803 11.5206067-10.7879759 16.2550055-9.7027949 9.7522946-21.4884754 14.6851412-35.3570414 14.79854h-.1702244c-6.7333236 0-13.1829397-1.3111733-19.3488483-3.93352-6.1659087-2.6223466-11.4877876-6.1577896-15.9656369-10.606329s-8.04547055-9.7522946-10.7028637-15.9112655c-2.65739314-6.1589709-3.9844243-12.6038012-3.98254337-19.3344909-.05674149-6.6716279 1.17029325-13.0585776 3.68110421-19.1608491 2.51081095-6.1022715 6.10680292-11.5206067 10.78797586-16.2550055 9.7027949-9.75229456 21.4884754-14.68514123 35.3570414-14.79854zm12.6566146 26.4757998c1.6745578-1.6828001 2.5118367-3.6747334 2.5118367-5.9757998 0-2.4126333-.8095238-4.4324583-2.4285714-6.059475s-3.6289796-2.440525-6.0297959-2.440525c-2.4008164 0-4.4107483.8135083-6.029796 2.440525-1.6745578 1.6270167-2.5118367 3.6468417-2.5118367 6.059475 0 2.1871753.8372789 4.1791086 2.5118367 5.9757998 1.6745579 1.6828001 3.6844898 2.5242002 6.029796 2.5242002 2.3453061 0 4.3274829-.8414001 5.9465306-2.5242002zm-12.1370589 52.7776981-1.2815282-.9486968c0-.4588935.398855-1.8938272 1.196565-4.3048011l12.7338588-39-23.0745876 3.6164609.2548896 3.873251c0-.1141289.4554971-.1997256 1.3664914-.2567901.9109942 0 1.623741.1723823 2.1382404.5171468.5121392.2306356.7965299.6039323.8531721 1.1198902 0 .8607225-.6549247 3.2134431-1.9647739 7.0581619l-8.1175252 24.1061729c-1.0242785 3.2716963-1.5080967 5.5388203-1.4514546 6.8013717.0566421 1.6643804.8826732 2.9839963 2.4780932 3.9588477 1.2532071.803658 2.8769482 1.205487 4.8712231 1.205487h.5982825c1.7653464-.0570645 3.8445846-.3875629 6.2377146-.9914952 2.3931299-.6039323 4.3590839-1.3933242 5.8978617-2.3681756 1.3098493-.803658 2.3919499-1.5359853 3.2463021-2.1969821.8543521-.6609968 1.3959925-1.1341564 1.6249211-1.4194788l.3433929-.3459533-2.8214861-3.3596708-2.9914125 2.0650205c-.79771.4588935-1.5104568.7454047-2.1382404.8595337z" fill="#000" fill-rule="nonzero"/>
10
+ </g>
11
+ </svg>
12
+ `;
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable */
2
2
  import { sentryLogs } from '../../config/sentry-events.js';
3
+ import log from '../log.js';
3
4
 
4
5
  /**
5
6
  * Helper to call loan service
@@ -29,7 +30,7 @@ export default async function ActionsHandlerService(options) {
29
30
  'return_loan',
30
31
  ];
31
32
  const shouldReturnError =
32
- location?.href?.indexOf('?error=true') !== -1 &&
33
+ new URLSearchParams(location?.search).get('error') === 'true' &&
33
34
  location?.hostname !== 'archive.org';
34
35
 
35
36
  const testHostname = ['localhost', 'internetarchive.github.io'];
@@ -42,6 +43,7 @@ export default async function ActionsHandlerService(options) {
42
43
  let formData = new FormData();
43
44
  formData.append('action', option.action);
44
45
  formData.append('identifier', option.identifier);
46
+
45
47
  try {
46
48
  await fetch(baseHost, {
47
49
  method: 'POST',
@@ -82,8 +84,10 @@ export default async function ActionsHandlerService(options) {
82
84
  .then(data => {
83
85
  // `data` is the parsed version of the JSON returned from the above endpoint.
84
86
  if (!data?.error) {
87
+ log(`[ActionsHandlerService] ✓ ${option.action} succeeded`, data);
85
88
  option?.success(data);
86
89
  } else {
90
+ log(`[ActionsHandlerService] ✗ ${option.action} failed`, data);
87
91
  option?.error(data);
88
92
  }
89
93
  });
@@ -183,14 +183,15 @@ export default class ActionsHandler extends LitElement {
183
183
  ActionsHandlerService({
184
184
  action,
185
185
  identifier: this.identifier,
186
- success: data => {
186
+ success: async data => {
187
187
  log('RENEW_LOAN --- ', data, action, data.loan, this.identifier);
188
188
  const activeLoan = data.loan ? data.loan : undefined;
189
189
  const isRenewal = activeLoan.renewal;
190
190
 
191
191
  if (activeLoan && isRenewal) {
192
- // when loan is renewed, let's reset timer & let everyone know.
193
- this.setBrowseTimeSession();
192
+ // Await — loanAutoRenewed listeners read this same cache key
193
+ // immediately; dispatching before the write lands was a race.
194
+ await this.setBrowseTimeSession();
194
195
  } else {
195
196
  log('RENEW_LOAN ERROR --- ', {
196
197
  action,
@@ -150,7 +150,7 @@ export default class LoanAnanlytics {
150
150
  }
151
151
 
152
152
  /**
153
- * reponsible to sent events to GA
153
+ * responsible to sent events to GA
154
154
  *
155
155
  * @param {*} eventCategory
156
156
  * @param {*} eventAction
@@ -16,8 +16,7 @@ export class LoanRenewHelper {
16
16
  // messages for auto return machenism
17
17
  this.loanRenewMessage =
18
18
  'This book has been renewed for #time #unitsOfTime.';
19
- this.loanReturnWarning =
20
- 'With no action, this book will be auto-returned in #time #unitsOfTime.';
19
+ this.loanReturnWarning = 'Go to any other page to keep your loan active.';
21
20
 
22
21
  // private props
23
22
  this.result = {
@@ -27,7 +26,7 @@ export class LoanRenewHelper {
27
26
  };
28
27
  }
29
28
 
30
- handleLoanRenew() {
29
+ async handleLoanRenew() {
31
30
  try {
32
31
  if (this.hasPageChanged) {
33
32
  return this.pageChanged(); // user clicked on page