Merge pull request '代码库二级页面issue中readme更改' (#99) from hc1913847458/forgeplus-react:feature_repo_second_page into feature_repo_second_page

This commit is contained in:
jasder 2021-09-30 17:16:30 +08:00
commit 030c6ad61f
1 changed files with 27 additions and 16 deletions

View File

@ -67,14 +67,14 @@ function CoderDepot(props){
const [ editReadme , setEditReadme ] = useState(false);
const [ pullsFlag , setPullsFlag ] = useState(true);
const [ issuesFlag , setIssuesFlag ] = useState(true);
const [ releaseVersions , setReleaseVersions] = useState(undefined);
const details = props.projectDetail;
const owner = props.match.params.owner;
const projectsId = props.match.params.projectsId;
let branchName = props.match.params.branchName;
branchName = returnbar(branchName);
const details = props.projectDetail;
let pathname = props.history.location.pathname;
const { bannerList } = props;
useEffect(()=>{
@ -90,6 +90,7 @@ function CoderDepot(props){
}
},[bannerList])
useEffect(()=>{
if(details){
setProjectDetail(details);
@ -99,7 +100,7 @@ function CoderDepot(props){
setDefaultBranch(details.default_branch);
setInviteCode(details.invite_code);
}
})
},[details])
useEffect(()=>{
if(treeValue){
@ -118,30 +119,40 @@ function CoderDepot(props){
setTreeValue(url);
getFileInfo(url,branchName);
setType("file");
getReadmeInfo(url,branchName);
}else{
setTreeValue(undefined);
getDirInfo(branchName || defaultBranch);
setType("dir");
getReadmeInfo('', branchName || defaultBranch);
}
}
},[projectsId,owner,pathname,defaultBranch])
useEffect(()=>{
axios.get(`/${owner}/${projectsId}/releases.json`).then((result)=>{
if(result && result.data){
const release = {
"list":result.data.releases,
"total_count":result.data.releases.length
}
setReleaseVersions(release);
// readme
function getReadmeInfo(path, ref) {
axios.get(`/${owner}/${projectsId}/readme.json`, {
params:{
owner: owner,
repo: projectsId,
filepath:path,
ref:ref || branchName
}
}).then((result) => {
console.log('getReadmeInfo', result)
if (result) {
setReadme(result.data);
} else {
setReadme(undefined);
}
})
},[])
}
//
function getDirInfo(branch){
setIsSpin(true);
const url = `/${owner}/${projectsId}/entries.json`;
axios.get(url, {
params: { ref: branch }
}).then((result) => {
@ -156,7 +167,7 @@ function CoderDepot(props){
setLastCommitAuthor(c && c.committer);
setMainFlag(true);
setReadOnly(true);
setReadme(result.data.readme);
// setReadme(result.data.readme);
setEditReadme(false);
setHide(true);
}
@ -201,7 +212,7 @@ function CoderDepot(props){
setLastCommit(c && c.commit);
setLastCommitAuthor(c && c.committer);
setMainFlag(false);
setReadme(result.data.readme)
// setReadme(result.data.readme);
setReadOnly(true);
setReadOnly(!editReadme);
setHide(true);
@ -532,13 +543,13 @@ function CoderDepot(props){
}
{/* 发布 */}
{
releaseVersions &&
projectDetail && projectDetail.release_versions &&
<React.Fragment>
<Divider />
<Releases
owner={owner}
projectsId={projectsId}
releaseVersions={releaseVersions}
releaseVersions={projectDetail.release_versions}
history={props.history}
baseOperate={baseOperate}
projectType={projectDetail.type}