Skip to content

Commit

Permalink
优化个人详情页支持组织
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuoSmall committed Dec 29, 2017
1 parent 2f138ee commit 34f76be
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 58 deletions.
15 changes: 12 additions & 3 deletions app/components/PersonPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,24 @@ class PersonPage extends BasePersonPage {
if (res && res.result) {
this.setState({
userInfo: res.data
})
});
if (res.data.type === "Organization") {
Actions.refresh({titleData: res.data, showType: "Organization"});
} else {
Actions.refresh({titleData: res.data});
}
}
Actions.refresh({titleData: res.data});
return res.next();
}).then((res) => {
if (res && res.result) {
this.setState({
userInfo: res.data
})
});
if (res.data.type === "Organization") {
Actions.refresh({titleData: res.data, showType: "Organization"});
} else {
Actions.refresh({titleData: res.data});
}
}
});
userAction.checkFollow(this.props.currentUser).then((res) => {
Expand Down
161 changes: 113 additions & 48 deletions app/components/widget/BasePersonPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import styles from "../../style"
import * as Constant from '../../style/constant'
import eventActions from '../../store/actions/event'
import userActions from '../../store/actions/user'
import repositoryActions from '../../store/actions/repository'
import UserHeadItem from './UserHeadItem'
import PullListView from './PullLoadMoreListView'
Expand All @@ -17,6 +18,7 @@ import {getActionAndDes, ActionUtils} from '../../utils/eventUtils'
import * as Config from '../../config'
import I18n from '../../style/i18n'
import resolveTime from '../../utils/timeUtil'
import UserItem from '../widget/UserItem'

/**
* 用户显示基础控件
Expand All @@ -36,6 +38,7 @@ class BasePersonPage extends Component {
beStaredList: null
};
this.page = 2;
this.showType = 0;
}

componentDidMount() {
Expand All @@ -51,71 +54,132 @@ class BasePersonPage extends Component {

}


componentWillReceiveProps(newProps) {
if (newProps.showType && newProps.showType !== this.props.showType && newProps.showType === "Organization") {
this.showType = 1;
newProps.showType = "";
this._refresh();
}
}

_renderRow(rowData, sectionID, rowID, highlightRow) {
let res = getActionAndDes(rowData);
return (
<EventItem
actionTime={rowData.created_at}
actionUser={rowData.actor.display_login}
actionUserPic={rowData.actor.avatar_url}
des={res.des}
onPressItem={() => {
ActionUtils(rowData)
}}
actionTarget={res.actionStr}/>
)
if (this.showType === 1) {
return (<UserItem
location={rowData.location}
actionUser={rowData.login}
actionUserPic={rowData.avatar_url}
des={rowData.bio}/>);
} else {
let res = getActionAndDes(rowData);
return (
<EventItem
actionTime={rowData.created_at}
actionUser={rowData.actor.display_login}
actionUserPic={rowData.actor.avatar_url}
des={res.des}
onPressItem={() => {
ActionUtils(rowData)
}}
actionTarget={res.actionStr}/>
)
}
}

/**
* 刷新
* */
_refresh() {
let userInfo = this.getUserInfo();
eventActions.getEvent(1, userInfo.login).then((res) => {
if (res && res.result) {
this.setState({
dataSource: res.data
});
}
return res.next();
}).then((res) => {
let size = 0;
if (res && res.result) {
this.page = 2;
this.setState({
dataSource: res.data
});
size = res.data.length;
}
setTimeout(() => {
if (this.refs.pullList) {
this.refs.pullList.refreshComplete((size >= Config.PAGE_SIZE), false);
if (this.showType === 1) {
userActions.getMember(1, userInfo.login).then((res) => {
if (res && res.result) {
this.setState({
dataSource: res.data
});
}
}, 500);
})
return res.next();
}).then((res) => {
let size = 0;
if (res && res.result) {
this.page = 2;
this.setState({
dataSource: res.data
});
size = res.data.length;
}
setTimeout(() => {
if (this.refs.pullList) {
this.refs.pullList.refreshComplete((size >= Config.PAGE_SIZE), false);
}
}, 500);
})
} else {
eventActions.getEvent(1, userInfo.login).then((res) => {
if (res && res.result) {
this.setState({
dataSource: res.data
});
}
return res.next();
}).then((res) => {
let size = 0;
if (res && res.result) {
this.page = 2;
this.setState({
dataSource: res.data
});
size = res.data.length;
}
setTimeout(() => {
if (this.refs.pullList) {
this.refs.pullList.refreshComplete((size >= Config.PAGE_SIZE), false);
}
}, 500);
})
}
}

/**
* 加载更多
* */
_loadMore() {
let userInfo = this.getUserInfo();
eventActions.getEvent(this.page, userInfo.login).then((res) => {
this.page++;
let size = 0;
if (res && res.result) {
let localData = this.state.dataSource.concat(res.data);
this.setState({
dataSource: localData
});
size = res.data.length;
}
setTimeout(() => {
if (this.refs.pullList) {
this.refs.pullList.loadMoreComplete((size >= Config.PAGE_SIZE));
if (this.showType === 1) {
userActions.getMember(this.page, userInfo.login).then((res) => {
this.page++;
let size = 0;
if (res && res.result) {
let localData = this.state.dataSource.concat(res.data);
this.setState({
dataSource: localData
});
size = res.data.length;
}
setTimeout(() => {
if (this.refs.pullList) {
this.refs.pullList.loadMoreComplete((size >= Config.PAGE_SIZE));
}
}, 500);
});
} else {
eventActions.getEvent(this.page, userInfo.login).then((res) => {
this.page++;
let size = 0;
if (res && res.result) {
let localData = this.state.dataSource.concat(res.data);
this.setState({
dataSource: localData
});
size = res.data.length;
}
}, 500);
});
setTimeout(() => {
if (this.refs.pullList) {
this.refs.pullList.loadMoreComplete((size >= Config.PAGE_SIZE));
}
}, 500);
});
}
}

_getMoreInfo() {
Expand Down Expand Up @@ -176,6 +240,7 @@ class BasePersonPage extends Component {
hadFollowed={this.getHanFollow()}
userDisPlayName={userInfo.login}
userName={userInfo.name}
userType={userInfo.type}
isOrganizations={"Organization" === userInfo.type || !userInfo.type}
userPic={userInfo.avatar_url}
groupName={userInfo.company}
Expand Down
8 changes: 5 additions & 3 deletions app/components/widget/UserHeadItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ class UserHeadItem extends Component {
let {
link, userPic, userName, userDisPlayName, des, location, groupName,
follower, followed, repos, star, setting, unRead, settingNeed, needFollow, hadFollowed, beStared,
doFollowLogic, beStaredList, isOrganizations
doFollowLogic, beStaredList, isOrganizations, userType
} = this.props;

let followView = needFollow ? <TouchableOpacity
let followView = (needFollow && !isOrganizations) ? <TouchableOpacity
style={[styles.flexDirectionRowNotFlex, {
marginTop: Constant.normalMarginEdge,
borderColor: Constant.miWhite,
Expand All @@ -118,6 +118,8 @@ class UserHeadItem extends Component {

let Organizations = this.getActivity(isOrganizations, userDisPlayName);

let menuTitle = !userType ? "" : (userType === "Organization" ? I18n("Member") : I18n("personDynamic"));

return (
<View>
<View style={[{
Expand Down Expand Up @@ -320,7 +322,7 @@ class UserHeadItem extends Component {
fontWeight: "bold", marginTop: Constant.normalMarginEdge,
marginLeft: Constant.normalMarginEdge,
}]}>
{I18n('personDynamic')}
{menuTitle}
</Text>
</View>
{Organizations}
Expand Down
13 changes: 12 additions & 1 deletion app/dao/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ const UserFollowed = {
}
};

/**
* 用户关注表
*/
const OrgMember = {
name: 'OrgMember',
properties: {
org: 'string',
data: 'string',
}
};

/**
* 用户收藏表
*/
Expand Down Expand Up @@ -258,7 +269,7 @@ let realm = new Realm({
RepositoryDetail, RepositoryDetailReadme, RepositoryEvent, RepositoryIssue,
RepositoryBranch, RepositoryWatcher, RepositoryStar, RepositoryFork, RepositoryCommits,
UserFollower, UserFollowed, UserStared, UserRepos, RepositoryCommitInfoDetail,
IssueDetail, IssueComment, ReadHistory, RepositoryPulse
IssueDetail, IssueComment, ReadHistory, RepositoryPulse, OrgMember
]
});

Expand Down
51 changes: 49 additions & 2 deletions app/dao/userDao.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ const setNotificationAsReadDao = async (id) => {
};



/**
* 设置所有通知已读
*/
Expand Down Expand Up @@ -296,6 +295,53 @@ const checkFollowDao = async (name) => {
}
};

/**
* 组织成员
*/
const getMemberDao = async (userName, page, localNeed) => {
let nextStep = async () => {
let url = Address.getMember(userName) + Address.getPageParams("?", page);
let res = await await Api.netFetch(url);
if (res && res.result && res.data.length > 0 && page <= 1) {
realm.write(() => {
let allEvent = realm.objects('OrgMember').filtered(`org="${userName}"`);
realm.delete(allEvent);
res.data.forEach((item) => {
realm.create('OrgMember', {
org: userName,
data: JSON.stringify(item)
});
})
});
}
return {
data: res.data,
result: res.result
};
};
let local = async () => {
let allData = realm.objects('OrgMember').filtered(`org="${userName}"`);
if (allData && allData.length > 0) {
let data = [];
allData.forEach((item) => {
data.push(JSON.parse(item.data));
});
return {
data: data,
next: nextStep,
result: true
};
} else {
return {
data: [],
next: nextStep,
result: false
};
}
};
return localNeed ? local() : nextStep();
};


export default {
getUserInfoLocal,
Expand All @@ -307,5 +353,6 @@ export default {
setAllNotificationAsReadDao,
updateUserDao,
doFollowDao,
checkFollowDao
checkFollowDao,
getMemberDao
}
6 changes: 6 additions & 0 deletions app/net/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ export default AddressLocal = {
getEvent: (userName) => {
return `${host}users/${userName}/events`
},
/**
* 组织成员
*/
getMember:(orgs)=>{
return `${host}orgs/${orgs}/members`;
},
/**
* 通知 get
*/
Expand Down
Loading

0 comments on commit 34f76be

Please sign in to comment.