Skip to content

Commit 5b90408

Browse files
committed
handle some render detail.
1 parent 2d82e09 commit 5b90408

27 files changed

+365
-209
lines changed

source/action/comment.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@ import * as commentService from '../service/commentService';
44

55
export const getCommentsByPost = createAction(
66
types.FETCH_COMMENTS_BY_POST,
7-
async(category, pid, params)=> {
8-
return await commentService.getCommentsByPost(category, pid, {
7+
async(category, id, params)=> {
8+
return await commentService.getCommentsByPost(category, id, {
99
pageIndex: 1,
1010
...params
1111
});
1212
},
13-
(category, pid)=>{
13+
(category, id)=>{
1414
return {
1515
pending: true,
1616
category,
17-
pid
17+
id
1818
}
1919
}
2020
);
2121

2222
export const getCommentsByPostWithPage = createAction(
2323
types.FETCH_COMMENTS_BY_POST_WITHPAGE,
24-
async(category, pid, params)=> {
25-
return await commentService.getCommentsByPost(category, pid, params);
24+
async(category, id, params)=> {
25+
return await commentService.getCommentsByPost(category, id, params);
2626
},
27-
(category, pid)=> {
27+
(category, id)=> {
2828
return {
2929
pending: true,
3030
category,
31-
pid
31+
id
3232
}
3333
}
3434
);

source/action/config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import * as storageService from '../service/storage';
55

66
export const updateConfig = createAction(types.UPDATE_CONFIG, async({key, value})=> {
77
return storageService.mergeItem(key, value);
8-
}, ({key, value})=>{
8+
}, ({key, value, resolved, rejected})=>{
99
return {
1010
key,
11-
value
11+
value,
12+
resolved,
13+
rejected
1214
}
1315
});
1416

source/action/offline.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const savePost = createAction(types.OFFLINE_POST_TO_STORAGE, async(postDa
1212
export const getPost = createAction(types.GET_POST_FROM_STORAGE, async(id)=> {
1313
return storageService.getItem(storageKey.OFFLINE_POSTS).then((posts)=>{
1414
if (posts && posts[id]) {
15-
return posts[id].string;
15+
return posts[id].postContent;
1616
}
1717
return null;
1818
});

source/component/bar/post.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Text,
44
View,
55
Image,
6+
StyleSheet,
67
ToastAndroid,
78
TouchableOpacity
89
} from 'react-native';
@@ -11,7 +12,7 @@ import Icon from 'react-native-vector-icons/Ionicons';
1112
import PureRenderMixin from 'react-addons-pure-render-mixin';
1213
import { getBloggerName } from '../../common';
1314
import { postCategory, storageKey } from '../../config';
14-
import { ComponentStyles, StyleConfig } from '../../style';
15+
import { ComponentStyles, CommonStyles, StyleConfig } from '../../style';
1516

1617
class PostBar extends Component {
1718

@@ -34,16 +35,15 @@ class PostBar extends Component {
3435

3536
onOfflinePress(){
3637
let { post, postContent, category, offlineAction } = this.props;
37-
if (post && postContent && postContent.string) {
38+
if (post && postContent) {
3839
let offlineInfo = {};
39-
let offlineMeta = {
40+
let offlineData = {
4041
category: category,
42+
postContent: postContent,
4143
offlineDate: moment()
4244
};
45+
offlineInfo[post.Id] = {...post, ...offlineData};
4346

44-
offlineInfo[post.id] = {...post, ...postContent, ...offlineMeta};
45-
46-
4747
offlineAction.savePost(offlineInfo).then(()=>{
4848
ToastAndroid.show("离线保存成功", ToastAndroid.LONG);
4949
});
@@ -64,57 +64,56 @@ class PostBar extends Component {
6464
return (
6565
<TouchableOpacity
6666
onPress={ ()=> this.props.router.pop() }
67-
style={ ComponentStyles.barItem }>
67+
style={ [ ComponentStyles.bar_item ] }>
6868
<Icon
6969
name='ios-arrow-round-back'
70-
style={ ComponentStyles.barItemIcon }/>
70+
size = { StyleConfig.icon_size }/>
7171
</TouchableOpacity>
7272
);
7373
}
7474

7575
renderCommentItem(){
7676
const { post } = this.props;
77-
if (post.comments && post.comments!="0") {
77+
if (post.CommentCount && post.CommentCount!="0") {
7878
return (
7979
<TouchableOpacity
8080
onPress = {()=> this.onCommentPress() }
81-
style={ ComponentStyles.barItem }>
81+
style={ [ ComponentStyles.bar_item ] }>
8282
<Icon
8383
name='ios-chatbubbles-outline'
84-
style={ [ComponentStyles.barItemIcon, ComponentStyles.barItemIconActive ] }/>
85-
<View style={ ComponentStyles.barItemBadge }>
86-
<Text style={ ComponentStyles.barItemBadgeText }>
87-
{ post.comments }
88-
</Text>
89-
</View>
84+
size = { StyleConfig.icon_size - 4 }/>
85+
<View style={ ComponentStyles.bar_item_badge }>
86+
<Text style={ ComponentStyles.bar_item_badge_text }>
87+
{ post.CommentCount }
88+
</Text>
89+
</View>
9090
</TouchableOpacity>
9191
);
9292
}
9393

9494
return (
9595
<TouchableOpacity
9696
onPress = {()=> this.onCommentPress() }
97-
style={ ComponentStyles.barItem }>
97+
style={ [ ComponentStyles.bar_item ] }>
9898
<Icon
9999
name='ios-chatbubbles-outline'
100-
style={ [ComponentStyles.barItemIcon, { fontSize: 20 }] }/>
100+
size = { StyleConfig.icon_size -4 }/>
101101
</TouchableOpacity>
102102
);
103103
}
104104

105105

106106
renderAuthorItem(){
107107
let { router, category } = this.props;
108-
109108
let previousRoute = router.getPreviousRoute();
110109
if (previousRoute && previousRoute.name === "home" && category != postCategory.news) {
111110
return (
112111
<TouchableOpacity
113112
onPress = {()=>this.onAuthorPress() }
114-
style={ ComponentStyles.barItem }>
113+
style={ [ ComponentStyles.bar_item ] }>
115114
<Icon
116115
name='ios-person-outline'
117-
style={ ComponentStyles.barItemIcon }/>
116+
size = { StyleConfig.icon_size }/>
118117
</TouchableOpacity>
119118
);
120119
}
@@ -125,18 +124,18 @@ class PostBar extends Component {
125124
return (
126125
<TouchableOpacity
127126
onPress = {()=> this.onOfflinePress() }
128-
style={ ComponentStyles.barItem }>
127+
style={ [ ComponentStyles.bar_item ] }>
129128
<Icon
130129
name='ios-download-outline'
131-
style={ ComponentStyles.barItemIcon }/>
130+
size = { StyleConfig.icon_size }/>
132131
</TouchableOpacity>
133132
);
134133
}
135134

136135
render() {
137136
let { post } = this.props;
138137
return (
139-
<View style={ ComponentStyles.container }>
138+
<View style={ [ ComponentStyles.bar_container ] }>
140139
{ this.renderReturnItem() }
141140
{ this.renderCommentItem() }
142141
{ this.renderAuthorItem() }

source/component/htmlConvertor.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ class HtmlRender extends Component {
2323

2424
constructor(props) {
2525
super(props);
26-
this.images = {};
27-
2826
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
2927
}
3028

@@ -90,12 +88,16 @@ class HtmlRender extends Component {
9088
if(node.type == 'tag'){
9189
//note: 解析图片
9290
if(node.name == "img" && node.attribs && node.attribs.src){
91+
92+
let imageUri = node.attribs.src;
9393

94-
if(imgDisabled === true){
94+
// 1,禁用图片加载
95+
// 2,每篇博文尾部会附加:<img src="http://counter.cnblogs.com//blog/post/5876249" width="1" height="1" style="border:0px;visibility:hidden"/>
96+
// 不渲染图片
97+
if(imgDisabled === true || imageUri.indexOf("counter.cnblogs.com") > 0){
9598
return undefined;
9699
}
97100

98-
let imageUri = node.attribs.src;
99101
let imageId = _.uniqueId('image_');
100102
return (
101103
<ImageBox

source/component/listview/newsRow.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class NewsRow extends Component {
3030

3131
newsInfo.Title = decodeHTML(news.Title);
3232
if (news.Summary) {
33-
newsInfo.Summary = _.truncate(decodeHTML(news.Summary), { length : 70 });
33+
newsInfo.Description = _.truncate(decodeHTML(news.Summary), { length : 70 });
3434
}
3535
newsInfo.DateAdded = moment(news.DateAdded).startOf('minute').fromNow();
3636
newsInfo.Avatar = news.TopicIcon;
@@ -52,7 +52,7 @@ class NewsRow extends Component {
5252
return (
5353
<View style={ [ CommonStyles.m_b_2 ] }>
5454
<Text style={ [ CommonStyles.text_gray, CommonStyles.font_xs, CommonStyles.line_height_sm ] }>
55-
{ newsInfo.Summary }
55+
{ newsInfo.Description }
5656
</Text>
5757
</View>
5858
)

source/component/listview/offlineList.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ class OfflineList extends Component {
3131

3232
onListRowPress(post){
3333
this.props.router.toOfflinePost({
34-
id: post.id,
34+
id: post.Id,
3535
category: this.props.category,
3636
post
3737
});
3838
}
3939

4040
renderListRow(post) {
41-
if(post && post.id){
41+
if(post && post.Id){
4242
return (
4343
<OfflineRow
44-
key={ post.id }
44+
key={ post.Id }
4545
post={ post }
4646
onRowPress={ (e)=>this.onListRowPress(e) } />
4747
)

source/component/listview/offlineRow.js

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,66 @@ class OfflineRow extends Component {
2020
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
2121
}
2222

23-
renderPostRowMetas(post){
23+
renderPostAuthor(postInfo){
24+
if (postInfo.category != postCategory.news) {
25+
return (
26+
<View style={ [ CommonStyles.flexRow, CommonStyles.flexItemsMiddle, CommonStyles.m_b_2 ] }>
27+
<Image ref={view => this.imgView=view}
28+
style={ [ ComponentStyles.avatar_mini, CommonStyles.m_r_2] }
29+
source={ {uri:postInfo.Avatar} }>
30+
</Image>
31+
<Text style={ [ CommonStyles.text_danger, CommonStyles.font_xs ] }>
32+
{ postInfo.Author }
33+
</Text>
34+
</View>
35+
)
36+
}
37+
}
38+
39+
renderPostTitle(postInfo){
40+
return (
41+
<View style={ [ CommonStyles.m_b_1 ] }>
42+
<Text style={ [CommonStyles.text_black, CommonStyles.font_sm, CommonStyles.line_height_md ] }>
43+
{ postInfo.Title }
44+
</Text>
45+
</View>
46+
)
47+
}
48+
49+
renderPostDescr(postInfo){
50+
return (
51+
<View style={ [ CommonStyles.m_b_2 ] }>
52+
<Text style={ [ CommonStyles.text_gray, CommonStyles.font_xs, CommonStyles.line_height_sm ] }>
53+
{ postInfo.Description }
54+
</Text>
55+
</View>
56+
)
57+
}
2458

25-
let offlineDate = moment(post.offlineDate).startOf('minute').fromNow();
59+
renderPostMeta(postInfo){
60+
let offlineDate = moment(postInfo.offlineDate).startOf('minute').fromNow();
2661
let postCategoryLabel,
2762
postCategoryColor;
28-
if (post.category == postCategory.news) {
63+
if (postInfo.category == postCategory.news) {
2964
postCategoryLabel = "#新闻";
30-
postCategoryColor = StyleConfig.secondaryColor;
65+
postCategoryColor = StyleConfig.color_danger;
3166
}else{
3267
postCategoryLabel = "#博文";
33-
postCategoryColor = StyleConfig.mainColor;
68+
postCategoryColor = StyleConfig.color_primary;
3469
}
35-
36-
let metasContent = [];
37-
metasContent.push(
38-
<Text key='meta-date' style={ ComponentStyles.metaText }>
39-
离线日期:{ offlineDate }
40-
</Text>
41-
);
42-
metasContent.push(
43-
<View key='meta-count' style={ ComponentStyles.metaRight } >
44-
<Text style={ [ComponentStyles.metaText, {color: postCategoryColor }] }>
45-
{ postCategoryLabel }
70+
return (
71+
<View style={ [ CommonStyles.flexRow, CommonStyles.flexItemsBetween ] }>
72+
<Text style={ CommonStyles.text_gray }>
73+
离线日期:{ offlineDate }
4674
</Text>
75+
76+
<View>
77+
<Text style={ [ { color: postCategoryColor} ] }>
78+
{ postCategoryLabel }
79+
</Text>
80+
</View>
4781
</View>
48-
);
49-
return metasContent;
82+
)
5083
}
5184

5285
render() {
@@ -56,44 +89,14 @@ class OfflineRow extends Component {
5689
return (
5790
<TouchableHighlight
5891
onPress={(e)=>{ this.props.onRowPress(post) }}
59-
underlayColor={ StyleConfig.touchablePressColor }
60-
key={ post.id }>
61-
62-
<View style={ CommonStyles.rowContainer }>
63-
<View style={ ComponentStyles.authorInfo }>
64-
{
65-
post.authorAvatar?
66-
<Image ref={view => this.imgView=view}
67-
style={ ComponentStyles.authorAvatar }
68-
source={{ uri: post.authorAvatar }}>
69-
</Image>
70-
:null
71-
}
72-
73-
<Text style={ ComponentStyles.authorName }>
74-
{ post.authorName }
75-
</Text>
76-
</View>
77-
78-
<View>
79-
<Text style={ ComponentStyles.title }>
80-
{ post.title }
81-
</Text>
82-
</View>
83-
84-
{
85-
post.summary?
86-
<View>
87-
<Text style={ ComponentStyles.summary }>
88-
{ post.summary }
89-
</Text>
90-
</View>
91-
: null
92-
}
92+
underlayColor={ StyleConfig.touchable_press_color }
93+
key={ post.Id }>
9394

94-
<View style={ ComponentStyles.metaInfo }>
95-
{ this.renderPostRowMetas(post) }
96-
</View>
95+
<View style={ ComponentStyles.list }>
96+
{ this.renderPostAuthor(post) }
97+
{ this.renderPostTitle(post) }
98+
{ this.renderPostDescr(post) }
99+
{ this.renderPostMeta(post) }
97100
</View>
98101
</TouchableHighlight>
99102
)

0 commit comments

Comments
 (0)