Skip to content

Commit 2179fa1

Browse files
committed
post list render
1 parent 1a8935b commit 2179fa1

File tree

11 files changed

+102
-108
lines changed

11 files changed

+102
-108
lines changed

source/common/index.js

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,14 @@ export function getRandomColor(){
1818
}
1919

2020
export function getBloggerAvatar(avatarUri){
21-
if (avatarUri && !_.endsWith(avatarUri, ".gif")) {
21+
if (avatarUri && avatarUri!="https://pic.cnblogs.com/face/" &&!_.endsWith(avatarUri, ".gif")) {
2222
avatarUri = avatarUri.replace(/face/, 'avatar');
2323
avatarUri = avatarUri.replace(/avatar\/u/, 'avatar\/a');
2424
return avatarUri;
2525
}
2626
return Config.appInfo.avatar;
2727
}
2828

29-
/**
30-
* 从2016年这个炎热的8月开始,
31-
* 博客园新闻列表 & 详情接口,返回的图片格式出现错误:
32-
* 列表:http://images0.cnblogs.com/news_topic///images2015.cnblogs.com/news_topic/20160627211458609-1031834166.png
33-
* 详情://images2015.cnblogs.com/news/66372/201608/66372-20160817121401015-627031105.jpg
34-
* wtf
35-
* 所以打个补丁兼容一下。
36-
*============================================================================================================= */
37-
export function formatNewsImgUri(uri){
38-
if(uri){
39-
uri = uri.replace("images0.cnblogs.com/news_topic///", "");
40-
if(!_.startsWith(uri, "http:")){
41-
uri = "http:" + uri;
42-
}
43-
}
44-
45-
return uri;
46-
}
47-
4829
export function filterCodeSnippet(codeText) {
4930
if (codeText && codeText.length) {
5031
codeText = _.trim(codeText);
@@ -71,7 +52,7 @@ export function decodeHTML(htmlStr) {
7152
return htmlStr;
7253
}
7354

74-
const imageSourcePath = Config.domain + "/public/img/metarial/";
55+
const imageSourcePath = Config.assetDomain + "/public/img/metarial/";
7556
export function getImageSource(key){
7657
let imageLen = 20;
7758
if (!key) {

source/component/drawerPanel.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
import TimerMixin from 'react-timer-mixin';
1010
import Icon from 'react-native-vector-icons/Ionicons';
1111
import PureRenderMixin from 'react-addons-pure-render-mixin';
12-
import Config, { drawerItems, postCategory } from '../config';
12+
import Config, { postCategory } from '../config';
13+
import drawerItems from '../config/drawer';
1314
import { getImageSource } from '../common';
1415
import { CommonStyles, DrawerPanelStyles, StyleConfig } from '../style';
1516

@@ -52,12 +53,15 @@ class DrawerPanel extends Component {
5253
style={ DrawerPanelStyles.headerBg }
5354
resizeMode="stretch"
5455
source={ {uri:backgroundImageSource} }>
55-
<Text style={ DrawerPanelStyles.headerTitle }>
56-
{ Config.appInfo.name }
57-
</Text>
58-
<Text style={ DrawerPanelStyles.headerSub }>
59-
{ Config.appInfo.descr }
60-
</Text>
56+
<View style={ DrawerPanelStyles.headerContent }>
57+
<Image
58+
style={ DrawerPanelStyles.headerAvatar }
59+
source={{uri:"http://123.56.135.166/cnblog/public/img/common/author.jpg"}}/>
60+
<View style={ DrawerPanelStyles.headerText}>
61+
<Text style={ DrawerPanelStyles.headerName}>愤怒的晃晃</Text>
62+
<Text style={ DrawerPanelStyles.headerDate}>2016-09-06 12:23:45</Text>
63+
</View>
64+
</View>
6165
</Image>
6266
</View>
6367
)
@@ -136,7 +140,6 @@ class DrawerPanel extends Component {
136140
}
137141
}
138142

139-
140143
export default DrawerPanel;
141144

142145

source/component/homeRender.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class HomeRender extends Component {
101101
}
102102

103103
renderParallaxStickyHeader(){
104+
105+
console.info(backgroundImageSource);
106+
104107
return (
105108
<Navbar
106109
backgroundImage = { {uri: backgroundImageSource} }

source/component/postList.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ class PostList extends Component {
5252
}
5353

5454
renderListRow(post) {
55-
if(post && post.id){
55+
if(post && post.Id){
5656
return (
5757
<PostRow
58-
key={ post.id }
58+
key={ post.Id }
5959
post={ post }
6060
category={ this.props.category }
6161
onRowPress={ (e)=>this.onListRowPress(e) } />

source/component/postRow.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import _ from 'lodash';
1010
import moment from 'moment';
1111
import PureRenderMixin from 'react-addons-pure-render-mixin';
12-
import { decodeHTML, formatNewsImgUri } from '../common';
12+
import { decodeHTML, getBloggerAvatar } from '../common';
1313
import Config from '../config';
1414
import { PostStyles, CommonStyles, StyleConfig } from '../style';
1515

@@ -24,22 +24,22 @@ class PostRow extends Component {
2424
getPostInfo(){
2525
const { post } = this.props;
2626
let postInfo = {};
27-
if (post && post.id) {
28-
postInfo.id = post.id;
29-
postInfo.title = decodeHTML(post.title);
30-
if (post.summary) {
31-
postInfo.summary = _.truncate(decodeHTML(post.summary), { length : 60 });
27+
if (post && post.Id) {
28+
postInfo.Id = post.Id;
29+
postInfo.Title = decodeHTML(post.Title);
30+
if (post.Description) {
31+
postInfo.Description = _.truncate(decodeHTML(post.Description), { length : 60 });
3232
}
33-
postInfo.published = moment(post.published).startOf('minute').fromNow();
34-
postInfo.authorName = decodeHTML(post.author.name);
35-
if (post.author.avatar) {
36-
postInfo.authorAvatar = formatNewsImgUri(post.author.avatar);
33+
postInfo.PostDate = moment(post.PostDate).startOf('minute').fromNow();
34+
postInfo.Author = decodeHTML(post.Author);
35+
if (post.Avatar) {
36+
postInfo.Avatar = getBloggerAvatar(post.Avatar);
3737
}else{
38-
postInfo.authorAvatar = Config.appInfo.avatar;
38+
postInfo.Avatar = Config.appInfo.avatar;
3939
}
40-
postInfo.comments = post.comments;
41-
postInfo.views = post.views;
42-
postInfo.authorUri = post.author.uri;
40+
postInfo.CommentCount = post.CommentCount;
41+
postInfo.ViewCount = post.ViewCount;
42+
postInfo.Url = post.Url;
4343
}
4444
return postInfo;
4545
}
@@ -49,13 +49,13 @@ class PostRow extends Component {
4949
let metasContent = [];
5050
metasContent.push(
5151
<Text key='meta-date' style={ PostStyles.metaText }>
52-
{ postInfo.published }
52+
{ postInfo.PostDate }
5353
</Text>
5454
);
5555
metasContent.push(
5656
<View key='meta-count' style={ PostStyles.metaRight } >
5757
<Text style={ [PostStyles.metaText, { color: StyleConfig.mainColor }] }>
58-
{ postInfo.comments + ' / ' + postInfo.views }
58+
{ postInfo.CommentCount + ' / ' + postInfo.ViewCount }
5959
</Text>
6060
</View>
6161
);
@@ -68,30 +68,30 @@ class PostRow extends Component {
6868
<TouchableHighlight
6969
onPress={(e)=>{ this.props.onRowPress(postInfo) }}
7070
underlayColor={ StyleConfig.touchablePressColor }
71-
key={ postInfo.id }>
71+
key={ postInfo.Id }>
7272

7373
<View style={ CommonStyles.rowContainer }>
7474
<View style={ PostStyles.authorInfo }>
7575
<Image ref={view => this.imgView=view}
7676
style={ PostStyles.authorAvatar }
77-
source={ {uri:postInfo.authorAvatar} }>
77+
source={ {uri:postInfo.Avatar} }>
7878
</Image>
7979
<Text style={ PostStyles.authorName }>
80-
{ postInfo.authorName }
80+
{ postInfo.Author }
8181
</Text>
8282
</View>
8383

8484
<View>
8585
<Text style={ PostStyles.title }>
86-
{ postInfo.title }
86+
{ postInfo.Title }
8787
</Text>
8888
</View>
8989

9090
{
91-
postInfo.summary?
91+
postInfo.Description?
9292
<View>
9393
<Text style={ PostStyles.summary }>
94-
{ postInfo.summary }
94+
{ postInfo.Description }
9595
</Text>
9696
</View>
9797
: null

source/config/drawer.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

2-
export const drawerItems = [{
2+
import { postCategory } from './index';
3+
4+
export default [{
35
text: "首页",
46
icon: "ios-home-outline",
57
action: "refresh",
@@ -15,17 +17,17 @@ export const drawerItems = [{
1517
action: "refresh",
1618
flag: postCategory.news
1719
},{
18-
text: "离线",
20+
text: "闪存",
1921
icon: "ios-download-outline",
2022
action: "toOffline",
2123
flag:"offline"
2224
},{
23-
text: "设置",
25+
text: "博问",
2426
icon: "ios-cog",
2527
action: "toSetting",
2628
flag:"setting"
2729
},{
28-
text: "关于",
30+
text: "离线",
2931
icon: "ios-redo-outline",
3032
action: "toAbout",
3133
flag:"about"

source/config/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
export default {
3-
domain:'https://api.cnblogs.com/',
43
appInfo:{
54
name:'博客园',
65
avatar:'http://123.56.135.166/cnblog/public/img/common/avatar.jpg?v=1.0',
@@ -16,7 +15,9 @@ export default {
1615
avatar: 'http://123.56.135.166/cnblog/public/img/common/author.jpg',
1716
homepage: 'https://github.com/togayther',
1817
declare: '本软件为个人学习交流作品,博文内容来源于博客园官方开放接口,版权为博客园及原作者所有。'
19-
}
18+
},
19+
apiDomain:'https://api.cnblogs.com/',
20+
assetDomain: 'http://123.56.135.166/cnblog',
2021
};
2122

2223
export const postCategory = {

source/service/request.js

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Config, { authData } from '../config';
22
import { Base64 } from '../common/base64';
33
import * as UserToken from './token';
44

5-
const apiDomain = Config.domain;
5+
const apiDomain = Config.apiDomain;
66
const timeout = 15000;
77

88
function filterJSON(res) {
@@ -45,41 +45,36 @@ function timeoutFetch(ms, promise) {
4545

4646

4747
export function request(uri, type = "GET", headers = {}, data = ""){
48-
49-
if(!headers["Authorization"]){
50-
51-
UserToken.getToken();
52-
console.info("token");
53-
console.info(token);
54-
55-
headers["Authorization"] = 'Bearer kangming';
56-
}
57-
58-
uri = Config.domain + uri;
59-
let fetchOption = {
60-
method: type,
61-
headers: headers
62-
};
63-
64-
if(type === "POST"){
65-
fetchOption.body = data;
66-
}
67-
68-
if(__DEV__){
69-
console.log("fetch data from uri:");
70-
console.log(uri)
71-
console.log("headers:");
72-
console.log(headers);
73-
console.log("data:");
74-
console.log(data);
75-
}
76-
77-
return timeoutFetch(timeout, fetch(uri, fetchOption))
78-
.then(filterStatus)
79-
.then(filterJSON)
80-
.catch(function(error) {
81-
throw error;
82-
});
48+
return UserToken.getToken().then((token)=>{
49+
if(!headers["Authorization"]){
50+
headers["Authorization"] = `Bearer ${token.access_token}`;
51+
}
52+
uri = Config.apiDomain + uri;
53+
let fetchOption = {
54+
method: type,
55+
headers: headers
56+
};
57+
58+
if(type === "POST"){
59+
fetchOption.body = data;
60+
}
61+
62+
if(__DEV__){
63+
console.log("fetch data from uri:");
64+
console.log(uri)
65+
console.log("headers:");
66+
console.log(headers);
67+
console.log("data:");
68+
console.log(data);
69+
}
70+
71+
return timeoutFetch(timeout, fetch(uri, fetchOption))
72+
.then(filterStatus)
73+
.then(filterJSON)
74+
.catch(function(error) {
75+
throw error;
76+
});
77+
});
8378
}
8479

8580
export function get(uri, headers = {}) {

source/service/token.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@ import { storageKey } from '../config';
22
import * as storageService from './storage';
33

44
export function getToken() {
5-
return storageService.getItem(storageKey.USER_TOKEN).then((token)=>{
6-
return token;
7-
});
5+
return storageService.getItem(storageKey.USER_TOKEN);
86
}

source/service/userService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as Util from '../common';
55
import { Base64 } from '../common/base64';
66

77
import { authData } from '../config';
8-
import dataApi from '../config/api';
8+
import dataApi from '../config/api';
99

1010
function filterData(data) {
1111
try{

source/style/index.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -503,17 +503,28 @@ export const DrawerPanelStyles = StyleSheet.create({
503503
flexDirection:'column',
504504
paddingLeft: StyleConfig.contentPadding
505505
},
506-
headerTitle:{
507-
fontSize: 24,
508-
marginTop: 30,
509-
marginBottom: 5,
510-
color:'#fff'
506+
headerContent:{
507+
flexDirection:'row',
508+
alignItems:'center'
511509
},
512-
headerSub:{
513-
fontSize: 16,
514-
color: 'rgba(255,255,255, 0.6)'
510+
headerAvatar:{
511+
width: 60,
512+
height: 60,
513+
borderRadius: 30,
514+
marginRight: 10
515+
},
516+
headerText:{
517+
flexDirection:'column',
518+
justifyContent:'space-between'
519+
},
520+
headerName:{
521+
fontSize: 20,
522+
color:'#f2f2f2',
523+
marginBottom: 5
515524
},
516-
avatar:{
525+
headerDate:{
526+
fontSize: 12,
527+
color: '#aaa'
517528
},
518529
list:{
519530
paddingTop: 10

0 commit comments

Comments
 (0)