@internetarchive/ia-book-actions 0.0.7-4 → 0.0.7-5

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-4",
3
+ "version": "0.0.7-5",
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';
@@ -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 indexedDBGet('consecutive-loan-count');
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 { get as indexedDBGet, set as indexedDBSet } from 'idb-keyval';
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
 
@@ -277,21 +278,18 @@ export default class ActionsHandler extends LitElement {
277
278
  try {
278
279
  let newCount = 1;
279
280
  const storageKey = `consecutive-loan-count`;
280
- const existingCount = await indexedDBGet(storageKey);
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();
281
+ const existingCount = await this.localCache.get(storageKey);
286
282
 
287
283
  // increase browse-count by 1 when you consecutive reading a book.
288
284
  if (action === 'browseAgain' && existingCount !== undefined) {
289
- newCount = existingCount.value ? existingCount.value + 1 : 1;
285
+ newCount = existingCount ? existingCount + 1 : 1;
290
286
  }
291
287
 
292
- await indexedDBSet(storageKey, {
288
+ // set new value
289
+ await this.localCache.set({
290
+ key: storageKey,
293
291
  value: newCount,
294
- expire: expireTime,
292
+ ttl: 7200, // 2 hours
295
293
  });
296
294
  } catch (error) {
297
295
  console.log(error);