Skip to content

Commit

Permalink
add Feed page
Browse files Browse the repository at this point in the history
  • Loading branch information
uniquexiaobai committed Oct 9, 2016
1 parent bedf681 commit 2f3f90d
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 64 deletions.
1 change: 0 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"pages/famous/famous",
"pages/me/me",
"pages/settings/settings",
"pages/logs/logs",
"pages/auth/onboard/onboard"
],
"window":{
Expand Down
2 changes: 1 addition & 1 deletion pages/explore/explore.wxml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<view class="container">
<loading hidden="{{loading_hidden}}" bindchange="loadingChange">
<loading hidden="{{loading_hidden}}">
玩命加载中...
</loading>
<view class="col explore">
Expand Down
1 change: 1 addition & 0 deletions pages/explore/explore.wxss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.container {
height: 100%;
background: rgba(255,255,255,0.8);
}
.explore {
flex: 1;
Expand Down
2 changes: 1 addition & 1 deletion pages/famous/famous.wxml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<view class="container">
<loading hidden="{{loading_hidden}}" bindchange="loadingChange">
<loading hidden="{{loading_hidden}}">
玩命加载中...
</loading>
<view class="col famous">
Expand Down
1 change: 1 addition & 0 deletions pages/famous/famous.wxss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.container {
height: 100%;
background: rgba(255,255,255,0.8);
}
.famous {
flex: 1;
Expand Down
31 changes: 31 additions & 0 deletions pages/helper/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

function formateActionType (type) {
switch (type) {
case 'CreateEvent':
return 'Create';
case 'DeleteEvent':
return 'Delete';
case 'ForkEvent':
return 'Forked';
case 'WatchEvent':
return 'Started';
case 'PushEvent':
return 'Push';
case 'PullRequestEvent':
return 'Pull Request';
case 'IssuesEvent':
return 'Create Issue'
case 'IssueCommentEvent':
return 'Comment Issue';
case 'MemberEvent':
return 'Add Member'
case 'PullRequestReviewCommentEvent':
return 'Pull Request Review';
default:
return 'Started';
}
}

module.exports = {
formateActionType: formateActionType
};
52 changes: 43 additions & 9 deletions pages/index/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,63 @@
const app = getApp();
const services = require('../../utils/services.js');
const helper = require('../helper/index.js');

Page({
data: {
motto: 'Feed',
loading_hidden: true,
items: [],
page: 1
},

onLoad() {
onLoad () {
const user = wx.getStorageSync('user');
console.log(user);
if(!user) {
wx.navigateTo({
url: '../auth/onboard/onboard'
});
}
this.refreshData();
},

bindViewTap() {
wx.navigateTo({
url: '../logs/logs'
})
_reloadUrl () {
const basic_url = 'https://api.github.com/users/uniquexiaobai/received_events?page=';
return basic_url + this.data.page;
},

goRouteSignIn() {
wx.navigateTo({
url: '../auth/onboard/onboard'
_initData () {
this.setData({
items: [],
page: 1
});
},

fetchEventsData (url) {
services.fetch(url).then(res => {
console.log(res.data);
res.data.forEach(item => {
item.type = helper.formateActionType(item.type);
});
this.setData({
items: this.data.items.concat(res.data),
loading_hidden: true
});
});
},

loadMoreData () {
this.setData({
page: ++this.data.page,
loading_hidden: false
});
this.fetchEventsData(this._reloadUrl());
},

refreshData () {
this.setData({
loading_hidden: false
});
this._initData();
this.fetchEventsData(this._reloadUrl());
}
});
27 changes: 20 additions & 7 deletions pages/index/index.wxml
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
<view class="container col">
<view bindtap="bindViewTap" class="userinfo">
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
<text>{{motto}}</text>
</view>
<view class="routes">
<button bindtap="goRouteSignIn" type="primary" size="mini">SignIn</button>
</view>
<loading hidden="{{loading_hidden}}" bindchange="loadingChange">
玩命加载中...
</loading>
<scroll-view scroll-y="true" bindscrolltolower="loadMoreData" bindscrolltoupper="refreshData">
<block wx:for="{{items}}">
<view class="col received_events">
<view class="row received_event_top">
<image class="actor_avatar" mode="aspectFit" src="{{item.actor.avatar_url}}"></image>
<view class="col">
<view class="actor_name">{{item.actor.display_login}}</view>
<text class="action_time">1 hours ago</text>
</view>
</view>
<view class="row received_event_bottom">
<text class="action_type">{{item.type}}</text>
<view class="action_repo">{{item.repo.name}}</view>
</view>
</view>
</block>
</scroll-view>
</view>
49 changes: 35 additions & 14 deletions pages/index/index.wxss
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
.container {
height: 100%;
background: rgba(255,255,255,0.8);
}

.userinfo-avatar {
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
scroll-view {
width: 100%;
height: 100%;
}
.received_events {
border-bottom: 1rpx solid #ccc;
padding: 15rpx;
}

.userinfo-nickname {
color: #aaa;
.received_event_top {
color: #5D5D5D;
}
.actor_avatar {
width: 80rpx;
height: 80rpx;
margin-right: 30rpx;
}
.actor_name {
color: #6491CC;
}
.action_time {
color: #B8B8B8;
font-size: 8rpx;
}

.routes {
display: flex;
.received_event_bottom {
margin-top: 10rpx;
}
.action_type {
font-size: 25rpx;
font-weight: bold;
margin-right: 20rpx;
}
.action_repo {
font-size: 16rpx;
color: #6491CC;
}
14 changes: 0 additions & 14 deletions pages/logs/logs.js

This file was deleted.

3 changes: 0 additions & 3 deletions pages/logs/logs.json

This file was deleted.

6 changes: 0 additions & 6 deletions pages/logs/logs.wxml

This file was deleted.

8 changes: 0 additions & 8 deletions pages/logs/logs.wxss

This file was deleted.

0 comments on commit 2f3f90d

Please sign in to comment.