@internetarchive/ia-book-actions 0.0.29-alpha21 → 0.0.29-alpha22
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
|
@@ -118,7 +118,7 @@ export const canBrowseAndBorrow = {
|
|
|
118
118
|
loanStartDate: '2021-07-30 09:57:40',
|
|
119
119
|
loansUrl: '/details/@neeraj-archive?tab=loans#loans-on-loan',
|
|
120
120
|
maxLoans: 10,
|
|
121
|
-
secondsLeftOnLoan:
|
|
121
|
+
secondsLeftOnLoan: 12,
|
|
122
122
|
shouldProtectImages: true,
|
|
123
123
|
totalWaitlistCount: 0,
|
|
124
124
|
userHasBorrowed: false,
|
|
@@ -58,8 +58,8 @@ export default class TimerCountdown extends LitElement {
|
|
|
58
58
|
render() {
|
|
59
59
|
return html`
|
|
60
60
|
<svg
|
|
61
|
-
width="
|
|
62
|
-
height="
|
|
61
|
+
width="16"
|
|
62
|
+
height="16"
|
|
63
63
|
viewBox="0 0 100 100"
|
|
64
64
|
xmlns="http://www.w3.org/2000/svg"
|
|
65
65
|
>
|
|
@@ -70,43 +70,40 @@ export default class TimerCountdown extends LitElement {
|
|
|
70
70
|
|
|
71
71
|
static get styles() {
|
|
72
72
|
const white = css`var(--white, #fff)`;
|
|
73
|
-
const
|
|
73
|
+
const timerSecondsLeft = css`var(--timerSeconds, 6000s)`;
|
|
74
|
+
const timerStrokeLeft = css`var(--timerStroke, 315)`;
|
|
74
75
|
|
|
75
76
|
return css`
|
|
76
77
|
:host {
|
|
77
78
|
right: 5px;
|
|
78
|
-
font-size: 14px;
|
|
79
79
|
position: absolute;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
@keyframes circletimer {
|
|
83
83
|
0% {
|
|
84
|
-
stroke-dashoffset:
|
|
85
|
-
stroke-dasharray:
|
|
84
|
+
stroke-dashoffset: ${timerStrokeLeft};
|
|
85
|
+
stroke-dasharray: 315;
|
|
86
86
|
}
|
|
87
87
|
100% {
|
|
88
88
|
stroke-dashoffset: 0;
|
|
89
|
-
stroke-dasharray:
|
|
89
|
+
stroke-dasharray: 315;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
svg {
|
|
94
|
-
background-color:
|
|
95
|
-
position: absolute;
|
|
96
|
-
top: 50%;
|
|
97
|
-
right: 0;
|
|
94
|
+
background-color: ${white};
|
|
98
95
|
border-radius: 50px;
|
|
99
96
|
border: 2px solid ${white};
|
|
100
|
-
transform:
|
|
97
|
+
transform: rotateZ(-90deg);
|
|
101
98
|
}
|
|
102
99
|
|
|
103
100
|
svg .circle {
|
|
104
|
-
stroke:
|
|
101
|
+
stroke: #000;
|
|
105
102
|
stroke-width: 100px;
|
|
106
|
-
fill:
|
|
107
|
-
stroke-dashoffset:
|
|
103
|
+
fill: ${white};
|
|
104
|
+
stroke-dashoffset: 315;
|
|
108
105
|
stroke-dasharray: 0;
|
|
109
|
-
animation: ${
|
|
106
|
+
animation: ${timerSecondsLeft} circletimer linear;
|
|
110
107
|
}
|
|
111
108
|
`;
|
|
112
109
|
}
|
|
@@ -148,7 +148,7 @@ export class LoanRenewHelper {
|
|
|
148
148
|
* @returns {Object} Date
|
|
149
149
|
*/
|
|
150
150
|
changeTime(date, minutes, op) {
|
|
151
|
-
if (date === undefined) return
|
|
151
|
+
if (date === undefined) return null;
|
|
152
152
|
|
|
153
153
|
if (op === 'sub') {
|
|
154
154
|
return new Date(date.getTime() - minutes * 1000);
|
package/src/ia-book-actions.js
CHANGED
|
@@ -232,9 +232,8 @@ export default class IABookActions extends LitElement {
|
|
|
232
232
|
*/
|
|
233
233
|
bindLoanRenewEvents() {
|
|
234
234
|
// dispatched this event from bookreader page changed
|
|
235
|
-
window.addEventListener('BookReader:pageChanged',
|
|
236
|
-
|
|
237
|
-
if (this.borrowType === 'browsed') {
|
|
235
|
+
window.addEventListener('BookReader:pageChanged', event => {
|
|
236
|
+
if (this.borrowType === 'browsed' && event.detail.hasPageChanged) {
|
|
238
237
|
this.autoLoanRenewChecker(true);
|
|
239
238
|
}
|
|
240
239
|
|
|
@@ -268,6 +267,7 @@ export default class IABookActions extends LitElement {
|
|
|
268
267
|
);
|
|
269
268
|
|
|
270
269
|
await this.loanRenewHelper.handleLoanRenew();
|
|
270
|
+
console.log(this.loanRenewResult);
|
|
271
271
|
this.loanRenewResult = this.loanRenewHelper.result;
|
|
272
272
|
}
|
|
273
273
|
|
|
@@ -327,12 +327,26 @@ export default class IABookActions extends LitElement {
|
|
|
327
327
|
* Reset timer animation state after book renewed
|
|
328
328
|
*/
|
|
329
329
|
async resetTimerCountState() {
|
|
330
|
+
const secondsLeft = Number(this.lendingStatus.secondsLeftOnLoan);
|
|
331
|
+
|
|
330
332
|
const timerCountdown = this.shadowRoot.querySelector('timer-countdown');
|
|
331
333
|
const animationCircle = timerCountdown.shadowRoot.querySelector('.circle');
|
|
332
334
|
|
|
335
|
+
// the perimeter of the circle
|
|
336
|
+
const circleStroke = 315; // (π * 2 * radius)
|
|
337
|
+
const strokeDashOffset =
|
|
338
|
+
(secondsLeft / this.loanRenewConfig.totalTime) *
|
|
339
|
+
circleStroke;
|
|
340
|
+
|
|
341
|
+
// set seconds left in loan expire
|
|
342
|
+
timerCountdown.style?.setProperty(
|
|
343
|
+
'--timerSeconds',
|
|
344
|
+
`${secondsLeft}s`
|
|
345
|
+
);
|
|
346
|
+
// set circle stroke offset left in loan expire
|
|
333
347
|
timerCountdown.style?.setProperty(
|
|
334
|
-
'--
|
|
335
|
-
`${Number(
|
|
348
|
+
'--timerStroke',
|
|
349
|
+
`${Number(strokeDashOffset)}`
|
|
336
350
|
);
|
|
337
351
|
|
|
338
352
|
animationCircle.style.animationName = 'none';
|