-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfeatured_carousel.jsx
122 lines (106 loc) · 3.59 KB
/
featured_carousel.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import React from 'react';
import {Link, hashHistory} from 'react-router';
class FeaturedCarousel extends React.Component {
constructor(props) {
super(props);
this.shiftLeft = this.props.shiftLeft.bind(this);
this.shiftRight = this.props.shiftRight.bind(this);
this.updateFeaturedCarousel = this.updateFeaturedCarousel.bind(this);
this.interval = null;
}
componentDidMount () {
this.props.fetchFeaturedCarouselCampaigns();
window.addEventListener('animationend', this.updateFeaturedCarousel);
this.interval = setInterval(this.shiftLeft, 5000);
}
componentWillUnmount () {
window.removeEventListener('animationend', this.updateFeaturedCarousel);
clearInterval(this.interval);
}
updateFeaturedCarousel(e) {
if (e.animationName === "shift-featured-carousel-right") {
this.props.featuredCarouselCampaigns.unshift(this.props.featuredCarouselCampaigns.pop());
} else if (e.animationName === "shift-featured-carousel-left") {
this.props.featuredCarouselCampaigns.push(this.props.featuredCarouselCampaigns.shift());
}
this.props.receiveFeaturedCarouselCampaigns(this.props.featuredCarouselCampaigns);
}
shiftOrNot(idx) {
return () => {
clearInterval(this.interval);
if (idx == 1) {
this.shiftRight();
} else if (idx == 3) {
this.shiftLeft();
}
};
}
classShifter() {
if (this.props.active) {
if (this.props.direction === 'right') {
return ("shift-featured-carousel-right");
} else if (this.props.direction === 'left') {
return ("shift-featured-carousel-left");
}
}
}
classFader(idx) {
if (this.props.active) {
if (this.props.direction === 'right' && idx == 2) {
return ("featured-carousel-fade-out-right");
} else if (this.props.direction === 'left' && idx == 2) {
return ("featured-carousel-fade-out-left");
} else if (this.props.direction === 'left' && idx == 3) {
return ("featured-carousel-fade-in-left");
} else if (this.props.direction === 'right' && idx == 1) {
return ("featured-carousel-fade-in-right");
}
}
}
middle(idx) {
if (idx == 2) {
return ("middle");
}
}
fCarouselTrack() {
const fCarouselItems = this.props.featuredCarouselCampaigns.map( (campaign, idx) => (
<div key={idx} className="featured-carousel-div" >
<img className="featured-carousel-img" src={campaign.pitch_img_url} />
<div className="grey"/>
<div className={this.middle(idx) + " featured-carousel-overlay " + this.classFader(idx)} onClick={this.shiftOrNot(idx)}>
<div className="featured-carousel-overlay-left">
<div className="featured-carousel-title">
{campaign.title}
</div>
<div className="featured-carousel-tagline">
{campaign.tagline}
</div>
</div>
<div className="featured-carousel-overlay-right">
<div onClick={() => hashHistory.push('/campaigns/' + campaign.id)} className={"see-campaign"}>
SEE CAMPAIGN
</div>
</div>
</div>
</div>
));
return (
<div className={"featured-carousel-track " + this.classShifter()}>
{fCarouselItems}
</div>
);
}
render () {
if (this.props.featuredCarouselCampaigns[0] === undefined) {
return (<div> </div>);
}
return (
<div className="featured-carousel">
<div className="featured-carousel-list">
{this.fCarouselTrack()}
</div>
</div>
);
}
}
export default FeaturedCarousel;