@@ -6,14 +6,15 @@ import { route } from 'laroute';
6
6
import { debounce } from 'lodash' ;
7
7
import { fadeToggle } from 'utils/fade' ;
8
8
import { toggleCart } from 'utils/store-cart' ;
9
+ import StoreSupporterTagPrice , { durationToPrice } from 'utils/store-supporter-tag-price' ;
9
10
import { present } from 'utils/string' ;
10
11
11
12
const maxValue = 52 ;
12
13
const minValue = 4 ;
13
14
const resolution = 8 ;
14
15
15
16
export default class StoreSupporterTag {
16
- private cost = 0 ;
17
+ private cost ;
17
18
private readonly debouncedGetUser ;
18
19
19
20
@@ -51,7 +52,7 @@ export default class StoreSupporterTag {
51
52
}
52
53
} ) ;
53
54
54
- this . cost = this . calculate ( this . initializeSlider ( ) . slider ( 'value' ) ) ;
55
+ this . cost = this . calculate ( + this . initializeSlider ( ) . slider ( 'value' ) ) ;
55
56
this . initializeSliderPresets ( ) ;
56
57
this . initializeUsernameInput ( ) ;
57
58
this . updateCostDisplay ( ) ;
@@ -73,8 +74,8 @@ export default class StoreSupporterTag {
73
74
}
74
75
}
75
76
76
- private calculate ( position : number ) : number {
77
- return new window . StoreSupporterTagPrice ( Math . floor ( position / resolution ) ) ;
77
+ private calculate ( position : number ) {
78
+ return new StoreSupporterTagPrice ( Math . floor ( position / resolution ) ) ;
78
79
}
79
80
80
81
private readonly getUser = ( username : string ) => {
@@ -121,7 +122,7 @@ export default class StoreSupporterTag {
121
122
private initializeSliderPresets ( ) {
122
123
$ ( this . sliderPresets ) . on ( 'click' , ( event ) => {
123
124
const target = event . currentTarget ;
124
- const price = StoreSupporterTagPrice . durationToPrice ( target . dataset . months ) as ( number | undefined ) ;
125
+ const price = durationToPrice ( + ( target . dataset ? .months ?? 0 ) ) ;
125
126
if ( price != null ) {
126
127
$ ( this . slider ) . slider ( 'value' , this . sliderValue ( price ) ) ;
127
128
}
@@ -152,10 +153,10 @@ export default class StoreSupporterTag {
152
153
}
153
154
154
155
private updateCostDisplay ( ) {
155
- this . el . querySelector ( 'input[name="item[cost]"]' ) . value = this . cost . price ( ) ;
156
- this . priceElement . textContent = `USD ${ this . cost . price ( ) } ` ;
157
- this . durationElement . textContent = this . cost . durationText ( ) ;
158
- this . discountElement . textContent = this . cost . discountText ( ) ;
156
+ this . el . querySelector < HTMLElement > ( 'input[name="item[cost]"]' ) . value = this . cost . price ;
157
+ this . priceElement . textContent = `USD ${ this . cost . price } ` ;
158
+ this . durationElement . textContent = this . cost . durationText ;
159
+ this . discountElement . textContent = this . cost . discountText ;
159
160
for ( const elem of this . sliderPresets ) {
160
161
this . updateSliderPreset ( elem , this . cost ) ;
161
162
}
@@ -167,8 +168,8 @@ export default class StoreSupporterTag {
167
168
this . updateUserInteraction ( ) ;
168
169
} ;
169
170
170
- private updateSliderPreset ( elem : HTMLElement , cost : number ) {
171
- $ ( elem ) . toggleClass ( 'js-slider-preset--active' , cost . duration ( ) >= + elem . dataset . months ) ;
171
+ private updateSliderPreset ( elem : HTMLElement , cost : StoreSupporterTagPrice ) {
172
+ $ ( elem ) . toggleClass ( 'js-slider-preset--active' , cost . duration >= + elem . dataset . months ) ;
172
173
}
173
174
174
175
private updateTargetId ( ) {
@@ -177,7 +178,7 @@ export default class StoreSupporterTag {
177
178
178
179
private updateUserInteraction ( ) {
179
180
const enabled = this . user ?. id != null && Number . isFinite ( this . user . id ) && this . user . id > 0 ;
180
- const messageInputVisible = enabled && this . user ?. id != window . currentUser . id ;
181
+ const messageInputVisible = enabled && this . user ?. id !== window . currentUser . id ;
181
182
fadeToggle ( this . messageInput , messageInputVisible ) ;
182
183
183
184
toggleCart ( enabled ) ;
0 commit comments