@internetarchive/ia-book-actions 0.0.7-4 → 0.0.7-7
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.7-
|
|
3
|
+
"version": "0.0.7-7",
|
|
4
4
|
"description": "Bookreader actions for borrowable book",
|
|
5
5
|
"author": "Internet Archive",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"@internetarchive/icon-bookmark": "^1.1.3",
|
|
23
23
|
"@internetarchive/icon-close": "^1.1.3",
|
|
24
24
|
"@internetarchive/icon-info": "^1.2.6",
|
|
25
|
+
"@internetarchive/local-cache": "^0.1.1",
|
|
25
26
|
"@internetarchive/modal-manager": "^0.1.0",
|
|
26
27
|
"@internetarchive/shared-resize-observer": "^0.0.1",
|
|
27
|
-
"idb-keyval": "^6.0.3",
|
|
28
28
|
"lit-element": "^2.4.0",
|
|
29
29
|
"lit-html": "^1.3.0"
|
|
30
30
|
},
|
|
@@ -2,7 +2,6 @@ import { html } from 'lit-element';
|
|
|
2
2
|
import { nothing } from 'lit-html';
|
|
3
3
|
import { classMap } from 'lit-html/directives/class-map';
|
|
4
4
|
|
|
5
|
-
import { get as indexedDBGet } from 'idb-keyval';
|
|
6
5
|
import ActionsHandler from '../core/services/actions-handler/actions-handler.js';
|
|
7
6
|
|
|
8
7
|
import buttonBaseStyle from '../assets/styles/ia-button.js';
|
|
@@ -51,19 +50,19 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
51
50
|
this.consecutiveLoanCounts = 1; // consecutive loan count
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
if (changed.has('width')) {
|
|
56
|
-
if (this.isBelowTabletContainer) {
|
|
57
|
-
this.resetActions();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
53
|
+
firstUpdated() {
|
|
61
54
|
// this is execute to fetch loan token
|
|
62
|
-
if (
|
|
55
|
+
if (this.borrowType) {
|
|
63
56
|
this.emitEnableBookAccess();
|
|
64
57
|
}
|
|
65
58
|
}
|
|
66
59
|
|
|
60
|
+
updated(changed) {
|
|
61
|
+
if (changed.has('width') && this.isBelowTabletContainer) {
|
|
62
|
+
this.resetActions();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
67
66
|
/**
|
|
68
67
|
* Dispatches event when patron is borrowing book.
|
|
69
68
|
* Notes borrow type, and consecutive borrow counts
|
|
@@ -74,7 +73,9 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
74
73
|
// send consecutiveLoanCounts for browsed books only.
|
|
75
74
|
if (this.borrowType === 'browsed') {
|
|
76
75
|
try {
|
|
77
|
-
const existingCount = await
|
|
76
|
+
const existingCount = await this.localCache.get(
|
|
77
|
+
'consecutive-loan-count'
|
|
78
|
+
);
|
|
78
79
|
if (existingCount !== undefined) {
|
|
79
80
|
this.consecutiveLoanCounts = existingCount.value ?? 1;
|
|
80
81
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LitElement } from 'lit-element';
|
|
2
|
-
import {
|
|
2
|
+
import { LocalCache } from '@internetarchive/local-cache';
|
|
3
3
|
|
|
4
4
|
import { URLHelper } from '../../config/url-helper.js';
|
|
5
5
|
import ActionsHandlerService from './actions-handler-service.js';
|
|
@@ -20,6 +20,7 @@ export default class ActionsHandler extends LitElement {
|
|
|
20
20
|
this.loanTokenPollingDelay =
|
|
21
21
|
window.location.pathname === '/demo/' ? 2000 : 120000; // 120000 ms = 2 min
|
|
22
22
|
this.loanTokenInterval = undefined;
|
|
23
|
+
this.localCache = new LocalCache();
|
|
23
24
|
this.bindEvents();
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -107,6 +108,9 @@ export default class ActionsHandler extends LitElement {
|
|
|
107
108
|
|
|
108
109
|
// fetch loan token for browsed/borrowed book and set an interval
|
|
109
110
|
if (borrowType) {
|
|
111
|
+
// Do an initial token, then set an interval
|
|
112
|
+
this.handleLoanTokenPoller();
|
|
113
|
+
|
|
110
114
|
this.loanTokenInterval = setInterval(() => {
|
|
111
115
|
this.handleLoanTokenPoller();
|
|
112
116
|
}, this.loanTokenPollingDelay);
|
|
@@ -277,21 +281,18 @@ export default class ActionsHandler extends LitElement {
|
|
|
277
281
|
try {
|
|
278
282
|
let newCount = 1;
|
|
279
283
|
const storageKey = `consecutive-loan-count`;
|
|
280
|
-
const existingCount = await
|
|
281
|
-
|
|
282
|
-
// expire indexDB key-value after 2 hours
|
|
283
|
-
const expireTime = new Date(
|
|
284
|
-
Date.now() + (1 / 12) * 24 * 60 * 60 * 1000
|
|
285
|
-
).toString();
|
|
284
|
+
const existingCount = await this.localCache.get(storageKey);
|
|
286
285
|
|
|
287
286
|
// increase browse-count by 1 when you consecutive reading a book.
|
|
288
287
|
if (action === 'browseAgain' && existingCount !== undefined) {
|
|
289
|
-
newCount = existingCount
|
|
288
|
+
newCount = existingCount ? existingCount + 1 : 1;
|
|
290
289
|
}
|
|
291
290
|
|
|
292
|
-
|
|
291
|
+
// set new value
|
|
292
|
+
await this.localCache.set({
|
|
293
|
+
key: storageKey,
|
|
293
294
|
value: newCount,
|
|
294
|
-
|
|
295
|
+
ttl: 7200, // 2 hours
|
|
295
296
|
});
|
|
296
297
|
} catch (error) {
|
|
297
298
|
console.log(error);
|