@internetarchive/ia-book-actions 0.0.29-alpha3 → 0.0.29-alpha4
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
|
@@ -128,13 +128,13 @@
|
|
|
128
128
|
iaBookActions.returnUrl = 'https://openlibrary.org';
|
|
129
129
|
iaBookActions.localCache = localCache;
|
|
130
130
|
iaBookActions.autoRenewConfig = {
|
|
131
|
-
totalTime:
|
|
132
|
-
autoCheckAt:
|
|
131
|
+
totalTime: 10, // 60 second = 1 min
|
|
132
|
+
autoCheckAt: 8, // totalTime - 10th minute
|
|
133
133
|
FlippedInLast: 15, // within last 15 second/minute
|
|
134
134
|
};
|
|
135
135
|
|
|
136
136
|
let lendingStatus1 = iaBookActions.lendingStatus;
|
|
137
|
-
let secondsLeftOnLoan =
|
|
137
|
+
let secondsLeftOnLoan = iaBookActions.autoRenewConfig.totalTime;
|
|
138
138
|
|
|
139
139
|
document.querySelectorAll('.titleBar input[type=checkbox]').forEach((item) => {
|
|
140
140
|
item.addEventListener('click', (e) => {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ export class ToastMessage extends LitElement {
|
|
|
4
4
|
static get properties() {
|
|
5
5
|
return {
|
|
6
6
|
texts: { type: String },
|
|
7
|
-
dismisOnClick: { type:
|
|
7
|
+
dismisOnClick: { type: Boolean },
|
|
8
8
|
hideToast: { type: Boolean },
|
|
9
9
|
};
|
|
10
10
|
}
|
|
@@ -19,7 +19,11 @@ export class ToastMessage extends LitElement {
|
|
|
19
19
|
render() {
|
|
20
20
|
return !this.hideToast
|
|
21
21
|
? html`
|
|
22
|
-
<span
|
|
22
|
+
<span
|
|
23
|
+
class="toast-message fade-in ${this.textClass}"
|
|
24
|
+
title="Click/tap to close"
|
|
25
|
+
@click=${() => { this.dismisOnClick ? this.hideToast = true : nothing}}
|
|
26
|
+
>${this.texts}</span>
|
|
23
27
|
`
|
|
24
28
|
: nothing;
|
|
25
29
|
}
|
|
@@ -30,15 +34,16 @@ export class ToastMessage extends LitElement {
|
|
|
30
34
|
return css`
|
|
31
35
|
:host {
|
|
32
36
|
display: inline-block;
|
|
37
|
+
|
|
33
38
|
}
|
|
34
39
|
.toast-message {
|
|
35
40
|
z-index: 2;
|
|
36
41
|
position: absolute;
|
|
37
42
|
top: ${heightFromTop};
|
|
38
43
|
font-size: 1.4rem;
|
|
44
|
+
font-family: "Helvetica Neue";
|
|
39
45
|
color: #fff;
|
|
40
46
|
left: 50%;
|
|
41
|
-
right: 50%;
|
|
42
47
|
background: #333;
|
|
43
48
|
border: 1px solid #fff;
|
|
44
49
|
border-radius: 5px;
|
|
@@ -46,7 +51,18 @@ export class ToastMessage extends LitElement {
|
|
|
46
51
|
padding: 10px;
|
|
47
52
|
width: fit-content;
|
|
48
53
|
transform: translate(-50%, -50%);
|
|
54
|
+
cursor: pointer;
|
|
55
|
+
animation: fadeIn 5s;
|
|
56
|
+
@keyframes fadeIn {
|
|
57
|
+
0% {
|
|
58
|
+
opacity: 0;
|
|
59
|
+
}
|
|
60
|
+
100% {
|
|
61
|
+
opacity: 1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
49
64
|
}
|
|
65
|
+
|
|
50
66
|
.hidden {
|
|
51
67
|
display: none;
|
|
52
68
|
}
|
|
@@ -127,14 +127,18 @@ export default class ActionsHandler extends LitElement {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
handleAutoBrowseIt() {
|
|
130
|
-
const action = '
|
|
130
|
+
const action = 'renew_loan';
|
|
131
131
|
this.setBrowseTimeSession()
|
|
132
132
|
|
|
133
133
|
ActionsHandlerService({
|
|
134
134
|
action,
|
|
135
135
|
identifier: this.identifier,
|
|
136
|
-
success: () => {
|
|
136
|
+
success: () => {
|
|
137
|
+
console.log('success!');
|
|
138
|
+
},
|
|
137
139
|
error: data => {
|
|
140
|
+
console.log(data);
|
|
141
|
+
console.log('error!');
|
|
138
142
|
this.dispatchActionError(action, data);
|
|
139
143
|
},
|
|
140
144
|
});
|
|
@@ -13,18 +13,18 @@ export class OneHourAutoRenew {
|
|
|
13
13
|
this.autoRenewConfig = autoRenewConfig;
|
|
14
14
|
this.userHasBrowsed = userHasBrowsed;
|
|
15
15
|
|
|
16
|
+
// messages for auto return machenism
|
|
17
|
+
this.autoRenewMessage = 'This book has been renewed for another hour.';
|
|
18
|
+
this.autoReturnMessage = 'This book has been auto-returned due to inactivity.';
|
|
19
|
+
this.autoReturnWarning = 'This book will be auto-returned in 10 minutes unless you turn a page.';
|
|
20
|
+
|
|
16
21
|
// private props
|
|
17
22
|
this.resultRes = {
|
|
18
|
-
toastTexts:
|
|
23
|
+
toastTexts: this.autoReturnMessage,
|
|
19
24
|
hideToast: true,
|
|
20
25
|
renewNow: false,
|
|
21
26
|
};
|
|
22
27
|
|
|
23
|
-
// messages for auto return machenism
|
|
24
|
-
this.autoRenewMessage = 'This book has been renewed for another hour.';
|
|
25
|
-
this.autoReturnMessage = 'This book has been auto-returned due to inactivity.';
|
|
26
|
-
this.autoReturnWarning = 'This book will be auto-returned in 10 minutes unless you turn a page.';
|
|
27
|
-
|
|
28
28
|
return this.handleBookAutoRenew();
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -144,6 +144,7 @@ export class OneHourAutoRenew {
|
|
|
144
144
|
this.sendEvent('handleAutoRenew', action);
|
|
145
145
|
},
|
|
146
146
|
success: () => {
|
|
147
|
+
console.log('success!');
|
|
147
148
|
return 'success';
|
|
148
149
|
},
|
|
149
150
|
});
|
package/src/ia-book-actions.js
CHANGED
|
@@ -70,6 +70,7 @@ export default class IABookActions extends LitElement {
|
|
|
70
70
|
namespace: '1HourLoanStorage'
|
|
71
71
|
}),
|
|
72
72
|
this.autoRenewConfig = {},
|
|
73
|
+
this.autoRenewObj = undefined;
|
|
73
74
|
|
|
74
75
|
// private props
|
|
75
76
|
this.primaryActions = [];
|
|
@@ -101,6 +102,7 @@ export default class IABookActions extends LitElement {
|
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
updated(changed) {
|
|
105
|
+
console.log(changed)
|
|
104
106
|
if (changed.has('lendingStatus') || changed.has('bwbPurchaseUrl')) {
|
|
105
107
|
this.setupLendingToolbarActions();
|
|
106
108
|
this.update();
|
|
@@ -120,7 +122,7 @@ export default class IABookActions extends LitElement {
|
|
|
120
122
|
this.addEventListener('autoRenewAttempt', async event => {
|
|
121
123
|
const isPageFlipped = event.detail.bookPageChange;
|
|
122
124
|
|
|
123
|
-
|
|
125
|
+
this.autoRenewObj = await new OneHourAutoRenew(
|
|
124
126
|
isPageFlipped,
|
|
125
127
|
this.identifier,
|
|
126
128
|
this.localCache,
|
|
@@ -128,13 +130,12 @@ export default class IABookActions extends LitElement {
|
|
|
128
130
|
this.lendingStatus.user_has_browsed && !this.lendingStatus.browsingExpired
|
|
129
131
|
);
|
|
130
132
|
|
|
131
|
-
this.toastTexts =
|
|
132
|
-
this.hideToast =
|
|
133
|
-
this.browseAgainNow =
|
|
133
|
+
this.toastTexts = this.autoRenewObj.toastTexts;
|
|
134
|
+
this.hideToast = this.autoRenewObj.hideToast;
|
|
135
|
+
this.browseAgainNow = this.autoRenewObj.renewNow;
|
|
134
136
|
if (this.browseAgainNow) {
|
|
135
137
|
await this.browseHasRenew();
|
|
136
138
|
}
|
|
137
|
-
// this.handleBookAutoRenew(event);
|
|
138
139
|
});
|
|
139
140
|
}
|
|
140
141
|
|
|
@@ -147,7 +148,7 @@ export default class IABookActions extends LitElement {
|
|
|
147
148
|
await this.localCache.delete(`${this.identifier}-pageFlipTime`);
|
|
148
149
|
|
|
149
150
|
// show message after browsed book is expired.
|
|
150
|
-
this.toastTexts =
|
|
151
|
+
this.toastTexts = 'This book has been auto-returned due to inactivity.';
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
async browseHasRenew() {
|
|
@@ -155,7 +156,7 @@ export default class IABookActions extends LitElement {
|
|
|
155
156
|
...this.lendingStatus,
|
|
156
157
|
user_has_browsed: true,
|
|
157
158
|
browsingExpired: false,
|
|
158
|
-
secondsLeftOnLoan:
|
|
159
|
+
secondsLeftOnLoan: this.autoRenewConfig.totalTime + 1,
|
|
159
160
|
};
|
|
160
161
|
this.lendingStatus = currStatus;
|
|
161
162
|
|
|
@@ -301,7 +302,7 @@ export default class IABookActions extends LitElement {
|
|
|
301
302
|
return html`
|
|
302
303
|
<toast-message
|
|
303
304
|
.texts=${this.toastTexts}
|
|
304
|
-
|
|
305
|
+
?dismisOnClick=${true}
|
|
305
306
|
?hideToast=${this.hideToast}
|
|
306
307
|
></toast-message>
|
|
307
308
|
`;
|