Skip to content
This repository was archived by the owner on Mar 9, 2021. It is now read-only.

Commit 1ca8108

Browse files
deep-chandrvinaypuppal
authored andcommitted
Separate tabs for upcoming and recent events
1 parent 63ada9c commit 1ca8108

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

pages/events.js

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import fetch from 'isomorphic-unfetch';
33
import { Flex, Box } from 'grid-styled/emotion';
4-
import styled from 'react-emotion';
4+
import styled, { css } from 'react-emotion';
55
import { space } from 'styled-system';
66

77
import Layout from '../components/common/layout';
@@ -34,6 +34,7 @@ export default class Events extends React.Component {
3434
futureEventsLoadLimit: 2,
3535
fetchError: null,
3636
loading: true,
37+
showFutureEvents: true,
3738
};
3839

3940
async componentDidMount() {
@@ -97,8 +98,8 @@ export default class Events extends React.Component {
9798
const imageSrc = imgs
9899
? imgs[1]
99100
: event.featured_photo
100-
? event.featured_photo.photo_link
101-
: imagePlaceholderURL;
101+
? event.featured_photo.photo_link
102+
: imagePlaceholderURL;
102103
return (
103104
<EventCard
104105
showImg
@@ -134,6 +135,12 @@ export default class Events extends React.Component {
134135
: this.setState({ futureEventsLoadLimit: this.state.futureEventsLoadLimit + 5 });
135136
}
136137

138+
loadEventsOfThisCategory(category) {
139+
this.setState({
140+
showFutureEvents: category === 'upcomingEvents',
141+
});
142+
}
143+
137144
render() {
138145
const { loading } = this.state;
139146
return (
@@ -143,21 +150,39 @@ export default class Events extends React.Component {
143150
<Container>
144151
<Flex pb={[2, 2]} flexDirection="column" alignItems="center" justifyContent="center">
145152
<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>
152170
</Box>
153171
</Flex>
154-
<Flex flexDirection="column" alignItems="center" justifyContent="center">
172+
<Flex pb={[2, 2]} flexDirection="column" alignItems="center" justifyContent="center">
155173
<Box width={[1, 0.75]}>
156174
<h3 className="event_type_title" color="#222">
157-
Recent Events
175+
{this.state.showFutureEvents ? 'Upcoming Events' : 'Recent Events'}
158176
</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 &&
161186
this.renderLoadMoreButton(this.state.pastEvents.length, this.state.pastEventsLoadLimit, true)}
162187
</Box>
163188
</Flex>

0 commit comments

Comments
 (0)