@internetarchive/ia-book-actions 1.4.3 → 1.4.4-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/index.html +397 -118
- package/package.json +2 -2
- package/src/assets/data/info.js +12 -0
- package/src/core/services/actions-handler/actions-handler-service.js +5 -1
- package/src/core/services/actions-handler/actions-handler.js +4 -3
- package/src/core/services/loan-analytics.js +1 -1
- package/src/core/services/loan-renew-helper.js +2 -3
- package/src/ia-book-actions.js +222 -221
- package/test/core/services/loan-renew-helper.test.js +1 -1
- package/test/ia-book-actions.test.js +221 -7
|
@@ -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?.
|
|
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
|
-
//
|
|
193
|
-
|
|
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,
|
|
@@ -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
|