@internetarchive/ia-book-actions 0.0.29-alpha51 → 0.0.29-alpha52
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
|
@@ -56,14 +56,11 @@ export default class TimerCountdown extends LitElement {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
timerCountdown() {
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
// - let just execute setInterval in each second
|
|
62
|
-
// - otherwise execute in 60 seconds
|
|
63
|
-
const timerExecutionSeconds = this.loanTotalTime <= 600 ? 1 : 60;
|
|
59
|
+
// - let just execute setInterval in every 1 minute
|
|
60
|
+
this.timerExecutionSeconds = 60;
|
|
64
61
|
|
|
65
62
|
this.timerInterval = setInterval(() => {
|
|
66
|
-
this.secondsLeftOnLoan -= timerExecutionSeconds;
|
|
63
|
+
this.secondsLeftOnLoan -= this.timerExecutionSeconds;
|
|
67
64
|
const secondsLeft = Math.round(this.secondsLeftOnLoan);
|
|
68
65
|
|
|
69
66
|
/**
|
|
@@ -86,11 +83,11 @@ export default class TimerCountdown extends LitElement {
|
|
|
86
83
|
}
|
|
87
84
|
|
|
88
85
|
// clear interval
|
|
89
|
-
if (secondsLeft <=
|
|
86
|
+
if (secondsLeft <= 60) {
|
|
90
87
|
clearInterval(this.timerInterval);
|
|
91
88
|
window?.Sentry?.captureMessage(sentryLogs.clearOneHourTimer);
|
|
92
89
|
}
|
|
93
|
-
}, timerExecutionSeconds * 1000);
|
|
90
|
+
}, this.timerExecutionSeconds * 1000);
|
|
94
91
|
}
|
|
95
92
|
|
|
96
93
|
/**
|
|
@@ -100,17 +97,11 @@ export default class TimerCountdown extends LitElement {
|
|
|
100
97
|
* @return string
|
|
101
98
|
*/
|
|
102
99
|
get remainingTime() {
|
|
103
|
-
|
|
100
|
+
const unitOfTime = 'minute';
|
|
104
101
|
let timeLeft = Math.round(this.secondsLeftOnLoan);
|
|
105
102
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (timeLeft > 60) {
|
|
111
|
-
unitOfTime = 'minute';
|
|
112
|
-
timeLeft = Math.floor(timeLeft / 60);
|
|
113
|
-
}
|
|
103
|
+
// convert time from second to minute
|
|
104
|
+
timeLeft = Math.ceil(timeLeft / 60);
|
|
114
105
|
|
|
115
106
|
return timeLeft !== 1
|
|
116
107
|
? `${timeLeft} ${unitOfTime}s`
|
|
@@ -114,28 +114,26 @@ export class LoanRenewHelper {
|
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
116
|
* Texts we want to show in toast template including remaining time
|
|
117
|
-
* - eg. 1 minute,
|
|
117
|
+
* - eg. 1 minute, 2 minutes
|
|
118
118
|
*
|
|
119
119
|
* @param {String} texts
|
|
120
|
-
* @param {Number}
|
|
120
|
+
* @param {Number} secondsLeft
|
|
121
121
|
*
|
|
122
122
|
* @returns {String} // texts will be appear in toast template
|
|
123
123
|
*/
|
|
124
|
-
getMessageTexts(texts,
|
|
125
|
-
|
|
124
|
+
getMessageTexts(texts, secondsLeft) {
|
|
125
|
+
const unitOfTime = 'minute';
|
|
126
126
|
|
|
127
127
|
let toastTexts = texts;
|
|
128
|
-
let timeLeft =
|
|
128
|
+
let timeLeft = secondsLeft;
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
timeLeft = Math.floor(timeLeft / 60);
|
|
133
|
-
}
|
|
130
|
+
// convert time from second to minute
|
|
131
|
+
timeLeft = Math.ceil(timeLeft / 60);
|
|
134
132
|
|
|
135
|
-
// replace remaining time
|
|
133
|
+
// replace #time variable with remaining time
|
|
136
134
|
toastTexts = toastTexts?.replace(/#time/, timeLeft);
|
|
137
135
|
|
|
138
|
-
// replace unitsOfTime
|
|
136
|
+
// replace #unitsOfTime variable with minute/minutes
|
|
139
137
|
return toastTexts?.replace(
|
|
140
138
|
/#unitsOfTime/,
|
|
141
139
|
timeLeft !== 1 ? `${unitOfTime}s` : unitOfTime
|
package/src/ia-book-actions.js
CHANGED
|
@@ -334,11 +334,15 @@ export default class IABookActions extends LitElement {
|
|
|
334
334
|
}
|
|
335
335
|
await iaBookActions.appendChild(toastTemplate);
|
|
336
336
|
|
|
337
|
+
// if secondsLeft < 60, consider it 1 minute
|
|
338
|
+
let { secondsLeft } = this.loanRenewResult;
|
|
339
|
+
secondsLeft = secondsLeft > 60 ? secondsLeft : 60;
|
|
340
|
+
|
|
337
341
|
const config = new ToastConfig();
|
|
338
342
|
config.dismisOnClick = true;
|
|
339
343
|
config.texts = this.loanRenewHelper?.getMessageTexts(
|
|
340
344
|
this.loanRenewResult.texts,
|
|
341
|
-
|
|
345
|
+
secondsLeft
|
|
342
346
|
);
|
|
343
347
|
|
|
344
348
|
toastTemplate.showToast({
|
|
@@ -80,7 +80,7 @@ describe('Loan Renew Determine', () => {
|
|
|
80
80
|
);
|
|
81
81
|
|
|
82
82
|
expect(toastMsg).to.be.equal(
|
|
83
|
-
'This book will be automatically returned in
|
|
83
|
+
'This book will be automatically returned in 2 minutes unless you turn a page.'
|
|
84
84
|
);
|
|
85
85
|
});
|
|
86
86
|
});
|