增加section view review by 阿瑟
Showing
9 changed files
with
213 additions
and
217 deletions
@@ -5,7 +5,7 @@ import ReactNative from 'react-native'; | @@ -5,7 +5,7 @@ import ReactNative from 'react-native'; | ||
5 | import ImmutablePropTypes from 'react-immutable-proptypes'; | 5 | import ImmutablePropTypes from 'react-immutable-proptypes'; |
6 | import Banner from './Banner'; | 6 | import Banner from './Banner'; |
7 | import Notice from './Notice'; | 7 | import Notice from './Notice'; |
8 | -import Section from './Section'; | 8 | +import YH_SectionView from './YH_SectionView'; |
9 | import ListCell from './ListCell'; | 9 | import ListCell from './ListCell'; |
10 | 10 | ||
11 | const { | 11 | const { |
@@ -22,6 +22,7 @@ const { | @@ -22,6 +22,7 @@ const { | ||
22 | 22 | ||
23 | let {width, height} = Dimensions.get('window'); | 23 | let {width, height} = Dimensions.get('window'); |
24 | let bannerHeight = Math.ceil((363 / 750) * width); | 24 | let bannerHeight = Math.ceil((363 / 750) * width); |
25 | +let sectionHeight = Math.ceil((435 / 750) * width); | ||
25 | 26 | ||
26 | export default class Home extends React.Component { | 27 | export default class Home extends React.Component { |
27 | 28 | ||
@@ -45,8 +46,24 @@ export default class Home extends React.Component { | @@ -45,8 +46,24 @@ export default class Home extends React.Component { | ||
45 | section: ImmutablePropTypes.listOf( | 46 | section: ImmutablePropTypes.listOf( |
46 | ImmutablePropTypes.listOf( | 47 | ImmutablePropTypes.listOf( |
47 | ImmutablePropTypes.contains({ | 48 | ImmutablePropTypes.contains({ |
48 | - image: React.PropTypes.string.isRequired, | ||
49 | - url: React.PropTypes.string, | 49 | + header: ImmutablePropTypes.contains({ |
50 | + logo: React.PropTypes.string.isRequired, | ||
51 | + title: React.PropTypes.string.isRequired, | ||
52 | + postNum: React.PropTypes.string.isRequired, | ||
53 | + commentNum: React.PropTypes.string.isRequired, | ||
54 | + laudCount: React.PropTypes.string.isRequired, | ||
55 | + }), | ||
56 | + hot: ImmutablePropTypes.contains({ | ||
57 | + avatar: React.PropTypes.string.isRequired, | ||
58 | + content: React.PropTypes.string.isRequired, | ||
59 | + }), | ||
60 | + new: ImmutablePropTypes.contains({ | ||
61 | + avatar: React.PropTypes.string.isRequired, | ||
62 | + content: React.PropTypes.string.isRequired, | ||
63 | + }), | ||
64 | + num: ImmutablePropTypes.contains({ | ||
65 | + onedayAddNum: React.PropTypes.string.isRequired, | ||
66 | + }), | ||
50 | }) | 67 | }) |
51 | ), | 68 | ), |
52 | ), | 69 | ), |
@@ -115,17 +132,15 @@ export default class Home extends React.Component { | @@ -115,17 +132,15 @@ export default class Home extends React.Component { | ||
115 | ); | 132 | ); |
116 | case 'section': | 133 | case 'section': |
117 | return ( | 134 | return ( |
118 | - <Section | ||
119 | - data={rowData} | ||
120 | - width={width} | ||
121 | - height={210} | ||
122 | - onPress={(url) => { | ||
123 | - this.props._onPressSection && this.props._onPressSection(url); | 135 | + <YH_SectionView |
136 | + style={styles.carouselSection} | ||
137 | + items={rowData} | ||
138 | + onClick={(index) => { | ||
139 | + this.props.onPressSection && this.props.onPressSection(index); | ||
124 | }} | 140 | }} |
125 | /> | 141 | /> |
126 | ); | 142 | ); |
127 | case 'recommendation': | 143 | case 'recommendation': |
128 | - console.log(rowData); | ||
129 | return ( | 144 | return ( |
130 | <ListCell | 145 | <ListCell |
131 | key={sectionID + rowID} | 146 | key={sectionID + rowID} |
@@ -175,9 +190,9 @@ export default class Home extends React.Component { | @@ -175,9 +190,9 @@ export default class Home extends React.Component { | ||
175 | 190 | ||
176 | render() { | 191 | render() { |
177 | let dataSource = { | 192 | let dataSource = { |
178 | - banner: this.props.banner.toObject(), | ||
179 | - notice: this.props.notice.toObject(), | ||
180 | - section: this.props.section.toObject(), | 193 | + banner: this.props.banner.toArray(), |
194 | + notice: this.props.notice.toArray(), | ||
195 | + section: this.props.section.toArray(), | ||
181 | recommendation: this.props.recommendation.toArray(), | 196 | recommendation: this.props.recommendation.toArray(), |
182 | } | 197 | } |
183 | return ( | 198 | return ( |
@@ -205,6 +220,10 @@ let styles = StyleSheet.create({ | @@ -205,6 +220,10 @@ let styles = StyleSheet.create({ | ||
205 | container: { | 220 | container: { |
206 | flex: 1, | 221 | flex: 1, |
207 | }, | 222 | }, |
223 | + carouselSection: { | ||
224 | + width, | ||
225 | + height: sectionHeight, | ||
226 | + }, | ||
208 | sectionHeader: { | 227 | sectionHeader: { |
209 | flexDirection: 'row', | 228 | flexDirection: 'row', |
210 | height: 32, | 229 | height: 32, |
1 | -'use strict'; | ||
2 | - | ||
3 | -import React from 'react'; | ||
4 | -import ReactNative from 'react-native'; | ||
5 | -import ImmutablePropTypes from 'react-immutable-proptypes'; | ||
6 | - | ||
7 | -const { | ||
8 | - View, | ||
9 | - Image, | ||
10 | - TouchableOpacity, | ||
11 | - ListView, | ||
12 | - ScrollView, | ||
13 | - StyleSheet, | ||
14 | - Dimensions, | ||
15 | - Animated, | ||
16 | - Text, | ||
17 | -} = ReactNative; | ||
18 | - | ||
19 | -export default class Section extends React.Component { | ||
20 | - | ||
21 | - static propTypes = { | ||
22 | - data: ImmutablePropTypes.listOf( | ||
23 | - ImmutablePropTypes.contains({ | ||
24 | - image: React.PropTypes.string.isRequired, | ||
25 | - url: React.PropTypes.string.isRequired, | ||
26 | - }) | ||
27 | - ), | ||
28 | - width: React.PropTypes.number.isRequired, | ||
29 | - height: React.PropTypes.number.isRequired, | ||
30 | - onPress: React.PropTypes.func, | ||
31 | - }; | ||
32 | - | ||
33 | - constructor(props) { | ||
34 | - super (props); | ||
35 | - | ||
36 | - this.animatedValue = new Animated.Value(Dimensions.get('window').width / 2); | ||
37 | - | ||
38 | - this._renderRow = this._renderRow.bind(this); | ||
39 | - this.state = { | ||
40 | - offsetX: 0, | ||
41 | - offsetXCenter: 0 + Dimensions.get('window').width / 2, | ||
42 | - offsetXCenterAnim: new Animated.Value(Dimensions.get('window').width / 2), | ||
43 | - }; | ||
44 | - | ||
45 | - | ||
46 | - } | ||
47 | - | ||
48 | - _renderRow(item, i) { | ||
49 | - return ( | ||
50 | - <TouchableOpacity | ||
51 | - style={styles.page} | ||
52 | - key={i} | ||
53 | - > | ||
54 | - <Animated.Image source={{uri: item.get('image')}} style={[styles.image]}/> | ||
55 | - </TouchableOpacity> | ||
56 | - ); | ||
57 | - } | ||
58 | - | ||
59 | - render() { | ||
60 | - let width = this.props.width; | ||
61 | - let height = this.props.height; | ||
62 | - let data = this.props.data.toArray(); | ||
63 | - | ||
64 | - return ( | ||
65 | - <View style={styles.container}> | ||
66 | - <ScrollView | ||
67 | - contentContainerStyle={styles.contentContainer} | ||
68 | - horizontal={true} | ||
69 | - pagingEnabled={false} | ||
70 | - scrollEventThrottle={100} | ||
71 | - bounces={false} | ||
72 | - onScroll={(event) => { | ||
73 | - // console.log(event.nativeEvent); | ||
74 | - // this.offsetX = event.nativeEvent.contentOffset.x; | ||
75 | - this.setState({ | ||
76 | - offsetX: event.nativeEvent.contentOffset.x, | ||
77 | - offsetXCenter: event.nativeEvent.contentOffset.x + Dimensions.get('window').width / 2, | ||
78 | - }); | ||
79 | - }} | ||
80 | - onTouchEnd={(event) => { | ||
81 | - // console.log('offsetY:', this.offsetY); | ||
82 | - // console.log('touch info:', event.nativeEvent); | ||
83 | - }} | ||
84 | - > | ||
85 | - {data.map((item, i) => { | ||
86 | - let pageSize = 180; | ||
87 | - let pageCenter = pageSize / 2 + i * pageSize; | ||
88 | - let offsetXCenter = this.state.offsetXCenter; | ||
89 | - // console.log(offsetXCenter); | ||
90 | - // let distance = Math.abs(pageCenter - offsetXCenter); | ||
91 | - let distance = offsetXCenter - pageCenter; | ||
92 | - // i == 1 && console.log(distance); | ||
93 | - distance = Math.abs(distance); | ||
94 | - distance = distance > 180 ? 180 : distance; | ||
95 | - // i == 1 && console.log(distance); | ||
96 | - // distance = Math.round(distance * 100) / 100; | ||
97 | - | ||
98 | - let scale = this.animatedValue.interpolate({ | ||
99 | - inputRange: [-200, -distance, -distance/2, 0, distance/2, distance, 200], | ||
100 | - // inputRange: [-distance*2, -distance, -distance/2, 0, distance/2, distance, distance*2], | ||
101 | - outputRange: [1, 0.65, 0.65, 0.85, 0.65, 0.65, 1], | ||
102 | - }); | ||
103 | - // console.log(scale); | ||
104 | - return ( | ||
105 | - <TouchableOpacity | ||
106 | - style={styles.page} | ||
107 | - key={i} | ||
108 | - > | ||
109 | - <Animated.Image source={{uri: item.get('image')}} style={[styles.image, {transform: [{ scale }]}]}/> | ||
110 | - </TouchableOpacity> | ||
111 | - ); | ||
112 | - })} | ||
113 | - </ScrollView> | ||
114 | - </View> | ||
115 | - ); | ||
116 | - } | ||
117 | -} | ||
118 | - | ||
119 | -let styles = StyleSheet.create({ | ||
120 | - container: { | ||
121 | - // flexDirection: 'row', | ||
122 | - // height: 360, | ||
123 | - // backgroundColor: 'green' | ||
124 | - }, | ||
125 | - contentContainer: { | ||
126 | - flexDirection: 'row', | ||
127 | - // width: 220, | ||
128 | - backgroundColor: 'gray' | ||
129 | - }, | ||
130 | - page: { | ||
131 | - width: 180, | ||
132 | - // justifyContent: 'center', | ||
133 | - paddingHorizontal: 15, | ||
134 | - backgroundColor: 'gray', | ||
135 | - | ||
136 | - }, | ||
137 | - image: { | ||
138 | - width: 160, | ||
139 | - height: 150, | ||
140 | - // marginHorizontal: 15, | ||
141 | - }, | ||
142 | -}); |
1 | +import React from 'react'; | ||
2 | +import ReactNative from 'react-native'; | ||
3 | +import ImmutablePropTypes from 'react-immutable-proptypes'; | ||
4 | + | ||
5 | +let { | ||
6 | + requireNativeComponent | ||
7 | +} = ReactNative; | ||
8 | + | ||
9 | +// requireNativeComponent automatically resolves this to "YH_SectionViewManager" | ||
10 | +module.exports = requireNativeComponent('YH_SectionView', null); | ||
11 | + | ||
12 | +class SectionView extends React.Component { | ||
13 | + | ||
14 | + constructor(props) { | ||
15 | + super(props); | ||
16 | + | ||
17 | + this._onClick = this._onClick.bind(this); | ||
18 | + } | ||
19 | + | ||
20 | + _onClick(event: Event) { | ||
21 | + console.log(event.nativeEvent); | ||
22 | + if (!this.props.onClick) { | ||
23 | + return; | ||
24 | + } | ||
25 | + | ||
26 | + this.props.onClick(event.nativeEvent); | ||
27 | + } | ||
28 | + | ||
29 | + render() { | ||
30 | + | ||
31 | + return <YH_SectionView {...this.props} onClick={this._onClick} />; | ||
32 | + } | ||
33 | +} | ||
34 | + | ||
35 | +SectionView.propTypes = { | ||
36 | + items: ImmutablePropTypes.listOf( | ||
37 | + ImmutablePropTypes.contains({ | ||
38 | + header: ImmutablePropTypes.contains({ | ||
39 | + logo: React.PropTypes.string.isRequired, | ||
40 | + title: React.PropTypes.string.isRequired, | ||
41 | + postNum: React.PropTypes.string.isRequired, | ||
42 | + commentNum: React.PropTypes.string.isRequired, | ||
43 | + laudCount: React.PropTypes.string.isRequired, | ||
44 | + }), | ||
45 | + hot: ImmutablePropTypes.contains({ | ||
46 | + avatar: React.PropTypes.string.isRequired, | ||
47 | + content: React.PropTypes.string.isRequired, | ||
48 | + }), | ||
49 | + new: ImmutablePropTypes.contains({ | ||
50 | + avatar: React.PropTypes.string.isRequired, | ||
51 | + content: React.PropTypes.string.isRequired, | ||
52 | + }), | ||
53 | + num: ImmutablePropTypes.contains({ | ||
54 | + onedayAddNum: React.PropTypes.string.isRequired, | ||
55 | + }), | ||
56 | + }) | ||
57 | + ), | ||
58 | + onClick: React.PropTypes.func, | ||
59 | +}; | ||
60 | + | ||
61 | +let YH_SectionView = requireNativeComponent('YH_SectionView', SectionView); | ||
62 | + | ||
63 | +module.exports = SectionView; |
@@ -2,9 +2,9 @@ import keyMirror from 'key-mirror'; | @@ -2,9 +2,9 @@ import keyMirror from 'key-mirror'; | ||
2 | 2 | ||
3 | export default keyMirror({ | 3 | export default keyMirror({ |
4 | 4 | ||
5 | - HOME_BANNER_REQUEST: null, | ||
6 | - HOME_BANNER_SUCCESS: null, | ||
7 | - HOME_BANNER_FAILURE: null, | 5 | + HOME_BANNER_AND_SECTION_REQUEST: null, |
6 | + HOME_BANNER_AND_SECTION_SUCCESS: null, | ||
7 | + HOME_BANNER_AND_SECTION_FAILURE: null, | ||
8 | 8 | ||
9 | HOME_NOTICE_REQUEST: null, | 9 | HOME_NOTICE_REQUEST: null, |
10 | HOME_NOTICE_SUCCESS: null, | 10 | HOME_NOTICE_SUCCESS: null, |
@@ -178,30 +178,85 @@ class HomeContainer extends React.Component { | @@ -178,30 +178,85 @@ class HomeContainer extends React.Component { | ||
178 | let section = [ | 178 | let section = [ |
179 | [ | 179 | [ |
180 | { | 180 | { |
181 | - image: 'https://img10.static.yhbimg.com/yhb-img01/2016/06/28/17/0180ef2077db7ec5117756e47c0b61a7b1.jpg?imageView2/2/w/640/h/240', | ||
182 | - url: 'https://www.baidu.com' | 181 | + header: { |
182 | + logo: 'https://img10.static.yhbimg.com/yhb-img01/2016/06/28/12/01dcc29b14bdd04d9051c2e5ce40fe6516.jpg?imageView2/2/w/640/h/240', | ||
183 | + title: '永恒的潮流1111', | ||
184 | + postNum: '1222', | ||
185 | + commentNum: '3444', | ||
186 | + laudCount: '6765', | ||
187 | + }, | ||
188 | + hot: { | ||
189 | + avatar: 'https://img11.static.yhbimg.com/yhb-img01/2016/06/28/11/01f429fffdff555ed0c141a5ec2b4fd421.jpg?imageView2/2/w/640/h/240', | ||
190 | + content: '学院风的格子衫可能是每个男生衣橱里都会有的单件衣服学院风的格子衫可能是每个男生衣橱里都会有的单件衣服', | ||
191 | + }, | ||
192 | + new: { | ||
193 | + avatar: 'https://img11.static.yhbimg.com/yhb-img01/2016/06/28/11/01f429fffdff555ed0c141a5ec2b4fd421.jpg?imageView2/2/w/640/h/240', | ||
194 | + content: '学院风的格子衫可能是每个男生衣橱里都会有的单件衣服学院风的格子衫可能是每个男生衣橱里都会有的单件衣服', | ||
195 | + }, | ||
196 | + num: { | ||
197 | + onedayAddNum: '233334', | ||
198 | + } | ||
183 | }, | 199 | }, |
184 | { | 200 | { |
185 | - image: 'https://img11.static.yhbimg.com/yhb-img01/2016/06/28/11/01f429fffdff555ed0c141a5ec2b4fd421.jpg?imageView2/2/w/640/h/240', | ||
186 | - url: 'https://www.baidu.com' | 201 | + header: { |
202 | + logo: 'https://img10.static.yhbimg.com/yhb-img01/2016/06/28/12/01dcc29b14bdd04d9051c2e5ce40fe6516.jpg?imageView2/2/w/640/h/240', | ||
203 | + title: '永恒的潮流2222', | ||
204 | + postNum: '2222', | ||
205 | + commentNum: '222', | ||
206 | + laudCount: '2222', | ||
207 | + }, | ||
208 | + hot: { | ||
209 | + avatar: 'https://img11.static.yhbimg.com/yhb-img01/2016/06/28/11/01f429fffdff555ed0c141a5ec2b4fd421.jpg?imageView2/2/w/640/h/240', | ||
210 | + content: '学院风的格子衫可能是每个男生衣橱里都会有的单件衣服学院风的格子衫可能是每个男生衣橱里都会有的单件衣服', | ||
211 | + }, | ||
212 | + new: { | ||
213 | + avatar: 'https://img11.static.yhbimg.com/yhb-img01/2016/06/28/11/01f429fffdff555ed0c141a5ec2b4fd421.jpg?imageView2/2/w/640/h/240', | ||
214 | + content: '学院风的格子衫可能是每个男生衣橱里都会有的单件衣服学院风的格子衫可能是每个男生衣橱里都会有的单件衣服', | ||
215 | + }, | ||
216 | + num: { | ||
217 | + onedayAddNum: '2222', | ||
218 | + } | ||
187 | }, | 219 | }, |
188 | { | 220 | { |
189 | - image: 'https://img10.static.yhbimg.com/yhb-img01/2016/06/28/12/01dcc29b14bdd04d9051c2e5ce40fe6516.jpg?imageView2/2/w/640/h/240', | ||
190 | - url: 'https://www.baidu.com' | 221 | + header: { |
222 | + logo: 'https://img10.static.yhbimg.com/yhb-img01/2016/06/28/12/01dcc29b14bdd04d9051c2e5ce40fe6516.jpg?imageView2/2/w/640/h/240', | ||
223 | + title: '永恒的潮流3333', | ||
224 | + postNum: '3333', | ||
225 | + commentNum: '3333', | ||
226 | + laudCount: '3333', | ||
227 | + }, | ||
228 | + hot: { | ||
229 | + avatar: 'https://img11.static.yhbimg.com/yhb-img01/2016/06/28/11/01f429fffdff555ed0c141a5ec2b4fd421.jpg?imageView2/2/w/640/h/240', | ||
230 | + content: '学院风的格子衫可能是每个男生衣橱里都会有的单件衣服学院风的格子衫可能是每个男生衣橱里都会有的单件衣服', | ||
231 | + }, | ||
232 | + new: { | ||
233 | + avatar: 'https://img11.static.yhbimg.com/yhb-img01/2016/06/28/11/01f429fffdff555ed0c141a5ec2b4fd421.jpg?imageView2/2/w/640/h/240', | ||
234 | + content: '学院风的格子衫可能是每个男生衣橱里都会有的单件衣服学院风的格子衫可能是每个男生衣橱里都会有的单件衣服', | ||
235 | + }, | ||
236 | + num: { | ||
237 | + onedayAddNum: '33333', | ||
238 | + } | ||
191 | }, | 239 | }, |
192 | { | 240 | { |
193 | - image: 'https://img10.static.yhbimg.com/yhb-img01/2016/06/28/17/0180ef2077db7ec5117756e47c0b61a7b1.jpg?imageView2/2/w/640/h/240', | ||
194 | - url: 'https://www.baidu.com' | 241 | + header: { |
242 | + logo: 'https://img10.static.yhbimg.com/yhb-img01/2016/06/28/12/01dcc29b14bdd04d9051c2e5ce40fe6516.jpg?imageView2/2/w/640/h/240', | ||
243 | + title: '永恒的潮流4444', | ||
244 | + postNum: '4444', | ||
245 | + commentNum: '4444', | ||
246 | + laudCount: '4444', | ||
247 | + }, | ||
248 | + hot: { | ||
249 | + avatar: 'https://img11.static.yhbimg.com/yhb-img01/2016/06/28/11/01f429fffdff555ed0c141a5ec2b4fd421.jpg?imageView2/2/w/640/h/240', | ||
250 | + content: '学院风的格子衫可能是每个男生衣橱里都会有的单件衣服学院风的格子衫可能是每个男生衣橱里都会有的单件衣服', | ||
251 | + }, | ||
252 | + new: { | ||
253 | + avatar: 'https://img11.static.yhbimg.com/yhb-img01/2016/06/28/11/01f429fffdff555ed0c141a5ec2b4fd421.jpg?imageView2/2/w/640/h/240', | ||
254 | + content: '学院风的格子衫可能是每个男生衣橱里都会有的单件衣服学院风的格子衫可能是每个男生衣橱里都会有的单件衣服', | ||
255 | + }, | ||
256 | + num: { | ||
257 | + onedayAddNum: '4444', | ||
258 | + } | ||
195 | }, | 259 | }, |
196 | - { | ||
197 | - image: 'https://img11.static.yhbimg.com/yhb-img01/2016/06/28/11/01f429fffdff555ed0c141a5ec2b4fd421.jpg?imageView2/2/w/640/h/240', | ||
198 | - url: 'https://www.baidu.com' | ||
199 | - }, | ||
200 | - { | ||
201 | - image: 'https://img10.static.yhbimg.com/yhb-img01/2016/06/28/12/01dcc29b14bdd04d9051c2e5ce40fe6516.jpg?imageView2/2/w/640/h/240', | ||
202 | - url: 'https://www.baidu.com' | ||
203 | - }, | ||
204 | - | ||
205 | ], | 260 | ], |
206 | ]; | 261 | ]; |
207 | let recommendation = [ | 262 | let recommendation = [ |
@@ -11,9 +11,9 @@ import HomeService from '../../services/HomeService'; | @@ -11,9 +11,9 @@ import HomeService from '../../services/HomeService'; | ||
11 | 11 | ||
12 | const { | 12 | const { |
13 | 13 | ||
14 | - HOME_BANNER_REQUEST, | ||
15 | - HOME_BANNER_SUCCESS, | ||
16 | - HOME_BANNER_FAILURE, | 14 | + HOME_BANNER_AND_SECTION_REQUEST, |
15 | + HOME_BANNER_AND_SECTION_SUCCESS, | ||
16 | + HOME_BANNER_AND_SECTION_FAILURE, | ||
17 | 17 | ||
18 | HOME_NOTICE_REQUEST, | 18 | HOME_NOTICE_REQUEST, |
19 | HOME_NOTICE_SUCCESS, | 19 | HOME_NOTICE_SUCCESS, |
@@ -29,22 +29,22 @@ const { | @@ -29,22 +29,22 @@ const { | ||
29 | 29 | ||
30 | } = require('../../constants/actionTypes').default; | 30 | } = require('../../constants/actionTypes').default; |
31 | 31 | ||
32 | -export function bannerRequest() { | 32 | +export function bannerAndSectionRequest() { |
33 | return { | 33 | return { |
34 | - type: HOME_BANNER_REQUEST, | 34 | + type: HOME_BANNER__AND_SECTIONREQUEST, |
35 | }; | 35 | }; |
36 | } | 36 | } |
37 | 37 | ||
38 | -export function bannerSuccess(json) { | 38 | +export function bannerAndSectionSuccess(json) { |
39 | return { | 39 | return { |
40 | - type: HOME_BANNER_SUCCESS, | 40 | + type: HOME_BANNER_AND_SECTION_SUCCESS, |
41 | payload: json | 41 | payload: json |
42 | }; | 42 | }; |
43 | } | 43 | } |
44 | 44 | ||
45 | -export function bannerFailure(error) { | 45 | +export function bannerAndSectionFailure(error) { |
46 | return { | 46 | return { |
47 | - type: HOME_BANNER_FAILURE, | 47 | + type: HOME_BANNER_AND_SECTION_FAILURE, |
48 | payload: error | 48 | payload: error |
49 | }; | 49 | }; |
50 | } | 50 | } |
@@ -68,25 +68,6 @@ export function noticeFailure(error) { | @@ -68,25 +68,6 @@ export function noticeFailure(error) { | ||
68 | payload: error | 68 | payload: error |
69 | }; | 69 | }; |
70 | } | 70 | } |
71 | -export function sectionRequest() { | ||
72 | - return { | ||
73 | - type: HOME_SECTION_REQUEST, | ||
74 | - }; | ||
75 | -} | ||
76 | - | ||
77 | -export function sectionSuccess(json) { | ||
78 | - return { | ||
79 | - type: HOME_SECTION_SUCCESS, | ||
80 | - payload: json | ||
81 | - }; | ||
82 | -} | ||
83 | - | ||
84 | -export function sectionFailure(error) { | ||
85 | - return { | ||
86 | - type: HOME_SECTION_FAILURE, | ||
87 | - payload: error | ||
88 | - }; | ||
89 | -} | ||
90 | 71 | ||
91 | export function recommendationRequest() { | 72 | export function recommendationRequest() { |
92 | return { | 73 | return { |
@@ -108,16 +89,15 @@ export function recommendationFailure(error) { | @@ -108,16 +89,15 @@ export function recommendationFailure(error) { | ||
108 | }; | 89 | }; |
109 | } | 90 | } |
110 | 91 | ||
111 | -export function banner(shopId) { | ||
112 | - | 92 | +export function bannerAndSection() { |
113 | return dispatch => { | 93 | return dispatch => { |
114 | - dispatch(bannerRequest()); | ||
115 | - return new HomeService().banner(shopId) | 94 | + dispatch(bannerAndSectionRequest()); |
95 | + return new HomeService().bannerAndSection(appType) | ||
116 | .then(json => { | 96 | .then(json => { |
117 | - dispatch(bannerSuccess(json)); | 97 | + dispatch(bannerAndSectionSuccess(json)); |
118 | }) | 98 | }) |
119 | .catch(error => { | 99 | .catch(error => { |
120 | - dispatch(bannerFailure(error)); | 100 | + dispatch(bannerAndSectionFailure(error)); |
121 | }); | 101 | }); |
122 | }; | 102 | }; |
123 | } | 103 | } |
@@ -17,9 +17,9 @@ import {Record, List, Map} from 'immutable'; | @@ -17,9 +17,9 @@ import {Record, List, Map} from 'immutable'; | ||
17 | let InitialState = Record({ | 17 | let InitialState = Record({ |
18 | isFetching: false, | 18 | isFetching: false, |
19 | error: null, | 19 | error: null, |
20 | - banner: new Map(), | ||
21 | - notice: new Map(), | ||
22 | - section: new Map(), | 20 | + banner: List(), |
21 | + notice: List(), | ||
22 | + section: List(), | ||
23 | recommendation: List(), | 23 | recommendation: List(), |
24 | }); | 24 | }); |
25 | 25 |
@@ -13,9 +13,9 @@ import InitialState from './homeInitialState'; | @@ -13,9 +13,9 @@ import InitialState from './homeInitialState'; | ||
13 | 13 | ||
14 | const { | 14 | const { |
15 | 15 | ||
16 | - HOME_BANNER_REQUEST, | ||
17 | - HOME_BANNER_SUCCESS, | ||
18 | - HOME_BANNER_FAILURE, | 16 | + HOME_BANNER_AND_SECTION_REQUEST, |
17 | + HOME_BANNER_AND_SECTION_SUCCESS, | ||
18 | + HOME_BANNER_AND_SECTION_FAILURE, | ||
19 | 19 | ||
20 | HOME_NOTICE_REQUEST, | 20 | HOME_NOTICE_REQUEST, |
21 | HOME_NOTICE_SUCCESS, | 21 | HOME_NOTICE_SUCCESS, |
@@ -43,7 +43,7 @@ export default function homeReducer(state = initialState, action) { | @@ -43,7 +43,7 @@ export default function homeReducer(state = initialState, action) { | ||
43 | 43 | ||
44 | switch (action.type) { | 44 | switch (action.type) { |
45 | 45 | ||
46 | - case HOME_BANNER_REQUEST: | 46 | + case HOME_BANNER_AND_SECTION_REQUEST: |
47 | case HOME_NOTICE_REQUEST: | 47 | case HOME_NOTICE_REQUEST: |
48 | case HOME_SECTION_REQUEST: | 48 | case HOME_SECTION_REQUEST: |
49 | case HOME_RECOMMENDATION_REQUEST: { | 49 | case HOME_RECOMMENDATION_REQUEST: { |
@@ -59,7 +59,7 @@ export default function homeReducer(state = initialState, action) { | @@ -59,7 +59,7 @@ export default function homeReducer(state = initialState, action) { | ||
59 | return nextState; | 59 | return nextState; |
60 | } | 60 | } |
61 | 61 | ||
62 | - case HOME_BANNER_FAILURE: | 62 | + case HOME_BANNER_AND_SECTION_FAILURE: |
63 | case HOME_NOTICE_FAILURE: | 63 | case HOME_NOTICE_FAILURE: |
64 | case HOME_SECTION_FAILURE: | 64 | case HOME_SECTION_FAILURE: |
65 | case HOME_RECOMMENDATION_FAILURE: | 65 | case HOME_RECOMMENDATION_FAILURE: |
@@ -8,6 +8,27 @@ export default class HomeService { | @@ -8,6 +8,27 @@ export default class HomeService { | ||
8 | this.api = new Request(); | 8 | this.api = new Request(); |
9 | } | 9 | } |
10 | 10 | ||
11 | + async bannerAndSection(appType) { | ||
12 | + let authorId = 2222222; | ||
13 | + let lastedTime = 1467116660000; | ||
14 | + let limit = 10; | ||
15 | + return await this.api.get({ | ||
16 | + url: '', | ||
17 | + body: { | ||
18 | + method: 'app.social.getHomePagePostList', | ||
19 | + authorId, | ||
20 | + lastedTime, | ||
21 | + limit | ||
22 | + } | ||
23 | + }) | ||
24 | + .then((json) => { | ||
25 | + return json; | ||
26 | + }) | ||
27 | + .catch((error) => { | ||
28 | + throw(error); | ||
29 | + }); | ||
30 | + } | ||
31 | + | ||
11 | async recommendation(authorId, lastedTime) { | 32 | async recommendation(authorId, lastedTime) { |
12 | authorId = 2222222; | 33 | authorId = 2222222; |
13 | lastedTime = 1467116660000; | 34 | lastedTime = 1467116660000; |
-
Please register or login to post a comment