@internetarchive/ia-book-actions 0.0.28-alpha1 → 0.0.29-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/demo/index.html CHANGED
@@ -127,7 +127,7 @@
127
127
  iaBookActions.lendingBarPostInit = lendingBarPostInit;
128
128
  iaBookActions.tokenDelay = 2000; // 2 seconds
129
129
  iaBookActions.returnUrl = 'https://openlibrary.org';
130
- iaBookActions.localCache = localCache;
130
+ // iaBookActions.localCache = localCache;
131
131
  iaBookActions.autoRenewTimeConfig = {
132
132
  totalTime: 60, // 60 second = 1 min
133
133
  autoRenewCheckerAtLast: 10, // totalTime - 10th minute
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.28-alpha1",
3
+ "version": "0.0.29-alpha1",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -11,20 +11,18 @@
11
11
  },
12
12
  "scripts": {
13
13
  "start": "web-dev-server",
14
- "lint": "eslint --ext .js,.html . --ignore-path .gitignore && prettier \"**/*.js\" --check --ignore-path .gitignore",
15
- "format": "eslint --ext .js,.html . --fix --ignore-path .gitignore && prettier \"**/*.js\" --write --ignore-path .gitignore",
14
+ "lint": "eslint --ext .js",
15
+ "format": "eslint --ext .js,",
16
16
  "test": "yarn run lint && yarn test:fast",
17
17
  "test:fast": "web-test-runner --coverage --playwright --browsers chromium firefox webkit",
18
18
  "test:watch": "web-test-runner --watch --playwright --browsers chromium firefox webkit"
19
19
  },
20
20
  "dependencies": {
21
21
  "@internetarchive/icon-info": "^1.2.6",
22
- "@internetarchive/local-cache": "^0.2.1",
22
+ "@internetarchive/local-cache": "^0.2.0",
23
23
  "@internetarchive/modal-manager": "^0.2.1",
24
24
  "@internetarchive/shared-resize-observer": "^0.2.0",
25
- "add": "^2.0.6",
26
- "lit": "^2.2.1",
27
- "yarn": "^1.22.19"
25
+ "lit": "^2.2.1"
28
26
  },
29
27
  "devDependencies": {
30
28
  "@open-wc/eslint-config": "^4.2.0",
@@ -56,7 +54,6 @@
56
54
  },
57
55
  "husky": {
58
56
  "hooks": {
59
- "pre-commit": "lint-staged"
60
57
  }
61
58
  },
62
59
  "lint-staged": {
@@ -115,7 +115,7 @@ export default class ActionsHandler extends LitElement {
115
115
  handleBrowseIt() {
116
116
  const action = 'browse_book';
117
117
  this.dispatchToggleActionGroup();
118
- // this.setBrowseTimeSession()
118
+ this.setBrowseTimeSession()
119
119
 
120
120
  ActionsHandlerService({
121
121
  action,
@@ -131,7 +131,7 @@ export default class ActionsHandler extends LitElement {
131
131
 
132
132
  handleAutoBrowseIt() {
133
133
  const action = 'auto_browse';
134
- // this.setBrowseTimeSession()
134
+ this.setBrowseTimeSession()
135
135
 
136
136
  ActionsHandlerService({
137
137
  action,
@@ -3,6 +3,7 @@ import { html, css, LitElement, nothing } from 'lit';
3
3
 
4
4
  import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
5
5
  import { ModalConfig } from '@internetarchive/modal-manager';
6
+ import { LocalCache } from '@internetarchive/local-cache';
6
7
 
7
8
  import './components/collapsible-action-group.js';
8
9
  import './components/book-title-bar.js';
@@ -65,7 +66,10 @@ export default class IABookActions extends LitElement {
65
66
  this.disableActionGroup = false;
66
67
  this.modal = undefined;
67
68
  this.tokenDelay = 120000; // 2 minutes
68
- this.localCache = {},
69
+ this.localCache = new LocalCache({
70
+ namespace: '1HourLoanStorage',
71
+ defaultTTL: 1 * 60, // 1 minute
72
+ }),
69
73
  this.autoRenewTimeConfig = {},
70
74
 
71
75
  // private props
@@ -77,6 +81,7 @@ export default class IABookActions extends LitElement {
77
81
  this.borrowType = ''; // (browsed|borrowed)
78
82
  this.consecutiveLoanCounts = 1; // consecutive loan count
79
83
  this.browseAgainNow = false;
84
+ this.browserTimer = undefined;
80
85
 
81
86
  // show toast-message for auto return message
82
87
  this.hideToast = true;
@@ -156,23 +161,33 @@ export default class IABookActions extends LitElement {
156
161
  }
157
162
 
158
163
  async browseHasRenew() {
159
- const currStatus = { ...this.lendingStatus, secondsLeftOnLoan: 61 };
164
+ const currStatus = {
165
+ ...this.lendingStatus,
166
+ user_has_browsed: true,
167
+ browsingExpired: false,
168
+ secondsLeftOnLoan: 61
169
+ };
160
170
  this.lendingStatus = currStatus;
171
+
172
+ this.startBrowseTimer();
161
173
  }
162
174
 
163
175
  startBrowseTimer() {
176
+ clearTimeout(this.browserTimer);
164
177
  const {
165
178
  browsingExpired,
166
179
  user_has_browsed,
167
180
  secondsLeftOnLoan,
168
181
  } = this.lendingStatus;
182
+ console.log(this.lendingStatus);
169
183
  if (!user_has_browsed || browsingExpired) {
184
+ console.log('attempted renew');
170
185
  return;
171
186
  }
172
187
 
173
188
  // expired book and show browse again button
174
189
  const timeLeft = secondsLeftOnLoan * 1000;
175
- setTimeout(() => {
190
+ this.browserTimer = setTimeout(() => {
176
191
  this.browseHasExpired();
177
192
  }, timeLeft);
178
193
  }