@internetarchive/ia-book-actions 0.0.29-alpha29 → 0.0.29-alpha30

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,8 +127,8 @@
127
127
  iaBookActions.returnUrl = 'https://openlibrary.org';
128
128
  iaBookActions.localCache = localCache;
129
129
  iaBookActions.loanRenewConfig = {
130
- totalTime: 20, // 60 second = 1 min
131
- autoCheckAt: 12, // totalTime - 10th minute
130
+ totalTime: 70, // 60 second = 1 min
131
+ autoCheckAt: 65, // totalTime - 10th minute
132
132
  pageChangedInLast: 5, // within last 15 second/minute
133
133
  env: 'dev', // dev/prod
134
134
  };
@@ -284,8 +284,8 @@
284
284
  document.querySelector('.pageChangedEvent').addEventListener('click', () => {
285
285
  // dispatch event to say book page has flipped
286
286
  document.querySelector('ia-book-actions').dispatchEvent(
287
- new CustomEvent('BookReader:pageChanged', {
288
- detail: { props: { hasPageChanged: true }},
287
+ new CustomEvent('BookReader:userAction', {
288
+ detail: {},
289
289
  bubbles: true,
290
290
  composed: true,
291
291
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.29-alpha29",
3
+ "version": "0.0.29-alpha30",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -13,7 +13,7 @@ export class LoanRenewHelper {
13
13
  // messages for auto return machenism
14
14
  this.loanRenewMessage = 'This book has been renewed for 1 hour.';
15
15
  this.loanReturnWarning =
16
- 'This book will be automatically returned in #time minutes unless you turn a page.';
16
+ 'This book will be automatically returned in #time #unitsOfTime unless you turn a page.';
17
17
 
18
18
  // private props
19
19
  this.result = {
@@ -93,7 +93,7 @@ export class LoanRenewHelper {
93
93
  ) {
94
94
  this.result.texts = this.loanReturnWarning;
95
95
  this.result.renewNow = false; // not viewed
96
- console.log('not viewed!');
96
+ // console.log('not viewed!');
97
97
  } else if (lastPageFlipTime >= lastFlipTimeFrame) {
98
98
  this.result.texts = '';
99
99
  this.result.renewNow = true; // viewed in last time frame
@@ -114,6 +114,34 @@ export class LoanRenewHelper {
114
114
  });
115
115
  }
116
116
 
117
+ /**
118
+ * Texts we want to show in toast template including remaining time
119
+ * - eg. 1 minute, 50 seconds
120
+ *
121
+ * @param {String} texts
122
+ * @param {Number} time
123
+ *
124
+ * @returns {String} // texts will be appear in toast template
125
+ */
126
+ getMessageTexts(texts, time) {
127
+ let unitOfTime = 'second';
128
+
129
+ let timeLeft = time;
130
+ let toastTexts = time;
131
+
132
+ if (timeLeft > 60) {
133
+ unitOfTime = 'minute';
134
+ timeLeft = 1;
135
+ }
136
+
137
+ toastTexts = toastTexts?.replace(/#time/, timeLeft);
138
+
139
+ return toastTexts?.replace(
140
+ /#unitsOfTime/,
141
+ timeLeft !== 1 ? `${unitOfTime}s` : unitOfTime
142
+ );
143
+ }
144
+
117
145
  /**
118
146
  * Helper function to get time difference
119
147
  *
@@ -156,6 +156,8 @@ export default class IABookActions extends LitElement {
156
156
  /** End SharedObserver resize handler */
157
157
 
158
158
  async setupLendingToolbarActions() {
159
+ this.suppressToast = false;
160
+
159
161
  this.lendingOptions = new GetLendingActions(
160
162
  this.userid,
161
163
  this.identifier,
@@ -237,7 +239,7 @@ export default class IABookActions extends LitElement {
237
239
  /**
238
240
  * dispatched this event from bookreader page changed
239
241
  */
240
- window.addEventListener('BookReader:userAction', event => {
242
+ window.addEventListener('BookReader:userAction', () => {
241
243
  if (this.borrowType === 'browsed') {
242
244
  console.log('user-action executed!');
243
245
  this.autoLoanRenewChecker(true);
@@ -281,7 +283,7 @@ export default class IABookActions extends LitElement {
281
283
  );
282
284
 
283
285
  await this.loanRenewHelper.handleLoanRenew();
284
- console.log(this.loanRenewResult);
286
+ // console.log(this.loanRenewResult.timeLeft);
285
287
  this.loanRenewResult = this.loanRenewHelper.result;
286
288
  }
287
289
 
@@ -302,8 +304,8 @@ export default class IABookActions extends LitElement {
302
304
  await iaBookActions.appendChild(toastTemplate);
303
305
 
304
306
  const config = new ToastConfig();
305
- config.texts = this.loanRenewResult.texts?.replace(
306
- /#time/,
307
+ config.texts = this.loanRenewHelper.getMessageTexts(
308
+ this.loanRenewResult.texts,
307
309
  this.loanRenewResult.timeLeft
308
310
  );
309
311
  config.dismisOnClick = true;