@internetarchive/ia-book-actions 0.0.29-alpha2 → 0.0.29-alpha3
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
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
iaBookActions.tokenDelay = 2000; // 2 seconds
|
|
128
128
|
iaBookActions.returnUrl = 'https://openlibrary.org';
|
|
129
129
|
iaBookActions.localCache = localCache;
|
|
130
|
-
iaBookActions.
|
|
130
|
+
iaBookActions.autoRenewConfig = {
|
|
131
131
|
totalTime: 60, // 60 second = 1 min
|
|
132
132
|
autoCheckAt: 55, // totalTime - 10th minute
|
|
133
133
|
FlippedInLast: 15, // within last 15 second/minute
|
|
@@ -226,7 +226,7 @@
|
|
|
226
226
|
await localCache.set({
|
|
227
227
|
key: `${identifier}-loanTime`,
|
|
228
228
|
value: new Date(), // current time
|
|
229
|
-
ttl: parseInt(iaBookActions.
|
|
229
|
+
ttl: parseInt(iaBookActions.autoRenewConfig.totalTime),
|
|
230
230
|
})
|
|
231
231
|
|
|
232
232
|
await localCache.delete(`${identifier}-pageFlipTime`);
|
package/package.json
CHANGED
|
@@ -29,7 +29,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
29
29
|
disabled: { type: Boolean },
|
|
30
30
|
returnUrl: { type: String },
|
|
31
31
|
browseAgainNow: { type: Boolean },
|
|
32
|
-
|
|
32
|
+
autoRenewConfig: { type: Object },
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -50,7 +50,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
50
50
|
this.disabled = false;
|
|
51
51
|
this.returnUrl = '';
|
|
52
52
|
this.browseAgainNow = false;
|
|
53
|
-
this.
|
|
53
|
+
this.autoRenewConfig = {};
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
updated(changed) {
|
|
@@ -19,7 +19,7 @@ export default class ActionsHandler extends LitElement {
|
|
|
19
19
|
this.identifier = '';
|
|
20
20
|
this.ajaxTimeout = 6000;
|
|
21
21
|
this.returnUrl = '';
|
|
22
|
-
this.
|
|
22
|
+
this.autoRenewConfig = {};
|
|
23
23
|
|
|
24
24
|
this.localCache = new LocalCache({
|
|
25
25
|
namespace: '1HourLoanStorage',
|
|
@@ -317,7 +317,7 @@ export default class ActionsHandler extends LitElement {
|
|
|
317
317
|
await this.localCache.set({
|
|
318
318
|
key: `${this.identifier}-loanTime`,
|
|
319
319
|
value: new Date(), // current time
|
|
320
|
-
ttl: parseInt(this.
|
|
320
|
+
ttl: parseInt(this.autoRenewConfig.totalTime),
|
|
321
321
|
})
|
|
322
322
|
|
|
323
323
|
await this.localCache.delete(`${this.identifier}-pageFlipTime`);
|
|
@@ -6,11 +6,11 @@ import ActionsHandlerService from './actions-handler/actions-handler-service.js'
|
|
|
6
6
|
* ActionsHandlerService is a function being used to execute
|
|
7
7
|
*/
|
|
8
8
|
export class OneHourAutoRenew {
|
|
9
|
-
constructor(pageClick, identifier, localCache,
|
|
9
|
+
constructor(pageClick, identifier, localCache, autoRenewConfig, userHasBrowsed) {
|
|
10
10
|
this.pageClick = pageClick;
|
|
11
11
|
this.identifier = identifier;
|
|
12
12
|
this.localCache = localCache;
|
|
13
|
-
this.
|
|
13
|
+
this.autoRenewConfig = autoRenewConfig;
|
|
14
14
|
this.userHasBrowsed = userHasBrowsed;
|
|
15
15
|
|
|
16
16
|
// private props
|
|
@@ -51,7 +51,7 @@ export class OneHourAutoRenew {
|
|
|
51
51
|
await this.localCache.set({
|
|
52
52
|
key: `${this.identifier}-pageFlipTime`,
|
|
53
53
|
value: new Date(), // current time
|
|
54
|
-
ttl: parseInt(this.
|
|
54
|
+
ttl: parseInt(this.autoRenewConfig.totalTime),
|
|
55
55
|
})
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -59,7 +59,7 @@ export class OneHourAutoRenew {
|
|
|
59
59
|
const {
|
|
60
60
|
totalTime, // 60
|
|
61
61
|
autoCheckAt, // 50
|
|
62
|
-
} = this.
|
|
62
|
+
} = this.autoRenewConfig;
|
|
63
63
|
const currentDate = new Date();
|
|
64
64
|
const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
|
|
65
65
|
|
|
@@ -82,7 +82,7 @@ export class OneHourAutoRenew {
|
|
|
82
82
|
|
|
83
83
|
async autoCheckerTimer() {
|
|
84
84
|
const currentDate = new Date();
|
|
85
|
-
const { FlippedInLast } = this.
|
|
85
|
+
const { FlippedInLast } = this.autoRenewConfig;
|
|
86
86
|
const lastPageFlipTime = await this.localCache.get(`${this.identifier}-pageFlipTime`);
|
|
87
87
|
|
|
88
88
|
// last 15 min if used flipped a page.
|
|
@@ -93,15 +93,18 @@ export class OneHourAutoRenew {
|
|
|
93
93
|
); // 15 seconds
|
|
94
94
|
|
|
95
95
|
if (lastPageFlipTime === undefined || lastPageFlipTime <= lastFlipTimeFrame) { // not viewed
|
|
96
|
-
console.log('2');
|
|
96
|
+
console.log('2 not viewed, warning message!');
|
|
97
97
|
this.resultRes.toastTexts = this.autoReturnWarning;
|
|
98
98
|
this.resultRes.hideToast = false;
|
|
99
99
|
} else if (lastPageFlipTime >= lastFlipTimeFrame) { // viewed in last time frame
|
|
100
|
-
console.log('3');
|
|
100
|
+
console.log('3 viewed, auto renew and message!');
|
|
101
101
|
this.resultRes.toastTexts = this.autoRenewMessage;
|
|
102
102
|
this.resultRes.browseAgainNow = true;
|
|
103
103
|
this.resultRes.hideToast = false;
|
|
104
104
|
this.resultRes.renewNow = true;
|
|
105
|
+
|
|
106
|
+
// delete pageFlipTime when book is auto renew at nth minute
|
|
107
|
+
await this.localCache.delete(`${this.identifier}-pageFlipTime`);
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
return this.resultRes;
|
package/src/ia-book-actions.js
CHANGED
|
@@ -45,7 +45,7 @@ export default class IABookActions extends LitElement {
|
|
|
45
45
|
remainingTime: { type: Number },
|
|
46
46
|
resetTimerCountdown: { type: Boolean },
|
|
47
47
|
localCache: { type: Object },
|
|
48
|
-
|
|
48
|
+
autoRenewConfig: { type: Object },
|
|
49
49
|
browseAgainNow: { type: Boolean },
|
|
50
50
|
};
|
|
51
51
|
}
|
|
@@ -69,7 +69,7 @@ export default class IABookActions extends LitElement {
|
|
|
69
69
|
this.localCache = new LocalCache({
|
|
70
70
|
namespace: '1HourLoanStorage'
|
|
71
71
|
}),
|
|
72
|
-
this.
|
|
72
|
+
this.autoRenewConfig = {},
|
|
73
73
|
|
|
74
74
|
// private props
|
|
75
75
|
this.primaryActions = [];
|
|
@@ -124,7 +124,7 @@ export default class IABookActions extends LitElement {
|
|
|
124
124
|
isPageFlipped,
|
|
125
125
|
this.identifier,
|
|
126
126
|
this.localCache,
|
|
127
|
-
this.
|
|
127
|
+
this.autoRenewConfig,
|
|
128
128
|
this.lendingStatus.user_has_browsed && !this.lendingStatus.browsingExpired
|
|
129
129
|
);
|
|
130
130
|
|
|
@@ -291,7 +291,7 @@ export default class IABookActions extends LitElement {
|
|
|
291
291
|
return this.borrowType === 'browsed'
|
|
292
292
|
? html`<timer-countdown
|
|
293
293
|
time=${Number(this.remainingTime)}
|
|
294
|
-
.autoCheckAt=${this.
|
|
294
|
+
.autoCheckAt=${this.autoRenewConfig.autoCheckAt}
|
|
295
295
|
?resetTimerCountdown=${this.resetTimerCountdown}
|
|
296
296
|
></timer-countdown>`
|
|
297
297
|
: nothing;
|
|
@@ -320,7 +320,7 @@ export default class IABookActions extends LitElement {
|
|
|
320
320
|
.borrowType=${this.borrowType}
|
|
321
321
|
.returnUrl=${this.returnUrl}
|
|
322
322
|
.autoRenew=${this.autoRenew}
|
|
323
|
-
.
|
|
323
|
+
.autoRenewConfig=${this.autoRenewConfig}
|
|
324
324
|
?hasAdminAccess=${this.hasAdminAccess}
|
|
325
325
|
?disabled=${this.disableActionGroup}
|
|
326
326
|
?browseAgainNow=${this.browseAgainNow}
|