forgeplus-react/src/forge/Main/CoderDepotReadme.jsx

75 lines
2.3 KiB
React
Raw Normal View History

import React, { useEffect, useState } from 'react';
2021-03-18 17:28:53 +08:00
import RenderHtml from '../../components/render-html';
2021-06-30 10:43:22 +08:00
import { AlignCenter } from '../Component/layout';
2021-08-13 17:12:56 +08:00
import { Dropdown , Anchor , Spin } from 'antd';
2021-08-12 11:45:56 +08:00
import ReadmeCatelogue from './sub/ReadmeCatelogue';
const $ = window.$;
2021-03-18 17:28:53 +08:00
function CoderDepotReadme({ operate , history , readme , ChangeFile }){
const [ menuList ,setMenuList ] = useState(undefined);
2021-05-21 18:58:17 +08:00
const [ content ,setContent ] = useState(undefined);
useEffect(()=>{
if(readme && readme.content){
2021-05-21 18:58:17 +08:00
setContent(readme.content);
2021-06-04 10:55:05 +08:00
}else{
setContent(undefined);
}
},[readme])
2021-05-21 19:21:16 +08:00
useEffect(()=>{
let path = history.location.pathname;
const items = $.map($("#readme").find("h1,h2,h3,h4,h5,h6"), function (el, _) {
const anchor = el.id;
const level = el.tagName.replace("H", "");
const href = `#${anchor}`;
2021-08-12 11:45:56 +08:00
return { href:`${href}`,text:el.textContent , level:level }
2021-05-21 19:21:16 +08:00
});
setMenuList(items);
},[content])
function menu(){
if(menuList && menuList.length > 0){
return(
2021-08-13 17:12:56 +08:00
<ReadmeCatelogue menuList={menuList} hash={history.location.hash}/>
)
}else{
return <Spin />
}
}
2021-08-13 17:12:56 +08:00
2021-03-18 17:28:53 +08:00
return(
2021-08-12 11:45:56 +08:00
<div className="commonBox readBox" id="readme">
2021-08-13 17:12:56 +08:00
<Anchor offsetTop={70} targetOffset={160}>
2021-09-08 18:00:51 +08:00
<div className="commonBox-title boxTitle" style={{overflow:"hidden"}}>
2021-08-13 17:12:56 +08:00
<AlignCenter>
<Dropdown overlay={menu()} trigger={['hover']} overlayClassName="menuslist">
<span className="catelogue">
<i className="iconfont icon-muluicon font-12 mr5"></i>
<span>目录</span>
</span>
</Dropdown>
2021-09-02 15:22:34 +08:00
<a href="#readme ">
2021-09-02 10:38:59 +08:00
<span className="commonBox-title-read">README.md</span>
</a>
2021-08-13 17:12:56 +08:00
</AlignCenter>
{
operate ?
<a className="ml20 pull-right" onClick={() =>ChangeFile(readme && readme.path, false)}>
<i className="iconfont icon-a-bianji font-17 color-grey-6"></i>
</a>
:""
}
</div>
</Anchor>
2021-05-25 10:05:14 +08:00
{
content &&
<div className="commonBox-info">
<RenderHtml className="break_word_comments imageLayerParent" value={content} url={history.location}/>
</div>
}
2021-03-18 17:28:53 +08:00
</div>
)
}
export default CoderDepotReadme;