@internetarchive/ia-book-actions 0.0.29-alpha2 → 0.0.29-alpha21

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.
@@ -1,58 +0,0 @@
1
- import { css } from 'lit';
2
-
3
- export default timerCountDownStyle = css`
4
- :host {
5
- right: 5px;
6
- font-size: 14px;
7
- position: absolute;
8
- }
9
- #countdown1 {
10
- position: relative;
11
- margin: auto;
12
- margin-top: 100px;
13
- height: 40px;
14
- width: 40px;
15
- text-align: center;
16
- }
17
-
18
- #countdown-number {
19
- color: white;
20
- display: inline-block;
21
- line-height: 40px;
22
- margin-right: 12px;
23
- }
24
-
25
- svg {
26
- position: absolute;
27
- top: 0;
28
- right: 0;
29
- width: 40px;
30
- height: 40px;
31
- transform: rotateY(-180deg) rotateZ(-90deg);
32
- }
33
-
34
- svg circle {
35
- stroke-dasharray: 113px;
36
- stroke-dashoffset: 0px;
37
- stroke-linecap: round;
38
- stroke-width: 3px;
39
- stroke: white;
40
- fill: none;
41
- animation: countdown 60s linear infinite forwards;
42
- }
43
-
44
- @keyframes countdown {
45
- from {
46
- stroke-dashoffset: 0px;
47
- }
48
- to {
49
- stroke-dashoffset: 113px;
50
- }
51
- }
52
- .hidden {
53
- display: none;
54
- }
55
- .visible {
56
- display: inline-block;
57
- }
58
- `;
@@ -1,60 +0,0 @@
1
- import { html, css, LitElement, nothing } from 'lit';
2
-
3
- export class ToastMessage extends LitElement {
4
- static get properties() {
5
- return {
6
- texts: { type: String },
7
- dismisOnClick: { type: Function },
8
- hideToast: { type: Boolean },
9
- };
10
- }
11
-
12
- constructor() {
13
- super();
14
- this.texts = '';
15
- this.textClass = '';
16
- this.hideToast = false;
17
- }
18
-
19
- render() {
20
- return !this.hideToast
21
- ? html`
22
- <span class="toast-message ${this.textClass}">${this.texts}</span>
23
- `
24
- : nothing;
25
- }
26
-
27
- static get styles() {
28
- const heightFromTop = css`var(--messageHeightFromTop, 15%)`;
29
-
30
- return css`
31
- :host {
32
- display: inline-block;
33
- }
34
- .toast-message {
35
- z-index: 2;
36
- position: absolute;
37
- top: ${heightFromTop};
38
- font-size: 1.4rem;
39
- color: #fff;
40
- left: 50%;
41
- right: 50%;
42
- background: #333;
43
- border: 1px solid #fff;
44
- border-radius: 5px;
45
- box-shadow: 1px 1px 2px;
46
- padding: 10px;
47
- width: fit-content;
48
- transform: translate(-50%, -50%);
49
- }
50
- .hidden {
51
- display: none;
52
- }
53
- .visible {
54
- display: inline-block;
55
- }
56
- `;
57
- }
58
- }
59
-
60
- window.customElements.define('toast-message', ToastMessage);
@@ -1,148 +0,0 @@
1
- import ActionsHandlerService from './actions-handler/actions-handler-service.js';
2
-
3
- /**
4
- * This class is used to determine if use is eligible for auto renew loan.
5
- *
6
- * ActionsHandlerService is a function being used to execute
7
- */
8
- export class OneHourAutoRenew {
9
- constructor(pageClick, identifier, localCache, autoRenewTimeConfig, userHasBrowsed) {
10
- this.pageClick = pageClick;
11
- this.identifier = identifier;
12
- this.localCache = localCache;
13
- this.autoRenewTimeConfig = autoRenewTimeConfig;
14
- this.userHasBrowsed = userHasBrowsed;
15
-
16
- // private props
17
- this.resultRes = {
18
- toastTexts: null,
19
- hideToast: true,
20
- renewNow: false,
21
- };
22
-
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
- return this.handleBookAutoRenew();
29
- }
30
-
31
- async handleBookAutoRenew() {
32
- try {
33
- // if page is not flipped in last 15 minutes,
34
- // instantaly renew it if user viewed new page in last 10 minutes
35
- if (this.pageClick) {
36
- console.log('page flipped!')
37
- this.setPageFlippedTime();
38
- return this.userFlippedBookPage(); // user clicked on page
39
- } else {
40
- console.log('auto checker!')
41
- return this.autoCheckerTimer(); // auto checker at 50th minute
42
- }
43
-
44
- } catch (error) {
45
- console.log(error)
46
- }
47
- }
48
-
49
- async setPageFlippedTime() {
50
- // set pageFlipTime time in localStorage
51
- await this.localCache.set({
52
- key: `${this.identifier}-pageFlipTime`,
53
- value: new Date(), // current time
54
- ttl: parseInt(this.autoRenewTimeConfig.totalTime),
55
- })
56
- }
57
-
58
- async userFlippedBookPage() {
59
- const {
60
- totalTime, // 60
61
- autoCheckAt, // 50
62
- } = this.autoRenewTimeConfig;
63
- const currentDate = new Date();
64
- const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
65
-
66
- const lastTimeFrame = await this.changeTime(
67
- loanTime,
68
- totalTime - autoCheckAt,
69
- 'add'
70
- ); // 50 seconds
71
-
72
- if (currentDate >= lastTimeFrame) {
73
- console.log('1 YES NOW BORROW IT AGAIN NOW!');
74
- this.resultRes.toastTexts = this.autoRenewMessage;
75
- this.resultRes.browseAgainNow = true;
76
- this.resultRes.hideToast = false;
77
- this.resultRes.renewNow = true;
78
- }
79
-
80
- return this.resultRes;
81
- }
82
-
83
- async autoCheckerTimer() {
84
- const currentDate = new Date();
85
- const { FlippedInLast } = this.autoRenewTimeConfig;
86
- const lastPageFlipTime = await this.localCache.get(`${this.identifier}-pageFlipTime`);
87
-
88
- // last 15 min if used flipped a page.
89
- const lastFlipTimeFrame = await this.changeTime(
90
- currentDate,
91
- FlippedInLast,
92
- 'sub'
93
- ); // 15 seconds
94
-
95
- if (lastPageFlipTime === undefined || lastPageFlipTime <= lastFlipTimeFrame) { // not viewed
96
- console.log('2');
97
- this.resultRes.toastTexts = this.autoReturnWarning;
98
- this.resultRes.hideToast = false;
99
- } else if (lastPageFlipTime >= lastFlipTimeFrame) { // viewed in last time frame
100
- console.log('3');
101
- this.resultRes.toastTexts = this.autoRenewMessage;
102
- this.resultRes.browseAgainNow = true;
103
- this.resultRes.hideToast = false;
104
- this.resultRes.renewNow = true;
105
- }
106
-
107
- return this.resultRes;
108
- }
109
-
110
- async changeTime(date, minutes, op) {
111
- if (date === undefined) return undefined;
112
-
113
- if (op === 'sub') {
114
- return new Date(date.getTime() - minutes * 1000);
115
- }
116
-
117
- return new Date(date.getTime() + minutes * 1000);
118
- }
119
-
120
-
121
- sendEvent(eventCategory, eventAction) {
122
- window?.archive_analytics?.send_event(
123
- eventCategory,
124
- eventAction,
125
- `identifier=${this.identifier}`
126
- );
127
- }
128
-
129
- async handleAutoRenew() {
130
- const action = 'renew_loan';
131
- ActionsHandlerService({
132
- identifier: this.identifier,
133
- action,
134
- error: data => {
135
- window?.Sentry?.captureMessage(
136
- 'handleAutoRenew error',
137
- JSON.stringify(data)
138
- );
139
- // this.errorCallback({ detail: { action, data } });
140
- // send LendingServiceError to GA
141
- this.sendEvent('handleAutoRenew', action);
142
- },
143
- success: () => {
144
- return 'success';
145
- },
146
- });
147
- }
148
- }