1
1
import React , { useEffect , useRef , useState } from 'react' ;
2
- import type { FC , RefObject } from 'react' ;
2
+ import type { FC , PropsWithChildren , RefObject } from 'react' ;
3
3
import dayjs from 'dayjs' ;
4
4
import type { GetServerSideProps , NextPage } from 'next' ;
5
5
import * as statsfm from '@statsfm/statsfm.js' ;
@@ -170,6 +170,31 @@ const ImportRequiredScope: FC<ScopeProps> = ({ children, value }) => {
170
170
) ;
171
171
} ;
172
172
173
+ const UserBanScope : FC < PropsWithChildren < { user : statsfm . UserPublic } > > = ( {
174
+ children,
175
+ user,
176
+ } ) => {
177
+ if ( user . userBan ?. active === true ) {
178
+ return (
179
+ < Container className = "mt-8" >
180
+ < h3 > Account banned</ h3 >
181
+ < p className = "[&>a]:text-primary" >
182
+ The account you are viewing has been banned from the platform.
183
+ </ p >
184
+ < p className = "[&>a]:text-primary" >
185
+ You can view more info about banned accounts here{ ' ' }
186
+ < Linkify options = { { target : '_blank' , rel : 'noopener noreferrer' } } >
187
+ https://support.stats.fm/docs/banned
188
+ </ Linkify >
189
+ .
190
+ </ p >
191
+ </ Container >
192
+ ) ;
193
+ }
194
+
195
+ return < > { children } </ > ;
196
+ } ;
197
+
173
198
const User : NextPage < Props > = ( {
174
199
userProfile : user ,
175
200
friendStatus,
@@ -295,6 +320,16 @@ const User: NextPage<Props> = ({
295
320
296
321
useScrollPercentage ( 30 , ( ) => event ( 'USER_scroll_30' ) ) ;
297
322
323
+ if ( user . userBan ?. active === true ) {
324
+ // eslint-disable-next-line no-param-reassign
325
+ user = {
326
+ ...user ,
327
+ displayName : 'Banned User' ,
328
+ image : undefined ,
329
+ isPlus : false ,
330
+ } ;
331
+ }
332
+
298
333
return (
299
334
< >
300
335
< Title >
@@ -330,11 +365,7 @@ const User: NextPage<Props> = ({
330
365
< Container >
331
366
< section className = "flex flex-col items-center gap-5 pt-24 pb-10 md:flex-row" >
332
367
< div className = "relative rounded-full border-2 border-background" >
333
- < Avatar
334
- src = { user . userBan ?. active !== true ? user . image : undefined }
335
- name = { user . userBan ?. active ? 'Banned User' : user . displayName }
336
- size = "4xl"
337
- />
368
+ < Avatar src = { user . image } name = { user . displayName } size = "4xl" />
338
369
< div className = "absolute right-0 bottom-2 text-center text-lg font-medium md:text-left" >
339
370
{ user . isPlus && < PlusBadge /> }
340
371
</ div >
@@ -343,12 +374,12 @@ const User: NextPage<Props> = ({
343
374
< div className = "flex flex-col items-center justify-end md:items-start" >
344
375
< span className = "flex" >
345
376
< h1 className = "text-center font-extrabold md:text-left" >
346
- { user . userBan ?. active !== true
347
- ? user . displayName
348
- : 'Banned User' }
377
+ { user . displayName }
349
378
</ h1 >
350
379
< span className = "ml-2 mt-2 self-center text-center text-lg font-medium md:text-left" >
351
- { user . privacySettings ?. profile && user . profile ?. pronouns }
380
+ { user . privacySettings ?. profile &&
381
+ user . userBan ?. active !== true &&
382
+ user . profile ?. pronouns }
352
383
</ span >
353
384
</ span >
354
385
{ user . privacySettings ?. profile &&
@@ -425,7 +456,7 @@ const User: NextPage<Props> = ({
425
456
</ div >
426
457
427
458
{ /* Active user page */ }
428
- { user . userBan ?. active !== true && (
459
+ < UserBanScope user = { user } >
429
460
< Container className = "mt-8" >
430
461
{ user . quarantined && (
431
462
< section className = "pb-10" >
@@ -546,26 +577,7 @@ const User: NextPage<Props> = ({
546
577
) }
547
578
</ Section >
548
579
</ Container >
549
- ) }
550
-
551
- { /* User banned page */ }
552
- { user . userBan ?. active === true && (
553
- < Container className = "mt-8" >
554
- < h3 > Account banned</ h3 >
555
- < p className = "[&>a]:text-primary" >
556
- The account you are viewing has been banned from the platform.
557
- </ p >
558
- < p className = "[&>a]:text-primary" >
559
- You can view more info about banned accounts here{ ' ' }
560
- < Linkify
561
- options = { { target : '_blank' , rel : 'noopener noreferrer' } }
562
- >
563
- https://support.stats.fm/docs/banned
564
- </ Linkify >
565
- .
566
- </ p >
567
- </ Container >
568
- ) }
580
+ </ UserBanScope >
569
581
</ Scope . Context >
570
582
</ >
571
583
) ;
0 commit comments