@internetarchive/ia-book-actions 0.1.11-b2 → 0.1.11-b3

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.1.11-b2",
3
+ "version": "0.1.11-b3",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -300,6 +300,7 @@ export default class ActionsHandler extends LitElement {
300
300
  * set browse time in indexedDB
301
301
  */
302
302
  async setBrowseTimeSession() {
303
+ // TODO: USE loan info to determine what we have left
303
304
  try {
304
305
  const expireDate = new Date(
305
306
  new Date().getTime() + this.loanTotalTime * 1000
@@ -100,13 +100,17 @@ export default class IABookActions extends LitElement {
100
100
 
101
101
  /**
102
102
  * contains one hour auto-loan-renew time configuration
103
- *
104
- * @type {object} loanRenewTimeConfig
105
- * @property {number} loanTotalTime - total seconds a loan does have
106
- * @property {number} loanRenewAtLast - check for loan renew at last
107
- * @property {number} pageChangedInLast - consider loan renew eligible if viewed new page
108
- */
109
- this.loanRenewTimeConfig = {};
103
+ * defaults to 1 hour config
104
+ * @type {{
105
+ * loanTotalTime: number, - total seconds a loan does have
106
+ * loanRenewAtLast: number, - check for loan renew at last
107
+ * pageChangedInLast: number, - consider loan renew eligible if viewed new page
108
+ */
109
+ this.loanRenewTimeConfig = {
110
+ loanTotalTime: 3600, // 1 hour
111
+ loanRenewAtLast: 660, // 11 minutes
112
+ pageChangedInLast: 900, // 15 minutes
113
+ };
110
114
 
111
115
  /**
112
116
  * contains one hour auto-loan-renew response
@@ -253,6 +257,7 @@ export default class IABookActions extends LitElement {
253
257
  // initial timer state for 1-hour loan
254
258
  if (this.borrowType === 'browsed' && !this.loanRenewResult.renewNow) {
255
259
  setTimeout(() => {
260
+ console.log('IN TIMEOUT OF --- setupLendingToolbarActions, firing resetTimerCountState');
256
261
  this.resetTimerCountState();
257
262
  }, 100);
258
263
  }
@@ -478,21 +483,6 @@ export default class IABookActions extends LitElement {
478
483
  });
479
484
  }
480
485
 
481
- async browseHasRenew() {
482
- window?.IALendingIntervals?.clearAll();
483
-
484
- const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
485
- const secondsLeft = (loanTime - new Date()) / 1000; // different in seconds
486
-
487
- const currStatus = {
488
- ...this.lendingStatus,
489
- user_has_browsed: true,
490
- browsingExpired: false,
491
- secondsLeftOnLoan: secondsLeft,
492
- };
493
- this.lendingStatus = currStatus;
494
- }
495
-
496
486
  /**
497
487
  * Execute when loan is expired
498
488
  */
@@ -543,11 +533,11 @@ export default class IABookActions extends LitElement {
543
533
  const timerCountdown = this._shadowRoot.querySelector('timer-countdown');
544
534
  if (!timerCountdown) return;
545
535
 
546
- const secondsLeft = Number(this.lendingStatus.secondsLeftOnLoan);
536
+ const secondsLeft = Number.parseInt((Number(this.lendingStatus.secondsLeftOnLoan)), 10);
547
537
  const strokeDashOffset =
548
538
  (secondsLeft / this.loanRenewTimeConfig.loanTotalTime) * 315;
549
539
 
550
- console.log('resetTimerCountState === ', secondsLeft);
540
+ console.log('resetTimerCountState === ', { secondsLeft, strokeDashOffset});
551
541
 
552
542
  // set seconds left in loan expire
553
543
  timerCountdown.style?.setProperty('--secondsLeftOnLoan', `${secondsLeft}s`);
@@ -635,14 +625,26 @@ export default class IABookActions extends LitElement {
635
625
  console.log('IABookActions: AutoRenewed:- ', {
636
626
  ajaxResponse: event?.detail?.data,
637
627
  loanRenewResult: this.loanRenewResult,
638
- secondsLeftOnLoan: Math.round(this.lendingStatus.secondsLeftOnLoan),
628
+ secondsLeftOnLoan: Math.round(this.lendingStatus.secondsLeftOnLoan), // stale? how to fix
639
629
  });
640
630
 
641
- /**
642
- * update the lendingStatus property
643
- */
644
- await this.browseHasRenew();
645
631
 
632
+ // Now, let's reset loan duration & this.lendingStatus
633
+ const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
634
+ const secondsLeft = (loanTime - new Date()) / 1000; // different in seconds
635
+
636
+ const currStatus = {
637
+ ...this.lendingStatus,
638
+ user_has_browsed: true,
639
+ browsingExpired: false,
640
+ secondsLeftOnLoan: secondsLeft,
641
+ };
642
+ this.lendingStatus = currStatus;
643
+
644
+ console.log('~~~ handleLoanAutoRenewed - new this.lendingStatus', {
645
+ secondsLeftOnLoan: this.lendingStatus.secondsLeftOnLoan
646
+ });
647
+
646
648
  /**
647
649
  * reset timer countdown states
648
650
  */
@@ -673,9 +675,11 @@ export default class IABookActions extends LitElement {
673
675
  secondsLeft = Math.round(secondsLeft); // round number
674
676
 
675
677
  // re-sync timer if gone off because of background window
678
+ // side effect: updates this.lendingStatus & kicks off lifecycle,
679
+ // if really updated, escape from here
676
680
  const resync = await this.reSyncTimerIfGoneOff(secondsLeft);
677
681
 
678
- console.log("*** startTimerCountdown ***", secondsLeft, resync);
682
+ console.log("*** startTimerCountdown = reSyncTimerIfGoneOff ***", { secondsLeft, resync });
679
683
 
680
684
  if (resync) {
681
685
  console.log('have resyncd, will end startTimerCountdown here - ');