@@ -17,7 +17,7 @@ import BlogFeed from 'containers/Contentful/BlogFeed';
17
17
import { errors } from 'topcoder-react-lib' ;
18
18
import LoadingIndicator from 'components/LoadingIndicator' ;
19
19
import PT from 'prop-types' ;
20
- import React from 'react' ;
20
+ import React , { useState } from 'react' ;
21
21
import Countdown from 'components/Contentful/Countdown' ;
22
22
import Tabs from 'components/Contentful/Tabs' ;
23
23
import AppComponentLoader from 'components/Contentful/AppComponent' ;
@@ -30,11 +30,13 @@ import Article from 'components/Contentful/Article';
30
30
import { isomorphy } from 'topcoder-react-utils' ;
31
31
import MemberTalkCloud from 'components/Contentful/MemberTalkCloud' ;
32
32
import Masonry from 'react-masonry-css' ;
33
+ import { PrimaryButton } from 'topcoder-react-ui-kit' ;
33
34
34
35
// AOS
35
36
import AOS from 'aos' ;
36
37
import 'aos/dist/aos.css' ;
37
38
39
+ import tc from 'components/buttons/themed/tc.scss' ;
38
40
import Viewport from './Viewport' ;
39
41
40
42
import columnTheme from './themes/column.scss' ;
@@ -78,6 +80,10 @@ const THEMES = {
78
80
Masonry : masonryTheme ,
79
81
} ;
80
82
83
+ const buttonThemes = {
84
+ tc,
85
+ } ;
86
+
81
87
/* Loads viewport content assets. */
82
88
function ViewportContentLoader ( props ) {
83
89
const {
@@ -91,12 +97,19 @@ function ViewportContentLoader(props) {
91
97
viewportId,
92
98
animationOnScroll,
93
99
masonryConfig,
100
+ itemsPerPage,
101
+ loadMoreButtonText,
102
+ loadMoreButtonTheme,
103
+ loadMoreButtonContainerStyles,
94
104
} = props ;
95
105
let {
96
106
extraStylesForContainer,
97
107
} = props ;
108
+ const [ page , setPage ] = useState ( 1 ) ;
98
109
99
- const getInner = data => contentIds . map ( ( id ) => {
110
+ const getInner = data => contentIds . slice (
111
+ 0 , ( itemsPerPage ? itemsPerPage * page : contentIds . length ) ,
112
+ ) . map ( ( id ) => {
100
113
const type = data . entries . items [ id ] . sys . contentType . sys . id ;
101
114
const Component = COMPONENTS [ type ] ;
102
115
if ( Component ) {
@@ -146,7 +159,44 @@ function ViewportContentLoader(props) {
146
159
AOS . init ( ) ;
147
160
}
148
161
}
149
- return (
162
+ return itemsPerPage ? (
163
+ < div className = { theme . loadMoreWrapper } >
164
+ < Viewport
165
+ viewportId = { viewportId }
166
+ extraStylesForContainer = { fixStyle ( extraStylesForContainer ) }
167
+ theme = { theme }
168
+ animation = { animation }
169
+ >
170
+ {
171
+ themeName === 'Masonry' && masonryConfig ? (
172
+ < Masonry breakpointCols = { masonryConfig } className = "viewport-masonry-grid" columnClassName = "viewport-masonry-grid_column" >
173
+ { getInner ( data ) }
174
+ </ Masonry >
175
+ ) : getInner ( data )
176
+ }
177
+ </ Viewport >
178
+ {
179
+ page * itemsPerPage < contentIds . length && (
180
+ < div
181
+ className = { theme . loadMoreButtonContainer }
182
+ style = { fixStyle ( loadMoreButtonContainerStyles ) }
183
+ >
184
+ < PrimaryButton
185
+ onClick = { ( ) => {
186
+ setPage ( page + 1 ) ;
187
+ } }
188
+ theme = { {
189
+ button : buttonThemes . tc [ loadMoreButtonTheme ] ,
190
+ disabled : buttonThemes . tc . themedButtonDisabled ,
191
+ } }
192
+ >
193
+ { loadMoreButtonText }
194
+ </ PrimaryButton >
195
+ </ div >
196
+ )
197
+ }
198
+ </ div >
199
+ ) : (
150
200
< Viewport
151
201
viewportId = { viewportId }
152
202
extraStylesForContainer = { fixStyle ( extraStylesForContainer ) }
@@ -180,6 +230,10 @@ ViewportContentLoader.defaultProps = {
180
230
} ) ,
181
231
animationOnScroll : null ,
182
232
masonryConfig : null ,
233
+ itemsPerPage : null ,
234
+ loadMoreButtonText : null ,
235
+ loadMoreButtonTheme : null ,
236
+ loadMoreButtonContainerStyles : null ,
183
237
} ;
184
238
185
239
ViewportContentLoader . propTypes = {
@@ -194,6 +248,10 @@ ViewportContentLoader.propTypes = {
194
248
baseUrl : PT . string . isRequired ,
195
249
animationOnScroll : PT . shape ( ) ,
196
250
masonryConfig : PT . shape ( ) ,
251
+ itemsPerPage : PT . string ,
252
+ loadMoreButtonText : PT . string ,
253
+ loadMoreButtonTheme : PT . string ,
254
+ loadMoreButtonContainerStyles : PT . shape ( ) ,
197
255
} ;
198
256
199
257
/* Loads the main viewport entry. */
@@ -247,6 +305,10 @@ export function ViewportLoader(props) {
247
305
baseUrl = { baseUrl }
248
306
animationOnScroll = { viewport . fields . animationOnScroll }
249
307
masonryConfig = { viewport . fields . masonryConfig }
308
+ itemsPerPage = { viewport . fields . itemsPerPage }
309
+ loadMoreButtonText = { viewport . fields . loadMoreButtonText }
310
+ loadMoreButtonTheme = { viewport . fields . loadMoreButtonTheme }
311
+ loadMoreButtonContainerStyles = { viewport . fields . loadMoreButtonContainerStyles }
250
312
/>
251
313
) ;
252
314
} ) }
0 commit comments