@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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.29-alpha21",
3
+ "version": "0.0.29-alpha22",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -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: 3591,
121
+ secondsLeftOnLoan: 12,
122
122
  shouldProtectImages: true,
123
123
  totalWaitlistCount: 0,
124
124
  userHasBorrowed: false,
@@ -49,12 +49,6 @@ export class InfoIcon extends LitElement {
49
49
  vertical-align: middle;
50
50
  background: white;
51
51
  }
52
- .more-info-icon.mobile {
53
- position: absolute;
54
- top: 4px;
55
- right: 55px;
56
- margin-top: 15px;
57
- }
58
52
  .hidden {
59
53
  display: none;
60
54
  }
@@ -58,8 +58,8 @@ export default class TimerCountdown extends LitElement {
58
58
  render() {
59
59
  return html`
60
60
  <svg
61
- width="30"
62
- height="30"
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 secondsLeft = css`var(--secondsLeft, 60s)`;
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: 320;
85
- stroke-dasharray: 320;
84
+ stroke-dashoffset: ${timerStrokeLeft};
85
+ stroke-dasharray: 315;
86
86
  }
87
87
  100% {
88
88
  stroke-dashoffset: 0;
89
- stroke-dasharray: 320;
89
+ stroke-dasharray: 315;
90
90
  }
91
91
  }
92
92
 
93
93
  svg {
94
- background-color: transparent;
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: translate(-50%, -50%) rotateZ(-90deg);
97
+ transform: rotateZ(-90deg);
101
98
  }
102
99
 
103
100
  svg .circle {
104
- stroke: ${white};
101
+ stroke: #000;
105
102
  stroke-width: 100px;
106
- fill: transparent;
107
- stroke-dashoffset: 320;
103
+ fill: ${white};
104
+ stroke-dashoffset: 315;
108
105
  stroke-dasharray: 0;
109
- animation: ${secondsLeft} circletimer linear;
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 nothing;
151
+ if (date === undefined) return null;
152
152
 
153
153
  if (op === 'sub') {
154
154
  return new Date(date.getTime() - minutes * 1000);
@@ -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
- // early return if book is not browsed (1 hour borrow)
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
- '--secondsLeft',
335
- `${Number(this.lendingStatus.secondsLeftOnLoan)}s`
348
+ '--timerStroke',
349
+ `${Number(strokeDashOffset)}`
336
350
  );
337
351
 
338
352
  animationCircle.style.animationName = 'none';