2021-05-28 16:19:40 +08:00
|
|
|
|
import React, { useEffect, useState } from 'react';
|
2021-06-02 18:22:29 +08:00
|
|
|
|
import { FlexAJ , AlignCenter } from '../../Component/layout';
|
2021-05-28 16:19:40 +08:00
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
import Box from './ConcentrateBox';
|
|
|
|
|
|
|
|
|
|
|
|
function ConcentrateProject({userLogin,current}) {
|
|
|
|
|
|
const [ list , setList ] = useState(undefined);
|
|
|
|
|
|
const [ visible , setVisible ] = useState(false);
|
|
|
|
|
|
const [ value , setValue ] = useState([]);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(()=>{
|
|
|
|
|
|
getList();
|
|
|
|
|
|
},[])
|
|
|
|
|
|
|
|
|
|
|
|
function getList() {
|
|
|
|
|
|
const url = `/users/${userLogin}/is_pinned_projects.json`;
|
|
|
|
|
|
axios.get(url).then(result=>{
|
|
|
|
|
|
if(result && result.data){
|
|
|
|
|
|
let p = result.data.projects;
|
|
|
|
|
|
setList(p);
|
|
|
|
|
|
if(p && p.length > 0){
|
|
|
|
|
|
let array = p.map(i=>{
|
2021-06-02 18:22:29 +08:00
|
|
|
|
return i.project_id
|
2021-05-28 16:19:40 +08:00
|
|
|
|
})
|
|
|
|
|
|
setValue(array);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}).catch(erroer=>{})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onSure(is_pinned_project_ids) {
|
|
|
|
|
|
const url = `/users/${userLogin}/is_pinned_projects/pin.json`;
|
|
|
|
|
|
axios.post(url,{
|
|
|
|
|
|
is_pinned_project_ids
|
|
|
|
|
|
}).then(result=>{
|
|
|
|
|
|
if(result && result.data){
|
|
|
|
|
|
setVisible(false);
|
|
|
|
|
|
getList();
|
|
|
|
|
|
}
|
|
|
|
|
|
}).catch(error=>{})
|
|
|
|
|
|
}
|
|
|
|
|
|
return(
|
2021-05-31 18:39:30 +08:00
|
|
|
|
<React.Fragment>
|
2021-05-28 16:19:40 +08:00
|
|
|
|
<Box visible={visible} onCancel={()=>setVisible(false)} onSure={onSure} username={userLogin} choosed={value}/>
|
|
|
|
|
|
{
|
|
|
|
|
|
list && list.length>0 &&
|
|
|
|
|
|
<div className="concentrate">
|
2021-06-02 18:22:29 +08:00
|
|
|
|
<FlexAJ>
|
2021-05-28 16:19:40 +08:00
|
|
|
|
<span className="font-18">精选项目</span>
|
|
|
|
|
|
{ current && <a className="color-blue" onClick={()=>setVisible(true)}>自定义精选项目</a> }
|
2021-06-02 18:22:29 +08:00
|
|
|
|
</FlexAJ>
|
2021-05-28 16:19:40 +08:00
|
|
|
|
<div>
|
|
|
|
|
|
<ul className="concentrateUl">
|
|
|
|
|
|
{
|
|
|
|
|
|
list.map((i,k)=>{
|
|
|
|
|
|
return(
|
|
|
|
|
|
<li>
|
2021-06-02 18:22:29 +08:00
|
|
|
|
<Link to={`/projects/${i.author && i.author.login}/${i.identifier}`} className="name">{i.name}</Link>
|
2021-05-28 16:19:40 +08:00
|
|
|
|
<p className="task-hide desc">{i.description}</p>
|
|
|
|
|
|
<AlignCenter>
|
|
|
|
|
|
{ i.category && <span className="tagName">{i.category.name}</span> }
|
|
|
|
|
|
<span className="pariseCount"><i className="iconfont icon-guanzhu"></i>{i.watchers_count}</span>
|
|
|
|
|
|
<span className="forkCount"><i className="iconfont icon-fork"></i>{i.forked_count}</span>
|
|
|
|
|
|
</AlignCenter>
|
|
|
|
|
|
</li>
|
|
|
|
|
|
)
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
|
|
|
list && list.length === 0 && current && <div className="ConcentrateTip"><i className="iconfont icon-tishi2"></i>你还没有设置精选项目,<a onClick={()=>setVisible(true)}>点击设置</a></div>
|
|
|
|
|
|
}
|
2021-05-31 18:39:30 +08:00
|
|
|
|
</React.Fragment>
|
2021-05-28 16:19:40 +08:00
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
export default ConcentrateProject;
|