@@ -13,7 +13,7 @@ import lottieLoader from '../../lib/rlottie/lottieLoader';
13
13
import classNames from '../../helpers/string/classNames' ;
14
14
import sortLongsArray from '../../helpers/long/sortLongsArray' ;
15
15
import { StarGiftsGrid } from '../stargifts/stargiftsGrid' ;
16
- import { fastRaf } from '../../helpers/schedulers' ;
16
+ import { doubleRaf , fastRaf } from '../../helpers/schedulers' ;
17
17
import PopupStarGiftInfo from './starGiftInfo' ;
18
18
import { FakeBubbles } from '../chat/bubbles/fakeBubbles' ;
19
19
import { ServiceBubble } from '../chat/bubbles/service' ;
@@ -37,6 +37,11 @@ import maybe2x from '../../helpers/maybe2x';
37
37
import { I18nTsx } from '../../helpers/solid/i18n' ;
38
38
import { StarGiftBadge } from '../stargifts/stargiftBadge' ;
39
39
import Scrollable from '../scrollable2' ;
40
+ import { PeerTitleTsx } from '../wrappers/peerTitle' ;
41
+ import { approxEquals } from '../../helpers/number/approxEquals' ;
42
+ import getVisibleRect from '../../helpers/dom/getVisibleRect' ;
43
+ import fastSmoothScroll from '../../helpers/fastSmoothScroll' ;
44
+ import clamp from '../../helpers/number/clamp' ;
40
45
41
46
type GiftOption = MyStarGift | MyPremiumGiftOption ;
42
47
@@ -63,6 +68,7 @@ function GiftOptionsPage(props: {
63
68
const [ category , setCategory ] = createSignal < string > ( 'All' ) ;
64
69
65
70
let categoriesContainer ! : HTMLDivElement ;
71
+ let categoriesScrollable ! : HTMLDivElement
66
72
let container ! : HTMLDivElement ;
67
73
68
74
const giftPremiumSection = props . peer . _ === 'user' && (
@@ -71,7 +77,10 @@ function GiftOptionsPage(props: {
71
77
{ i18n ( 'GiftPremium' ) }
72
78
</ div >
73
79
< div class = "popup-send-gift-subtitle" >
74
- { i18n ( 'GiftTelegramPremiumDescription' , [ props . peer . first_name ] ) }
80
+ < I18nTsx
81
+ key = "GiftTelegramPremiumDescription"
82
+ args = { < PeerTitleTsx peerId = { props . peerId } onlyFirstName = { props . peer . _ === 'user' } /> }
83
+ />
75
84
</ div >
76
85
< div class = "popup-send-gift-premium-options" >
77
86
< For each = { props . premiumOptions } >
@@ -124,11 +133,25 @@ function GiftOptionsPage(props: {
124
133
< div
125
134
class = { classNames ( 'popup-send-gift-category' , category ( ) === it && 'active' ) }
126
135
onClick = { ( event : MouseEvent ) => {
127
- if ( ! categoriesContainer . classList . contains ( 'is-pinned' ) ) {
128
- container . scrollTo ( { top : categoriesContainer . offsetTop , behavior : 'smooth' } ) ;
129
- }
130
- ( event . target as HTMLElement ) . scrollIntoView ( { behavior : 'smooth' } ) ;
136
+ const wasPinned = categoriesContainer . classList . contains ( 'is-pinned' ) ;
131
137
setCategory ( it )
138
+ const categoryEl = ( event . target as HTMLElement ) . closest ( '.popup-send-gift-category' ) as HTMLElement ;
139
+ fastRaf ( ( ) => {
140
+ if ( ! categoriesContainer . classList . contains ( 'is-pinned' ) ) {
141
+ container . scrollTo ( { top : categoriesContainer . offsetTop - 56 , behavior : wasPinned ? 'instant' : 'smooth' } ) ;
142
+ }
143
+
144
+ const categoryRect = categoryEl . getBoundingClientRect ( ) ;
145
+ const visibleRect = getVisibleRect ( categoryEl , categoriesScrollable , false , categoryRect ) ;
146
+ if ( ! visibleRect || visibleRect . overflow . horizontal ) {
147
+ fastSmoothScroll ( {
148
+ element : categoryEl ,
149
+ container : categoriesScrollable ,
150
+ position : 'center' ,
151
+ axis : 'x'
152
+ } )
153
+ }
154
+ } )
132
155
} }
133
156
>
134
157
{ it in STATIC_CATEGORIES ? i18n ( STATIC_CATEGORIES [ it ] ) : (
@@ -172,7 +195,7 @@ function GiftOptionsPage(props: {
172
195
173
196
const containerRect = container . getBoundingClientRect ( ) ;
174
197
const rect = categoriesContainer . getBoundingClientRect ( ) ;
175
- const isPinned = rect . top - containerRect . top === 56
198
+ const isPinned = approxEquals ( rect . top - containerRect . top , 56 , 0.1 )
176
199
177
200
categoriesContainer . classList . toggle ( 'is-pinned' , isPinned ) ;
178
201
container . classList . toggle ( 'has-pinned-categories' , isPinned ) ;
@@ -200,11 +223,14 @@ function GiftOptionsPage(props: {
200
223
{ i18n ( 'Chat.Menu.SendGift' ) }
201
224
</ div >
202
225
< div class = "popup-send-gift-subtitle" >
203
- { i18n ( 'SendStarGiftSubtitle' , [ props . peer . _ === 'user' ? props . peer . first_name : props . peer . title ] ) }
226
+ < I18nTsx
227
+ key = "SendStarGiftSubtitle"
228
+ args = { < PeerTitleTsx peerId = { props . peerId } onlyFirstName = { props . peer . _ === 'user' } /> }
229
+ />
204
230
</ div >
205
231
206
232
< div class = "popup-send-gift-categories" ref = { categoriesContainer } >
207
- < Scrollable axis = "x" >
233
+ < Scrollable axis = "x" ref = { categoriesScrollable } >
208
234
{ wrapCategory ( 'All' ) }
209
235
{ wrapCategory ( 'Limited' ) }
210
236
{ wrapCategory ( 'InStock' ) }
@@ -214,13 +240,15 @@ function GiftOptionsPage(props: {
214
240
</ Scrollable >
215
241
</ div >
216
242
217
- < StarGiftsGrid
218
- class = "popup-send-gift-gifts"
219
- items = { filteredGiftOptions ( ) }
220
- view = "list"
221
- scrollParent = { container }
222
- onClick = { handleGiftClick }
223
- />
243
+ < div class = "popup-send-gift-gifts" >
244
+ < StarGiftsGrid
245
+ class = "popup-send-gift-gifts-grid"
246
+ items = { filteredGiftOptions ( ) }
247
+ view = "list"
248
+ scrollParent = { container }
249
+ onClick = { handleGiftClick }
250
+ />
251
+ </ div >
224
252
</ div >
225
253
</ Scrollable >
226
254
)
@@ -359,11 +387,11 @@ function ChosenGiftPage(props: {
359
387
/>
360
388
) : (
361
389
< PremiumGiftBubble
362
- title = { i18n ( 'ActionGiftPremiumTitle ' , [ formatMonthsDuration ( props . chosenGift . months , false ) ] ) }
390
+ title = { i18n ( 'ActionGiftPremiumTitle2 ' , [ formatMonthsDuration ( props . chosenGift . months , false ) ] ) }
363
391
subtitle = {
364
392
textWithEntities ( ) ?
365
393
wrapRichText ( textWithEntities ( ) . text , { entities : textWithEntities ( ) . entities } ) :
366
- i18n ( 'ActionGiftPremiumSubtitle ' )
394
+ i18n ( 'ActionGiftPremiumSubtitle2 ' )
367
395
}
368
396
buttonText = { i18n ( 'ActionGiftPremiumView' ) }
369
397
assetName = { `Gift${ props . chosenGift . months } ` }
0 commit comments