forgeplus-react/src/forge/Main/CoderRootIndex.js

152 lines
4.5 KiB
JavaScript
Raw Normal View History

2020-03-16 14:12:11 +08:00
import React , { Component } from 'react';
2020-05-20 18:11:32 +08:00
import { Route , Switch } from 'react-router-dom';
// import Top from './DetailTop';
2020-03-16 14:12:11 +08:00
import Loadable from 'react-loadable';
import Loading from '../../Loading';
2020-07-03 16:32:47 +08:00
import axios from 'axios';
import './Index.scss';
2020-03-16 14:12:11 +08:00
2020-07-03 16:32:47 +08:00
const FileNew = Loadable({
loader: () => import('../Newfile/Index'),
loading: Loading,
})
const UploadFile = Loadable({
loader: () => import('../Newfile/upload_file'),
loading: Loading,
})
2020-03-16 14:12:11 +08:00
const CoderRootCommit = Loadable({
loader: () => import('./CoderRootCommit'),
loading: Loading,
})
const CoderRootBranch = Loadable({
loader: () => import('./tree/Index'),
2020-03-16 14:12:11 +08:00
loading: Loading,
})
2020-05-20 18:11:32 +08:00
const CoderRootTag = Loadable({
loader: () => import('./tag/Index'),
2020-05-20 18:11:32 +08:00
loading: Loading,
})
const CoderRootVersion = Loadable({
loader: () => import('./version/Index'),
2020-05-20 18:11:32 +08:00
loading: Loading,
})
// const CoderRootVersionNew = Loadable({
// loader: () => import('./version/New'),
// loading: Loading,
// })
// const CoderRootVersionUpdate = Loadable({
// loader: () => import('./version/New'),
// loading: Loading,
// })
2020-05-29 17:00:42 +08:00
const Diff = Loadable({
loader: () => import('./Diff'),
loading: Loading,
})
2020-03-30 18:51:30 +08:00
2020-03-16 14:12:11 +08:00
class CoderRootIndex extends Component{
2020-07-03 16:32:47 +08:00
constructor(props){
super(props);
this.state={
coderCount:undefined
}
}
componentDidMount=()=>{
2020-11-24 10:46:27 +08:00
this.Init();
}
componentDidUpdate=(prevProps)=>{
const { location } = this.props;
const prevlocation = prevProps && prevProps.location;
if (location !== prevlocation) {
this.Init();
2020-07-03 16:32:47 +08:00
}
2020-11-24 10:46:27 +08:00
}
Init=()=>{
const { branchName } = this.props.match.params;
2020-11-24 18:00:34 +08:00
const { defaultBranch } = this.props;
this.getTopCount(branchName || defaultBranch);
2020-07-03 16:32:47 +08:00
}
2021-03-18 17:28:53 +08:00
// 获取<Top />组件里要显示的数据
2020-07-03 16:32:47 +08:00
getTopCount=(branch)=>{
2020-08-12 18:13:18 +08:00
const { projectsId , owner } = this.props.match.params;
const url = `/${owner}/${projectsId}/top_counts.json`;
2020-07-03 16:32:47 +08:00
axios.get(url,{params:{
ref:branch
}}).then(result=>{
if(result){
this.setState({
coderCount:result.data
})
}
}).catch(error=>{console.log(error);})
}
2020-03-16 14:12:11 +08:00
render(){
return(
<div className="coderSubPage">
{/* <Top {...this.props} {...this.state}/> */}
2020-03-16 14:12:11 +08:00
<Switch {...this.props}>
2020-07-03 16:32:47 +08:00
{/* 新建文件 */}
2021-09-01 09:33:22 +08:00
<Route path="/:owner/:projectsId/:branch/newfile/:path"
2020-07-03 16:32:47 +08:00
render={
(props) => (<FileNew {...this.props} {...props} {...this.state} />)
}
></Route>
2021-09-01 09:33:22 +08:00
<Route path="/:owner/:projectsId/:branch/uploadfile"
2020-07-03 16:32:47 +08:00
render={
(props) => (<UploadFile {...this.props} {...props} {...this.state} />)
}
></Route>
2021-09-01 09:33:22 +08:00
<Route path="/:owner/:projectsId/:branch/newfile"
2020-07-03 16:32:47 +08:00
render={
2020-07-03 17:26:07 +08:00
(props) => (<FileNew {...this.props} {...props} {...this.state} getTopCount={this.getTopCount} />)
2020-07-03 16:32:47 +08:00
}
></Route>
2021-09-01 09:33:22 +08:00
<Route path="/:owner/:projectsId/commits/branch/:branchName"
2021-08-03 17:37:14 +08:00
render={
() => (<CoderRootCommit {...this.props} {...this.state} commit_class="main" getTopCount={this.getTopCount} />)
}
></Route>
2021-09-24 11:27:32 +08:00
<Route path="/:owner/:projectsId/commits/:sha/:branchName"
2020-03-16 14:12:11 +08:00
render={
2020-11-10 16:42:32 +08:00
(props) => (<Diff {...this.props} {...props} {...this.state}/>)
2020-03-16 14:12:11 +08:00
}
></Route>
2021-09-01 09:33:22 +08:00
<Route path="/:owner/:projectsId/commits"
2020-05-29 17:00:42 +08:00
render={
2020-11-10 16:42:32 +08:00
() => (<CoderRootCommit {...this.props} {...this.state} commit_class="main" getTopCount={this.getTopCount} />)
2020-05-29 17:00:42 +08:00
}
></Route>
{/* <Route path="/:owner/:projectsId/releases/:versionId/update"
2020-05-20 18:11:32 +08:00
render={
2020-08-19 18:34:52 +08:00
(props) => (<CoderRootVersionUpdate {...this.props} {...this.state} {...props} />)
2020-05-20 18:11:32 +08:00
}
></Route>
2021-09-01 09:33:22 +08:00
<Route path="/:owner/:projectsId/releases/new"
2020-05-20 18:11:32 +08:00
render={
2020-08-19 18:34:52 +08:00
() => (<CoderRootVersionNew {...this.props} {...this.state} />)
2020-05-20 18:11:32 +08:00
}
></Route> */}
2021-09-01 09:33:22 +08:00
<Route path="/:owner/:projectsId/releases"
2020-05-20 18:11:32 +08:00
render={
2020-07-03 16:32:47 +08:00
() => (<CoderRootVersion {...this.props} {...this.state} />)
2020-05-20 18:11:32 +08:00
}
></Route>
2021-09-03 09:23:12 +08:00
<Route path="/:owner/:projectsId/tags"
2020-05-20 18:11:32 +08:00
render={
2020-07-03 16:32:47 +08:00
() => (<CoderRootTag {...this.props} {...this.state} />)
2020-05-20 18:11:32 +08:00
}
></Route>
2021-09-03 11:38:22 +08:00
<Route path="/:owner/:projectsId/branches"
2020-03-16 14:12:11 +08:00
render={
2020-07-03 16:32:47 +08:00
() => (<CoderRootBranch {...this.props} {...this.state} />)
2020-03-16 14:12:11 +08:00
}
></Route>
</Switch>
</div>
)
}
}
export default CoderRootIndex;