@internetarchive/ia-book-actions 0.1.1 → 0.1.3-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
@@ -135,7 +135,7 @@
135
135
  let loanTotalTime5Min = { loanTotalTime: 300, loanRenewAtLast: 180, pageChangedInLast: 15 };
136
136
  let loanTotalTime1Hour = { loanTotalTime: 3600, loanRenewAtLast: 600, pageChangedInLast: 900 };
137
137
 
138
- iaBookActions.loanRenewTimeConfig = loanTotalTime2Min;
138
+ iaBookActions.loanRenewTimeConfig = loanTotalTime1Hour;
139
139
 
140
140
  let lendingStatus1 = iaBookActions.lendingStatus;
141
141
  let secondsLeftOnLoan = iaBookActions.loanRenewTimeConfig.loanTotalTime;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.1.1",
3
+ "version": "0.1.3-alpha1",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -63,6 +63,12 @@ export default class TimerCountdown extends LitElement {
63
63
  this.secondsLeftOnLoan -= this.timerExecutionSeconds;
64
64
  const secondsLeft = Math.round(this.secondsLeftOnLoan);
65
65
 
66
+ console.log(
67
+ 'timeLeftInSec',
68
+ secondsLeft,
69
+ ' ||| timeLeftInMin',
70
+ Math.ceil(secondsLeft / 60)
71
+ );
66
72
  /**
67
73
  * execute from last 10th minute to 0th minute
68
74
  * - 10th - to check if user has viewed
@@ -111,15 +117,14 @@ export default class TimerCountdown extends LitElement {
111
117
  render() {
112
118
  return html`
113
119
  <svg
114
- width="16"
115
- height="16"
120
+ width="14"
121
+ height="14"
116
122
  viewBox="0 0 100 100"
117
123
  xmlns="http://www.w3.org/2000/svg"
118
124
  >
119
125
  <circle class="circle" cx="50" cy="50" r="50" />
120
126
  </svg>
121
- <span class="sr-only">${this.remainingTime}</span>
122
- <span>${this.remainingTime}</span>
127
+ <span class="sr-only">${this.remainingTime} left</span>
123
128
  `;
124
129
  }
125
130
 
@@ -130,7 +135,8 @@ export default class TimerCountdown extends LitElement {
130
135
 
131
136
  return css`
132
137
  :host {
133
- right: 5px;
138
+ right: 0;
139
+ margin-right: 10px;
134
140
  position: absolute;
135
141
  }
136
142
 
@@ -13,7 +13,8 @@ export class LoanRenewHelper {
13
13
  this.loanRenewTimeConfig = loanRenewTimeConfig;
14
14
 
15
15
  // messages for auto return machenism
16
- this.loanRenewMessage = 'This book has been renewed for 1 hour.';
16
+ this.loanRenewMessage =
17
+ 'This book has been renewed for #time #unitsOfTime.';
17
18
  this.loanReturnWarning =
18
19
  'This book will be automatically returned in #time #unitsOfTime unless you turn a page.';
19
20
 
@@ -117,7 +118,7 @@ export class LoanRenewHelper {
117
118
  * @returns {String} // texts will be appear in toast template
118
119
  */
119
120
  getMessageTexts(texts, secondsLeft) {
120
- const unitOfTime = 'minute';
121
+ let unitOfTime = 'minute';
121
122
 
122
123
  let toastTexts = texts;
123
124
  let timeLeft = secondsLeft;
@@ -125,6 +126,12 @@ export class LoanRenewHelper {
125
126
  // convert time from second to minute
126
127
  timeLeft = Math.ceil(timeLeft / 60);
127
128
 
129
+ // convert minute to hour
130
+ if (timeLeft === 60) {
131
+ timeLeft = 1; // 1 hour
132
+ unitOfTime = 'hour';
133
+ }
134
+
128
135
  // replace #time variable with remaining time
129
136
  toastTexts = toastTexts?.replace(/#time/, timeLeft);
130
137
 
@@ -336,7 +336,11 @@ export default class IABookActions extends LitElement {
336
336
 
337
337
  // if secondsLeft < 60, consider it 1 minute
338
338
  let { secondsLeft } = this.loanRenewResult;
339
- secondsLeft = secondsLeft > 60 ? secondsLeft : 60;
339
+ if (secondsLeft === undefined) {
340
+ secondsLeft = this.lendingStatus.secondsLeftOnLoan;
341
+ } else {
342
+ secondsLeft = secondsLeft > 60 ? secondsLeft : 60;
343
+ }
340
344
 
341
345
  const config = new ToastConfig();
342
346
  config.dismisOnClick = true;
@@ -498,8 +502,8 @@ export default class IABookActions extends LitElement {
498
502
  this.tokenPoller?.disconnectedInterval();
499
503
 
500
504
  this.suppressToast = false;
501
- await this.showToastMessage();
502
505
  await this.browseHasRenew();
506
+ await this.showToastMessage();
503
507
  await this.resetTimerCountState();
504
508
 
505
509
  window?.Sentry?.captureMessage(`${sentryLogs.bookHasRenewed}`);