1+ import React , { useRef , useState } from 'react' ;
2+ import { Splide , SplideSlide , SplideTrack } from '@splidejs/react-splide' ;
3+ import { LeftOutlined , RightOutlined } from '@ant-design/icons' ;
4+ import { useTranslation } from 'react-i18next' ;
5+ import { NFTCardHeader } from '@app/components/relay-dashboard/common/NFTCardHeader/NFTCardHeader' ;
6+ import { ViewAll } from '@app/components/relay-dashboard/common/ViewAll/ViewAll' ;
7+ import { SubscriberAvatar } from '@app/components/relay-dashboard/paid-subscribers/avatar/SubscriberAvatar' ;
8+ import { SubscriberDetailModal } from './SubscriberDetailModal/SubscriberDetailModal' ;
9+ import * as S from './PaidSubscribers.styles' ;
10+ import { BaseRow } from '@app/components/common/BaseRow/BaseRow' ;
11+ import { BaseCol } from '@app/components/common/BaseCol/BaseCol' ;
12+ import { SplideCarousel } from '@app/components/common/SplideCarousel/SplideCarousel' ;
13+ import { useResponsive } from '@app/hooks/useResponsive' ;
14+ import usePaidSubscribers , { SubscriberProfile } from '@app/hooks/usePaidSubscribers' ;
15+ import { Row , Col } from 'antd' ;
16+
17+ export const PaidSubscribers : React . FC = ( ) => {
18+ console . log ( '[PaidSubscribers] Component rendering...' ) ;
19+ const hookResult = usePaidSubscribers ( 12 ) ;
20+ const { subscribers } = hookResult ;
21+
22+ // Modal state for subscriber details
23+ const [ selectedSubscriber , setSelectedSubscriber ] = useState < SubscriberProfile | null > ( null ) ;
24+ const [ isModalVisible , setIsModalVisible ] = useState ( false ) ;
25+
26+ // Handle opening subscriber detail modal
27+ const handleOpenSubscriberDetails = ( subscriber : SubscriberProfile ) => {
28+ setSelectedSubscriber ( subscriber ) ;
29+ setIsModalVisible ( true ) ;
30+ } ;
31+
32+ // Handle closing subscriber detail modal
33+ const handleCloseModal = ( ) => {
34+ setIsModalVisible ( false ) ;
35+ } ;
36+
37+ console . log ( '[PaidSubscribers] Received subscribers:' , subscribers ) ;
38+ console . log ( '[PaidSubscribers] Complete hook result:' , hookResult ) ;
39+
40+ const sliderRef = useRef < Splide > ( null ) ;
41+ const { isTablet : isTabletOrHigher } = useResponsive ( ) ;
42+ const { t } = useTranslation ( ) ;
43+
44+ const goPrev = ( ) => {
45+ if ( sliderRef . current ?. splide ) {
46+ sliderRef . current . splide . go ( '-1' ) ;
47+ }
48+ } ;
49+
50+ const goNext = ( ) => {
51+ if ( sliderRef . current ?. splide ) {
52+ sliderRef . current . splide . go ( '+1' ) ;
53+ }
54+ } ;
55+
56+ // Determine whether to use carousel with looping based on count
57+ const shouldUseLoop = subscribers . length >= 7 ;
58+
59+ // Simple grid for few subscribers
60+ if ( subscribers . length > 0 && subscribers . length < 7 ) {
61+ return (
62+ < >
63+ < NFTCardHeader title = { t ( 'nft.paidSubs' ) } >
64+ < BaseRow align = "middle" >
65+ < BaseCol >
66+ < ViewAll bordered = { false } />
67+ </ BaseCol >
68+ </ BaseRow >
69+ </ NFTCardHeader >
70+
71+ < Row gutter = { [ 16 , 16 ] } style = { { padding : '0 10px' } } >
72+ { subscribers . map ( ( subscriber : SubscriberProfile ) => (
73+ < Col key = { subscriber . pubkey } xs = { 6 } sm = { 4 } md = { 3 } lg = { 3 } xl = { 2 } >
74+ < S . CardWrapper >
75+ < SubscriberAvatar
76+ onStoryOpen = { ( ) => handleOpenSubscriberDetails ( subscriber ) }
77+ img = { subscriber . picture }
78+ viewed = { false }
79+ />
80+ </ S . CardWrapper >
81+ </ Col >
82+ ) ) }
83+ </ Row >
84+
85+ < SubscriberDetailModal
86+ subscriber = { selectedSubscriber }
87+ isVisible = { isModalVisible }
88+ onClose = { handleCloseModal }
89+ />
90+ </ >
91+ ) ;
92+ }
93+
94+ // Carousel view for 7+ subscribers
95+ return (
96+ < >
97+ < SplideCarousel
98+ ref = { sliderRef }
99+ type = { shouldUseLoop ? "loop" : undefined }
100+ drag = "free"
101+ gap = ".2rem"
102+ snap = "false"
103+ autoSpeed = { isTabletOrHigher ? 0.7 : 0.8 }
104+ flickPower = "500"
105+ breakpoints = { {
106+ 8000 : {
107+ perPage : 10 ,
108+ } ,
109+ 1920 : {
110+ perPage : 10 ,
111+ } ,
112+ 1600 : {
113+ perPage : 8 ,
114+ } ,
115+ 850 : {
116+ perPage : 7 ,
117+ } ,
118+ 768 : {
119+ perPage : 4 ,
120+ } ,
121+ } }
122+ >
123+ < NFTCardHeader title = { t ( 'nft.paidSubs' ) } >
124+ < BaseRow align = "middle" >
125+ < BaseCol >
126+ < ViewAll bordered = { false } />
127+ </ BaseCol >
128+
129+ { isTabletOrHigher && subscribers . length > 1 && (
130+ < >
131+ < BaseCol >
132+ < S . ArrowBtn type = "text" size = "small" onClick = { goPrev } >
133+ < LeftOutlined />
134+ </ S . ArrowBtn >
135+ </ BaseCol >
136+
137+ < BaseCol >
138+ < S . ArrowBtn type = "text" size = "small" onClick = { goNext } >
139+ < RightOutlined />
140+ </ S . ArrowBtn >
141+ </ BaseCol >
142+ </ >
143+ ) }
144+ </ BaseRow >
145+ </ NFTCardHeader >
146+ < SplideTrack >
147+ { subscribers . map ( ( subscriber : SubscriberProfile ) => (
148+ < SplideSlide key = { subscriber . pubkey } >
149+ < S . CardWrapper >
150+ < SubscriberAvatar
151+ onStoryOpen = { ( ) => handleOpenSubscriberDetails ( subscriber ) }
152+ img = { subscriber . picture }
153+ viewed = { false }
154+ />
155+ </ S . CardWrapper >
156+ </ SplideSlide >
157+ ) ) }
158+ </ SplideTrack >
159+ </ SplideCarousel >
160+
161+ < SubscriberDetailModal
162+ subscriber = { selectedSubscriber }
163+ isVisible = { isModalVisible }
164+ onClose = { handleCloseModal }
165+ />
166+ </ >
167+ ) ;
168+ } ;
169+
170+ export default PaidSubscribers ;
0 commit comments