@internetarchive/ia-book-actions 0.0.29-alpha2 → 0.0.29-alpha4

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,14 +127,14 @@
127
127
  iaBookActions.tokenDelay = 2000; // 2 seconds
128
128
  iaBookActions.returnUrl = 'https://openlibrary.org';
129
129
  iaBookActions.localCache = localCache;
130
- iaBookActions.autoRenewTimeConfig = {
131
- totalTime: 60, // 60 second = 1 min
132
- autoCheckAt: 55, // totalTime - 10th minute
130
+ iaBookActions.autoRenewConfig = {
131
+ totalTime: 10, // 60 second = 1 min
132
+ autoCheckAt: 8, // totalTime - 10th minute
133
133
  FlippedInLast: 15, // within last 15 second/minute
134
134
  };
135
135
 
136
136
  let lendingStatus1 = iaBookActions.lendingStatus;
137
- let secondsLeftOnLoan = 60;
137
+ let secondsLeftOnLoan = iaBookActions.autoRenewConfig.totalTime;
138
138
 
139
139
  document.querySelectorAll('.titleBar input[type=checkbox]').forEach((item) => {
140
140
  item.addEventListener('click', (e) => {
@@ -226,7 +226,7 @@
226
226
  await localCache.set({
227
227
  key: `${identifier}-loanTime`,
228
228
  value: new Date(), // current time
229
- ttl: parseInt(iaBookActions.autoRenewTimeConfig.totalTime),
229
+ ttl: parseInt(iaBookActions.autoRenewConfig.totalTime),
230
230
  })
231
231
 
232
232
  await localCache.delete(`${identifier}-pageFlipTime`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.29-alpha2",
3
+ "version": "0.0.29-alpha4",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -29,7 +29,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
29
29
  disabled: { type: Boolean },
30
30
  returnUrl: { type: String },
31
31
  browseAgainNow: { type: Boolean },
32
- autoRenewTimeConfig: { type: Object },
32
+ autoRenewConfig: { type: Object },
33
33
  };
34
34
  }
35
35
 
@@ -50,7 +50,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
50
50
  this.disabled = false;
51
51
  this.returnUrl = '';
52
52
  this.browseAgainNow = false;
53
- this.autoRenewTimeConfig = {};
53
+ this.autoRenewConfig = {};
54
54
  }
55
55
 
56
56
  updated(changed) {
@@ -4,7 +4,7 @@ export class ToastMessage extends LitElement {
4
4
  static get properties() {
5
5
  return {
6
6
  texts: { type: String },
7
- dismisOnClick: { type: Function },
7
+ dismisOnClick: { type: Boolean },
8
8
  hideToast: { type: Boolean },
9
9
  };
10
10
  }
@@ -19,7 +19,11 @@ export class ToastMessage extends LitElement {
19
19
  render() {
20
20
  return !this.hideToast
21
21
  ? html`
22
- <span class="toast-message ${this.textClass}">${this.texts}</span>
22
+ <span
23
+ class="toast-message fade-in ${this.textClass}"
24
+ title="Click/tap to close"
25
+ @click=${() => { this.dismisOnClick ? this.hideToast = true : nothing}}
26
+ >${this.texts}</span>
23
27
  `
24
28
  : nothing;
25
29
  }
@@ -30,15 +34,16 @@ export class ToastMessage extends LitElement {
30
34
  return css`
31
35
  :host {
32
36
  display: inline-block;
37
+
33
38
  }
34
39
  .toast-message {
35
40
  z-index: 2;
36
41
  position: absolute;
37
42
  top: ${heightFromTop};
38
43
  font-size: 1.4rem;
44
+ font-family: "Helvetica Neue";
39
45
  color: #fff;
40
46
  left: 50%;
41
- right: 50%;
42
47
  background: #333;
43
48
  border: 1px solid #fff;
44
49
  border-radius: 5px;
@@ -46,7 +51,18 @@ export class ToastMessage extends LitElement {
46
51
  padding: 10px;
47
52
  width: fit-content;
48
53
  transform: translate(-50%, -50%);
54
+ cursor: pointer;
55
+ animation: fadeIn 5s;
56
+ @keyframes fadeIn {
57
+ 0% {
58
+ opacity: 0;
59
+ }
60
+ 100% {
61
+ opacity: 1;
62
+ }
63
+ }
49
64
  }
65
+
50
66
  .hidden {
51
67
  display: none;
52
68
  }
@@ -19,7 +19,7 @@ export default class ActionsHandler extends LitElement {
19
19
  this.identifier = '';
20
20
  this.ajaxTimeout = 6000;
21
21
  this.returnUrl = '';
22
- this.autoRenewTimeConfig = {};
22
+ this.autoRenewConfig = {};
23
23
 
24
24
  this.localCache = new LocalCache({
25
25
  namespace: '1HourLoanStorage',
@@ -127,14 +127,18 @@ export default class ActionsHandler extends LitElement {
127
127
  }
128
128
 
129
129
  handleAutoBrowseIt() {
130
- const action = 'auto_browse';
130
+ const action = 'renew_loan';
131
131
  this.setBrowseTimeSession()
132
132
 
133
133
  ActionsHandlerService({
134
134
  action,
135
135
  identifier: this.identifier,
136
- success: () => {},
136
+ success: () => {
137
+ console.log('success!');
138
+ },
137
139
  error: data => {
140
+ console.log(data);
141
+ console.log('error!');
138
142
  this.dispatchActionError(action, data);
139
143
  },
140
144
  });
@@ -317,7 +321,7 @@ export default class ActionsHandler extends LitElement {
317
321
  await this.localCache.set({
318
322
  key: `${this.identifier}-loanTime`,
319
323
  value: new Date(), // current time
320
- ttl: parseInt(this.autoRenewTimeConfig.totalTime),
324
+ ttl: parseInt(this.autoRenewConfig.totalTime),
321
325
  })
322
326
 
323
327
  await this.localCache.delete(`${this.identifier}-pageFlipTime`);
@@ -6,25 +6,25 @@ import ActionsHandlerService from './actions-handler/actions-handler-service.js'
6
6
  * ActionsHandlerService is a function being used to execute
7
7
  */
8
8
  export class OneHourAutoRenew {
9
- constructor(pageClick, identifier, localCache, autoRenewTimeConfig, userHasBrowsed) {
9
+ constructor(pageClick, identifier, localCache, autoRenewConfig, userHasBrowsed) {
10
10
  this.pageClick = pageClick;
11
11
  this.identifier = identifier;
12
12
  this.localCache = localCache;
13
- this.autoRenewTimeConfig = autoRenewTimeConfig;
13
+ this.autoRenewConfig = autoRenewConfig;
14
14
  this.userHasBrowsed = userHasBrowsed;
15
15
 
16
+ // messages for auto return machenism
17
+ this.autoRenewMessage = 'This book has been renewed for another hour.';
18
+ this.autoReturnMessage = 'This book has been auto-returned due to inactivity.';
19
+ this.autoReturnWarning = 'This book will be auto-returned in 10 minutes unless you turn a page.';
20
+
16
21
  // private props
17
22
  this.resultRes = {
18
- toastTexts: null,
23
+ toastTexts: this.autoReturnMessage,
19
24
  hideToast: true,
20
25
  renewNow: false,
21
26
  };
22
27
 
23
- // messages for auto return machenism
24
- this.autoRenewMessage = 'This book has been renewed for another hour.';
25
- this.autoReturnMessage = 'This book has been auto-returned due to inactivity.';
26
- this.autoReturnWarning = 'This book will be auto-returned in 10 minutes unless you turn a page.';
27
-
28
28
  return this.handleBookAutoRenew();
29
29
  }
30
30
 
@@ -51,7 +51,7 @@ export class OneHourAutoRenew {
51
51
  await this.localCache.set({
52
52
  key: `${this.identifier}-pageFlipTime`,
53
53
  value: new Date(), // current time
54
- ttl: parseInt(this.autoRenewTimeConfig.totalTime),
54
+ ttl: parseInt(this.autoRenewConfig.totalTime),
55
55
  })
56
56
  }
57
57
 
@@ -59,7 +59,7 @@ export class OneHourAutoRenew {
59
59
  const {
60
60
  totalTime, // 60
61
61
  autoCheckAt, // 50
62
- } = this.autoRenewTimeConfig;
62
+ } = this.autoRenewConfig;
63
63
  const currentDate = new Date();
64
64
  const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
65
65
 
@@ -82,7 +82,7 @@ export class OneHourAutoRenew {
82
82
 
83
83
  async autoCheckerTimer() {
84
84
  const currentDate = new Date();
85
- const { FlippedInLast } = this.autoRenewTimeConfig;
85
+ const { FlippedInLast } = this.autoRenewConfig;
86
86
  const lastPageFlipTime = await this.localCache.get(`${this.identifier}-pageFlipTime`);
87
87
 
88
88
  // last 15 min if used flipped a page.
@@ -93,15 +93,18 @@ export class OneHourAutoRenew {
93
93
  ); // 15 seconds
94
94
 
95
95
  if (lastPageFlipTime === undefined || lastPageFlipTime <= lastFlipTimeFrame) { // not viewed
96
- console.log('2');
96
+ console.log('2 not viewed, warning message!');
97
97
  this.resultRes.toastTexts = this.autoReturnWarning;
98
98
  this.resultRes.hideToast = false;
99
99
  } else if (lastPageFlipTime >= lastFlipTimeFrame) { // viewed in last time frame
100
- console.log('3');
100
+ console.log('3 viewed, auto renew and message!');
101
101
  this.resultRes.toastTexts = this.autoRenewMessage;
102
102
  this.resultRes.browseAgainNow = true;
103
103
  this.resultRes.hideToast = false;
104
104
  this.resultRes.renewNow = true;
105
+
106
+ // delete pageFlipTime when book is auto renew at nth minute
107
+ await this.localCache.delete(`${this.identifier}-pageFlipTime`);
105
108
  }
106
109
 
107
110
  return this.resultRes;
@@ -141,6 +144,7 @@ export class OneHourAutoRenew {
141
144
  this.sendEvent('handleAutoRenew', action);
142
145
  },
143
146
  success: () => {
147
+ console.log('success!');
144
148
  return 'success';
145
149
  },
146
150
  });
@@ -45,7 +45,7 @@ export default class IABookActions extends LitElement {
45
45
  remainingTime: { type: Number },
46
46
  resetTimerCountdown: { type: Boolean },
47
47
  localCache: { type: Object },
48
- autoRenewTimeConfig: { type: Object },
48
+ autoRenewConfig: { type: Object },
49
49
  browseAgainNow: { type: Boolean },
50
50
  };
51
51
  }
@@ -69,7 +69,8 @@ export default class IABookActions extends LitElement {
69
69
  this.localCache = new LocalCache({
70
70
  namespace: '1HourLoanStorage'
71
71
  }),
72
- this.autoRenewTimeConfig = {},
72
+ this.autoRenewConfig = {},
73
+ this.autoRenewObj = undefined;
73
74
 
74
75
  // private props
75
76
  this.primaryActions = [];
@@ -101,6 +102,7 @@ export default class IABookActions extends LitElement {
101
102
  }
102
103
 
103
104
  updated(changed) {
105
+ console.log(changed)
104
106
  if (changed.has('lendingStatus') || changed.has('bwbPurchaseUrl')) {
105
107
  this.setupLendingToolbarActions();
106
108
  this.update();
@@ -120,21 +122,20 @@ export default class IABookActions extends LitElement {
120
122
  this.addEventListener('autoRenewAttempt', async event => {
121
123
  const isPageFlipped = event.detail.bookPageChange;
122
124
 
123
- const dd = await new OneHourAutoRenew(
125
+ this.autoRenewObj = await new OneHourAutoRenew(
124
126
  isPageFlipped,
125
127
  this.identifier,
126
128
  this.localCache,
127
- this.autoRenewTimeConfig,
129
+ this.autoRenewConfig,
128
130
  this.lendingStatus.user_has_browsed && !this.lendingStatus.browsingExpired
129
131
  );
130
132
 
131
- this.toastTexts = dd.toastTexts;
132
- this.hideToast = dd.hideToast;
133
- this.browseAgainNow = dd.renewNow;
133
+ this.toastTexts = this.autoRenewObj.toastTexts;
134
+ this.hideToast = this.autoRenewObj.hideToast;
135
+ this.browseAgainNow = this.autoRenewObj.renewNow;
134
136
  if (this.browseAgainNow) {
135
137
  await this.browseHasRenew();
136
138
  }
137
- // this.handleBookAutoRenew(event);
138
139
  });
139
140
  }
140
141
 
@@ -147,7 +148,7 @@ export default class IABookActions extends LitElement {
147
148
  await this.localCache.delete(`${this.identifier}-pageFlipTime`);
148
149
 
149
150
  // show message after browsed book is expired.
150
- this.toastTexts = this.autoReturnMessage;
151
+ this.toastTexts = 'This book has been auto-returned due to inactivity.';
151
152
  }
152
153
 
153
154
  async browseHasRenew() {
@@ -155,7 +156,7 @@ export default class IABookActions extends LitElement {
155
156
  ...this.lendingStatus,
156
157
  user_has_browsed: true,
157
158
  browsingExpired: false,
158
- secondsLeftOnLoan: 61
159
+ secondsLeftOnLoan: this.autoRenewConfig.totalTime + 1,
159
160
  };
160
161
  this.lendingStatus = currStatus;
161
162
 
@@ -291,7 +292,7 @@ export default class IABookActions extends LitElement {
291
292
  return this.borrowType === 'browsed'
292
293
  ? html`<timer-countdown
293
294
  time=${Number(this.remainingTime)}
294
- .autoCheckAt=${this.autoRenewTimeConfig.autoCheckAt}
295
+ .autoCheckAt=${this.autoRenewConfig.autoCheckAt}
295
296
  ?resetTimerCountdown=${this.resetTimerCountdown}
296
297
  ></timer-countdown>`
297
298
  : nothing;
@@ -301,7 +302,7 @@ export default class IABookActions extends LitElement {
301
302
  return html`
302
303
  <toast-message
303
304
  .texts=${this.toastTexts}
304
- .dismisOnClick="1"
305
+ ?dismisOnClick=${true}
305
306
  ?hideToast=${this.hideToast}
306
307
  ></toast-message>
307
308
  `;
@@ -320,7 +321,7 @@ export default class IABookActions extends LitElement {
320
321
  .borrowType=${this.borrowType}
321
322
  .returnUrl=${this.returnUrl}
322
323
  .autoRenew=${this.autoRenew}
323
- .autoRenewTimeConfig=${this.autoRenewTimeConfig}
324
+ .autoRenewConfig=${this.autoRenewConfig}
324
325
  ?hasAdminAccess=${this.hasAdminAccess}
325
326
  ?disabled=${this.disableActionGroup}
326
327
  ?browseAgainNow=${this.browseAgainNow}