1
1
import React from 'react' ;
2
2
import fetch from 'isomorphic-unfetch' ;
3
3
import { Flex , Box } from 'grid-styled/emotion' ;
4
- import styled from 'react-emotion' ;
4
+ import styled , { css } from 'react-emotion' ;
5
5
import { space } from 'styled-system' ;
6
6
7
7
import Layout from '../components/common/layout' ;
@@ -34,6 +34,7 @@ export default class Events extends React.Component {
34
34
futureEventsLoadLimit : 2 ,
35
35
fetchError : null ,
36
36
loading : true ,
37
+ showFutureEvents : true ,
37
38
} ;
38
39
39
40
async componentDidMount ( ) {
@@ -97,8 +98,8 @@ export default class Events extends React.Component {
97
98
const imageSrc = imgs
98
99
? imgs [ 1 ]
99
100
: event . featured_photo
100
- ? event . featured_photo . photo_link
101
- : imagePlaceholderURL ;
101
+ ? event . featured_photo . photo_link
102
+ : imagePlaceholderURL ;
102
103
return (
103
104
< EventCard
104
105
showImg
@@ -134,6 +135,12 @@ export default class Events extends React.Component {
134
135
: this . setState ( { futureEventsLoadLimit : this . state . futureEventsLoadLimit + 5 } ) ;
135
136
}
136
137
138
+ loadEventsOfThisCategory ( category ) {
139
+ this . setState ( {
140
+ showFutureEvents : category === 'upcomingEvents' ,
141
+ } ) ;
142
+ }
143
+
137
144
render ( ) {
138
145
const { loading } = this . state ;
139
146
return (
@@ -143,21 +150,39 @@ export default class Events extends React.Component {
143
150
< Container >
144
151
< Flex pb = { [ 2 , 2 ] } flexDirection = "column" alignItems = "center" justifyContent = "center" >
145
152
< Box width = { [ 1 , 0.75 ] } >
146
- < h3 className = "event_type_title" color = "#222" >
147
- Upcoming Events
148
- </ h3 >
149
- { this . renderEvents ( this . state . futureEvents , this . state . futureEventsLoadLimit ) }
150
- { ! loading &&
151
- this . renderLoadMoreButton ( this . state . futureEvents . length , this . state . futureEventsLoadLimit , false ) }
153
+ < div
154
+ className = { css `
155
+ text-align : center;
156
+ ` } >
157
+ < Button
158
+ medium
159
+ ghost = { this . state . showFutureEvents }
160
+ onClick = { ( ) => this . loadEventsOfThisCategory ( 'upcomingEvents' ) } >
161
+ Upcoming Events
162
+ </ Button >
163
+ < Button
164
+ medium
165
+ ghost = { ! this . state . showFutureEvents }
166
+ onClick = { ( ) => this . loadEventsOfThisCategory ( 'recentEvents' ) } >
167
+ Recent Events
168
+ </ Button >
169
+ </ div >
152
170
</ Box >
153
171
</ Flex >
154
- < Flex flexDirection = "column" alignItems = "center" justifyContent = "center" >
172
+ < Flex pb = { [ 2 , 2 ] } flexDirection = "column" alignItems = "center" justifyContent = "center" >
155
173
< Box width = { [ 1 , 0.75 ] } >
156
174
< h3 className = "event_type_title" color = "#222" >
157
- Recent Events
175
+ { this . state . showFutureEvents ? 'Upcoming Events' : ' Recent Events' }
158
176
</ h3 >
159
- { this . renderEvents ( this . state . pastEvents , this . state . pastEventsLoadLimit ) }
160
- { ! loading &&
177
+ { this . state . showFutureEvents &&
178
+ this . renderEvents ( this . state . futureEvents , this . state . futureEventsLoadLimit ) }
179
+ { this . state . showFutureEvents &&
180
+ ! loading &&
181
+ this . renderLoadMoreButton ( this . state . futureEvents . length , this . state . futureEventsLoadLimit , false ) }
182
+ { ! this . state . showFutureEvents &&
183
+ this . renderEvents ( this . state . pastEvents , this . state . pastEventsLoadLimit ) }
184
+ { ! this . state . showFutureEvents &&
185
+ ! loading &&
161
186
this . renderLoadMoreButton ( this . state . pastEvents . length , this . state . pastEventsLoadLimit , true ) }
162
187
</ Box >
163
188
</ Flex >
0 commit comments