Skip to content
This repository was archived by the owner on Jan 31, 2019. It is now read-only.

Commit 11525c8

Browse files
committed
recommend beta 1
1 parent 213b670 commit 11525c8

File tree

10 files changed

+262
-91
lines changed

10 files changed

+262
-91
lines changed

src/actions/bannerActions.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const CHANGE = 'BANNER/CHANGE';
2+
const INIT = 'BANNER/INIT';
3+
4+
export const bannerActions = {
5+
CHANGE: CHANGE,
6+
INIT: INIT
7+
}
8+
9+
const initBanner = (payload) => ({
10+
type: INIT,
11+
payload
12+
});
13+
14+
const changeBanner = (payload) => ({
15+
type: CHANGE,
16+
payload
17+
});
18+
19+
export {
20+
changeBanner,
21+
initBanner,
22+
}

src/actions/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export * from './inviteActions';
1010
export * from './cheeseActions';
1111
export * from './favoriteActions';
1212
export * from './onlineActions';
13-
export * from './recommendActions';
13+
export * from './recommendActions';
14+
export * from './bannerActions';

src/actions/recommendActions.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,29 @@
22
import fetch from 'isomorphic-fetch';
33
import config from '../../config';
44

5+
import { initBanner } from 'actions'
6+
57
const API_HOST = `${config.HOST}:3000`
68
const url = '/api/recommend';
79

810
const REQUEST = 'recommend/REQUEST';
911
const OK = 'recommend/OK';
1012
const ERROR = 'recommend/ERROR';
1113

14+
const bannerItemsHander = (data) => {
15+
let results = [];
16+
17+
for(let key in data) {
18+
19+
let items = data[key];
20+
21+
if(results.length < 5) results.push(items[0])
22+
23+
}
24+
25+
return results;
26+
}
27+
1228
export const recommendActions = {
1329
REQUEST,
1430
OK,
@@ -32,10 +48,13 @@ const getRecommendError = payload => ({
3248

3349
const getRecommend = () => (dispatch) => {
3450
dispatch(getRecommendRequest());
35-
51+
3652
return fetch(`${API_HOST}${url}`)
3753
.then(res => res.json())
38-
.then(json => dispatch(getRecommendOk(json)))
54+
.then(json => {
55+
dispatch(initBanner(bannerItemsHander(json)))
56+
dispatch(getRecommendOk(json))
57+
})
3958
.catch(err => dispatch(getRecommendError(err)));
4059
};
4160

src/components/Banner/Banner.css

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
.banner {
2+
width: 1200px;
3+
height: 565px;
4+
margin: 20px auto;
5+
display: flex;
6+
justify-content: space-between;
7+
8+
& * {
9+
box-sizing: border-box;
10+
}
11+
12+
& .list {
13+
width: 200px;
14+
background: rgba(0, 0, 0, 0.3);;
15+
display: flex;
16+
flex-direction: column;
17+
18+
& .item {
19+
cursor: pointer;
20+
margin-bottom: 5px;
21+
overflow: hidden;
22+
padding-left: 5px;
23+
opacity: .5;
24+
25+
& img {
26+
width: 100%;
27+
height: 113px;
28+
}
29+
30+
&:last-child {
31+
margin-bottom: 0;
32+
}
33+
34+
&:hover {
35+
opacity: 1;
36+
}
37+
}
38+
39+
&.active0 {
40+
& .item:nth-child(1) {
41+
opacity: 1;
42+
}
43+
}
44+
&.active1 {
45+
& .item:nth-child(2) {
46+
opacity: 1;
47+
}
48+
}
49+
&.active2 {
50+
& .item:nth-child(3) {
51+
opacity: 1;
52+
}
53+
}
54+
&.active3 {
55+
& .item:nth-child(4) {
56+
opacity: 1;
57+
}
58+
}
59+
&.active4 {
60+
& .item:nth-child(5) {
61+
opacity: 1;
62+
}
63+
}
64+
}
65+
66+
67+
& .player {
68+
max-width: 1000px;
69+
width: 100%;
70+
71+
& section:first-child {
72+
padding: 0 !important;
73+
height: 100%;
74+
width: 100%;
75+
}
76+
}
77+
78+
}

src/components/Banner/Banner.jsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React from 'react';
2+
import { connect } from 'react-redux';
3+
import classnames from 'classnames';
4+
import ScreenItem from 'components/ScreenItem';
5+
import styles from './Banner.css';
6+
7+
import { changeBanner } from 'actions';
8+
9+
10+
11+
class Banner extends React.Component {
12+
13+
constructor(props) {
14+
super(props)
15+
16+
this.changeBanner = this.changeBanner.bind(this)
17+
18+
this.state = {
19+
active: 0,
20+
}
21+
}
22+
23+
componentDidMount() {
24+
25+
}
26+
27+
componentDidUpdate() {
28+
29+
}
30+
31+
changeBanner(item, i) {
32+
this.props.changeBanner(item)
33+
this.setState({
34+
active: i,
35+
})
36+
}
37+
38+
39+
render() {
40+
const {items: items, index: index } = this.props.banner;
41+
let itemsHtml = [];
42+
43+
items.forEach((item, key) => {
44+
itemsHtml.push(
45+
<section key={`${item.roomId}`} onClick={() => this.changeBanner(item, key)} className={styles.item}>
46+
<img src={item.cover} alt={item.title} title={item.title}/>
47+
</section>
48+
)
49+
})
50+
51+
52+
53+
return (
54+
<div className={styles.banner}>
55+
<section className={styles.player}>
56+
<ScreenItem isBanner={true} item={index} screenCount={1} />
57+
</section>
58+
<section className={classnames(styles.list, styles[`active${this.state.active}`])}>
59+
{itemsHtml}
60+
</section>
61+
</div>
62+
)
63+
}
64+
}
65+
66+
const mapStateToProps = (state, ownProps) => ({
67+
banner: state.banner,
68+
})
69+
70+
const mapDispatchToProps = (dispatch, ownProps) => ({
71+
changeBanner: (item) => dispatch(changeBanner(item))
72+
})
73+
74+
export default connect(mapStateToProps, mapDispatchToProps)(Banner);

src/components/Banner/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Banner from './Banner'
2+
3+
export default Banner

src/components/Recommend/Recommend.css

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,11 @@
1414
}
1515
}
1616

17-
.banner {
18-
width: 1200px;
19-
height: 565px;
20-
margin: 20px auto;
21-
display: flex;
22-
justify-content: space-between;
23-
24-
& * {
25-
box-sizing: border-box;
26-
}
27-
28-
& .list {
29-
width: 200px;
30-
background: rgba(0, 0, 0, 0.3);;
31-
display: flex;
32-
flex-direction: column;
33-
34-
& .item {
35-
cursor: pointer;
36-
margin-bottom: 5px;
37-
overflow: hidden;
38-
padding-left: 5px;
39-
opacity: .5;
40-
41-
& img {
42-
width: 100%;
43-
height: 113px;
44-
}
45-
46-
&:last-child {
47-
margin-bottom: 0;
48-
}
49-
50-
&.active, &:hover {
51-
opacity: 1;
52-
}
53-
}
54-
}
55-
56-
57-
& .player {
58-
max-width: 1000px;
59-
width: 100%;
60-
61-
& section:first-child {
62-
padding: 0 !important;
63-
height: 100%;
64-
width: 100%;
65-
}
66-
}
67-
17+
.outerWrapper {
18+
opacity: 0;
19+
animation: zoomIn 4s ease forwards;
20+
width: 100%;
21+
height: 100%;
6822
}
6923

7024
.content {
@@ -108,4 +62,17 @@
10862
}
10963
}
11064
}
65+
}
66+
67+
.empty {
68+
width: 100%;
69+
height: 100%;
70+
display: flex;
71+
justify-content: center;
72+
align-items: center;
73+
}
74+
75+
@keyframes zoomIn {
76+
from {opacity: 0; transform: scale(.95) }
77+
to {opacity: 1; transform: scale(1)}
11178
}

0 commit comments

Comments
 (0)