From 34f76bea58d929f745725fcac3df69ea7c3e54df Mon Sep 17 00:00:00 2001 From: guoshuyu Date: Fri, 29 Dec 2017 11:36:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=AA=E4=BA=BA=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5=E6=94=AF=E6=8C=81=E7=BB=84=E7=BB=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/PersonPage.js | 15 ++- app/components/widget/BasePersonPage.js | 161 +++++++++++++++++------- app/components/widget/UserHeadItem.js | 8 +- app/dao/db/index.js | 13 +- app/dao/userDao.js | 51 +++++++- app/net/address.js | 6 + app/store/actions/user.js | 16 ++- app/style/i18n.js | 2 + 8 files changed, 214 insertions(+), 58 deletions(-) diff --git a/app/components/PersonPage.js b/app/components/PersonPage.js index fa527e3..4c96242 100644 --- a/app/components/PersonPage.js +++ b/app/components/PersonPage.js @@ -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) => { diff --git a/app/components/widget/BasePersonPage.js b/app/components/widget/BasePersonPage.js index 5487a75..6707623 100644 --- a/app/components/widget/BasePersonPage.js +++ b/app/components/widget/BasePersonPage.js @@ -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' @@ -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' /** * 用户显示基础控件 @@ -36,6 +38,7 @@ class BasePersonPage extends Component { beStaredList: null }; this.page = 2; + this.showType = 0; } componentDidMount() { @@ -51,19 +54,36 @@ 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 ( - { - ActionUtils(rowData) - }} - actionTarget={res.actionStr}/> - ) + if (this.showType === 1) { + return (); + } else { + let res = getActionAndDes(rowData); + return ( + { + ActionUtils(rowData) + }} + actionTarget={res.actionStr}/> + ) + } } /** @@ -71,28 +91,53 @@ class BasePersonPage extends Component { * */ _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); + }) + } } /** @@ -100,22 +145,41 @@ class BasePersonPage extends Component { * */ _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() { @@ -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} diff --git a/app/components/widget/UserHeadItem.js b/app/components/widget/UserHeadItem.js index 9c2ed7b..0ab044a 100644 --- a/app/components/widget/UserHeadItem.js +++ b/app/components/widget/UserHeadItem.js @@ -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 ? - {I18n('personDynamic')} + {menuTitle} {Organizations} diff --git a/app/dao/db/index.js b/app/dao/db/index.js index 1c81e8d..fa2fcd7 100644 --- a/app/dao/db/index.js +++ b/app/dao/db/index.js @@ -182,6 +182,17 @@ const UserFollowed = { } }; +/** + * 用户关注表 + */ +const OrgMember = { + name: 'OrgMember', + properties: { + org: 'string', + data: 'string', + } +}; + /** * 用户收藏表 */ @@ -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 ] }); diff --git a/app/dao/userDao.js b/app/dao/userDao.js index 3117fc7..3f5297c 100644 --- a/app/dao/userDao.js +++ b/app/dao/userDao.js @@ -243,7 +243,6 @@ const setNotificationAsReadDao = async (id) => { }; - /** * 设置所有通知已读 */ @@ -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, @@ -307,5 +353,6 @@ export default { setAllNotificationAsReadDao, updateUserDao, doFollowDao, - checkFollowDao + checkFollowDao, + getMemberDao } diff --git a/app/net/address.js b/app/net/address.js index 93512d0..7c63d97 100644 --- a/app/net/address.js +++ b/app/net/address.js @@ -312,6 +312,12 @@ export default AddressLocal = { getEvent: (userName) => { return `${host}users/${userName}/events` }, + /** + * 组织成员 + */ + getMember:(orgs)=>{ + return `${host}orgs/${orgs}/members`; + }, /** * 通知 get */ diff --git a/app/store/actions/user.js b/app/store/actions/user.js index 5e0efd1..6218dce 100644 --- a/app/store/actions/user.js +++ b/app/store/actions/user.js @@ -159,6 +159,19 @@ const checkFollow = async (name, followed) => { } }; + +/** + * 获取组织成员 + */ +const getMember = async (page = 1, userName) => { + if (page <= 1) { + return UserDao.getMemberDao(userName, page, true); + } else { + return UserDao.getMemberDao(userName, page) + } +}; + + export default { initUserInfo, getUserInfo, @@ -171,5 +184,6 @@ export default { setAllNotificationAsRead, updateUser, doFollow, - checkFollow + checkFollow, + getMember } diff --git a/app/style/i18n.js b/app/style/i18n.js index dc7e7f8..8590026 100644 --- a/app/style/i18n.js +++ b/app/style/i18n.js @@ -45,6 +45,7 @@ I18n.translations = { FollowedText: 'followed', repositoryText: 'repository', personDynamic: 'Activity', + Member: 'Member', trendDay: 'Day', trendWeek: 'Week', trendMonth: 'Month', @@ -195,6 +196,7 @@ I18n.translations = { FollowedText: '关注', repositoryText: '仓库', personDynamic: '个人动态', + Member: '组织成员', trendDay: '今日', trendWeek: '本周', trendMonth: '本月',