forgeplus-react/src/forge/users/InfosUser.js

254 lines
7.4 KiB
JavaScript
Raw Normal View History

2020-06-02 18:54:46 +08:00
import React, { Component } from "react";
2020-07-07 12:00:12 +08:00
import { Menu, Input, Spin, Pagination, Popover, Button, Divider } from "antd";
2021-09-01 17:46:58 +08:00
import CheckProfile from '../Component/ProfileModal/Profile';
2020-06-02 18:54:46 +08:00
import axios from "axios";
2020-06-03 18:10:53 +08:00
import ListItem from "../Main/IndexItem";
import Nodata from "../Nodata";
import img_new from "../Images/new.png";
import img_array from "../Images/array.png";
const Search = Input.Search;
2020-06-02 18:54:46 +08:00
class InfosUser extends Component {
constructor(props) {
super(props);
this.state = {
page: 1,
2020-06-03 18:10:53 +08:00
limit: 15,
sort_by: undefined,
2020-06-02 18:54:46 +08:00
totalCount: undefined,
isSpin: false,
2020-06-03 18:10:53 +08:00
projectsList: undefined,
total: undefined,
category: undefined,
2020-07-07 12:00:12 +08:00
is_public: undefined
2020-06-02 18:54:46 +08:00
};
}
componentDidMount = () => {
2020-06-03 18:10:53 +08:00
this.get_projects();
2020-06-02 18:54:46 +08:00
};
2020-06-03 18:10:53 +08:00
componentDidUpdate = (prevProps) => {
2020-12-14 17:04:58 +08:00
const { username } = this.props.match.params;
const prevUser = prevProps.match.params.username;
if (prevProps.project_type !== this.props.project_type || (prevUser && username && prevUser !== username)) {
2020-06-10 17:19:11 +08:00
this.get_projects();
}
};
2020-06-02 18:54:46 +08:00
2020-06-18 17:32:17 +08:00
get_projects = (isPublic) => {
2020-12-14 17:04:58 +08:00
const { username } = this.props.match.params;
const { project_type } = this.props;
const url = `/users/${username}/projects.json`;
2020-06-18 17:32:17 +08:00
const { page, limit, search, sort_by, category , is_public } = this.state;
2020-06-02 18:54:46 +08:00
this.setState({
isSpin: true,
});
2020-06-03 18:10:53 +08:00
axios
.get(url, {
params: {
page,
limit,
search,
sort_by,
category,
2020-06-10 17:19:11 +08:00
project_type,
2020-06-18 17:32:17 +08:00
is_public:isPublic!==undefined ? isPublic : is_public
2020-06-03 18:10:53 +08:00
},
})
.then((result) => {
if (result) {
this.setState({
projectsList: result.data.projects,
total: result.data.count,
isSpin: false,
});
}
})
.catch((error) => {
this.setState({
isSpin: false,
});
});
2020-06-02 18:54:46 +08:00
};
2020-06-03 18:10:53 +08:00
//切换种类
changeCategory = (cate) => {
2021-09-02 15:04:26 +08:00
this.state.page = 1;
2020-06-03 18:10:53 +08:00
this.state.category = cate.target.value;
this.get_projects();
2020-06-02 18:54:46 +08:00
};
//切换页数
changePage = (page) => {
2020-06-03 18:10:53 +08:00
this.state.page = page;
this.get_projects();
2020-06-02 18:54:46 +08:00
};
2020-06-03 18:10:53 +08:00
// 排序
ChangeSoryBy = (e) => {
this.state.sort_by = e.key;
this.get_projects();
};
2020-06-02 18:54:46 +08:00
2020-06-03 18:10:53 +08:00
changeSearchValue = (e) => {
2020-06-02 18:54:46 +08:00
this.setState({
2020-06-03 18:10:53 +08:00
search: e.target.value,
2020-06-02 18:54:46 +08:00
});
2020-06-03 18:10:53 +08:00
};
2020-06-02 18:54:46 +08:00
2020-06-18 16:05:22 +08:00
// 切换公有私有
2020-07-07 12:00:12 +08:00
changeStatus=(check_is_public)=>{
const {is_public} = this.state
const new_is_public = is_public === check_is_public ? undefined : check_is_public
this.state.is_public = new_is_public
this.get_projects(new_is_public);
2020-06-18 16:05:22 +08:00
}
2020-07-06 14:21:48 +08:00
menu =()=> (
<Menu onClick={this.ChangeSoryBy}>
<Menu.Item key="updated_on">更新时间排序</Menu.Item>
<Menu.Item key="created_on">创建时间排序</Menu.Item>
<Menu.Item key="forked_count">fork数据排序</Menu.Item>
<Menu.Item key="praises_count">点赞数量排序</Menu.Item>
</Menu>
);
2020-06-18 16:05:22 +08:00
2020-07-06 14:21:48 +08:00
newItem =()=> (
<Menu>
<Menu.Item key="created_deposit">
2021-09-09 16:49:09 +08:00
<CheckProfile {...this.props} sureFunc={()=>{this.props.history.push('/projects/deposit/new')}} >新建项目</CheckProfile>
</Menu.Item>
<Menu.Item key="created_mirror">
<CheckProfile {...this.props} sureFunc={()=>{this.props.history.push('/projects/mirror/new')}}>导入项目</CheckProfile>
2020-07-06 14:21:48 +08:00
</Menu.Item>
</Menu>
);
2021-09-01 17:46:58 +08:00
2020-07-06 14:21:48 +08:00
category_button=(category)=>{
2020-06-03 18:10:53 +08:00
const { current_user, user } = this.props;
2020-06-10 17:19:11 +08:00
const button_lists =
user && current_user && user.login === current_user.login
2020-07-06 14:21:48 +08:00
? [
{ type: undefined, name: "所有" },
{ type: "manage", name: "我创建的" },
{ type: "join", name: "我参与的" },
{ type: "watched", name: "我关注的" },
{ type: "forked", name: "我Fork的" },
]
:
[
{ type: undefined, name: "所有" },
{ type: "manage", name: "TA创建的" },
{ type: "join", name: "TA参与的" },
{ type: "watched", name: "TA关注的" },
{ type: "forked", name: "TAFork的" },
];
2020-06-03 18:10:53 +08:00
2020-07-06 14:21:48 +08:00
let list = button_lists.map((item, key) => {
return (
<span key={key} className="pr15">
<Button
type={
(category && category === item.type) || (!category && !item.type)
? "primary"
: "default"
}
ghost={
(category && category === item.type) || (!category && !item.type)
}
value={item.type}
onClick={this.changeCategory}
>
{item.name}
</Button>
</span>
);
})
return list;
}
2020-06-03 18:10:53 +08:00
2020-07-06 14:21:48 +08:00
render() {
const { current_user, user } = this.props;
const { category , is_public } = this.state;
2020-06-03 18:10:53 +08:00
const { projectsList, isSpin, total, search, limit, page } = this.state;
2020-06-02 18:54:46 +08:00
return (
2020-06-03 18:10:53 +08:00
<Spin spinning={isSpin}>
2021-06-04 13:58:42 +08:00
<div className="list-r-operation" style={{padding:"20px"}}>
2020-07-06 14:21:48 +08:00
<Search
placeholder="输入项目名称关键字进行搜索"
enterButton="搜索"
size="large"
onSearch={this.get_projects}
className="list-r-Search"
value={search}
onChange={this.changeSearchValue}
/>
<div>
{current_user && user && current_user.login === user.login && (
<Popover
content={this.newItem()}
2021-09-01 17:46:58 +08:00
trigger={["hover"]}
2020-07-06 14:21:48 +08:00
placement="bottom"
className="mr50"
>
2020-06-03 18:10:53 +08:00
<a className="ant-dropdown-link">
<span className="color-blue font-16">
2020-07-06 14:21:48 +08:00
<img src={img_new} alt="" width="13px" /> 新建
2020-06-03 18:10:53 +08:00
</span>
</a>
</Popover>
2020-07-06 14:21:48 +08:00
)}
<Popover content={this.menu()} trigger={["click"]} placement="bottom">
<a className="ant-dropdown-link">
<span className="color-blue font-16">
排序 <img src={img_array} alt="" width="10px" />
</span>
</a>
</Popover>
2020-06-18 16:05:22 +08:00
</div>
2020-07-06 14:21:48 +08:00
</div>
<div className="infosType">
<div>{this.category_button(category)}</div>
{
user && current_user && user.login === current_user.login ?
<p className="infoStatus">
<span className={is_public === "public" ? "active" : "" } onClick={()=>this.changeStatus("public")}>公有</span>
2020-07-07 12:00:12 +08:00
{
!is_public && <Divider type={"vertical"} className="statusDivider" ></Divider>
}
2020-07-06 14:21:48 +08:00
<span className={is_public === "private" ? "active" : "" } onClick={()=>this.changeStatus("private")}>私有</span>
</p>
:""
}
</div>
2020-07-06 16:11:44 +08:00
{projectsList && projectsList.length > 0 ?
<ListItem
{...this.props}
{...this.state}
projects={projectsList}
></ListItem>
:
<Nodata _html={`暂时没有项目`} />
}
2020-07-06 14:21:48 +08:00
{
2020-07-06 16:11:44 +08:00
total && total > limit ?
2020-07-07 14:28:02 +08:00
<div className="edu-txt-center pt30 mb30 border-top-grey">
2020-07-06 16:11:44 +08:00
<Pagination
simple
2021-09-02 15:04:26 +08:00
current={page}
2020-07-06 16:11:44 +08:00
total={total}
pageSize={limit}
onChange={this.changePage}
></Pagination>
</div>
:
""
2020-07-06 14:21:48 +08:00
}
2020-06-03 18:10:53 +08:00
</Spin>
2020-06-02 18:54:46 +08:00
);
}
}
export default InfosUser;