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

95 lines
3.2 KiB
React
Raw Normal View History

2020-06-03 09:56:07 +08:00
import React, { useEffect, useState } from "react";
import styled from "styled-components";
import { Button ,Spin } from "antd";
import { truncateCommitId } from '../common/util';
2020-11-10 16:42:32 +08:00
import { getImageUrl } from 'educoder';
import Files from '../Merge/Files';
2020-06-03 09:56:07 +08:00
import User from "../Component/User";
import Keys from "../Component/Keys";
import axios from "axios";
2020-05-29 17:00:42 +08:00
const Infos = styled.div`
2020-06-03 09:56:07 +08:00
border: 1px solid #dddddd;
2020-11-10 16:42:32 +08:00
margin-bottom:15px;
2020-06-03 09:56:07 +08:00
& .commitinfos {
background-color: #f1f8ff;
border-bottom: 1px solid #ddd;
padding: 20px;
2020-05-29 17:00:42 +08:00
}
2020-06-03 09:56:07 +08:00
& > .f-wrap-between {
2020-11-10 16:42:32 +08:00
padding: 10px 20px;
2020-05-29 17:00:42 +08:00
}
`;
2020-11-10 16:42:32 +08:00
export default ({ match , history }) => {
2020-07-07 09:25:56 +08:00
const [data, setData] = useState({undefined});
2020-06-03 09:56:07 +08:00
const [commit, setCommit] = useState(undefined);
const [parents, setParents] = useState(undefined);
const [committer, setCommitter] = useState(undefined);
const [isSpin, setIsSpin] = useState(true);
2020-05-29 17:00:42 +08:00
2020-11-10 16:42:32 +08:00
const { sha , projectsId, owner } = match.params;
2020-06-03 09:56:07 +08:00
useEffect(() => {
2020-11-10 16:42:32 +08:00
if (projectsId && owner && sha) {
const url = `/${owner}/${projectsId}/commits/${sha}.json`;
2020-06-03 09:56:07 +08:00
axios
.get(url)
.then(result => {
if (result) {
setData(result.data);
setCommit(result.data.commit);
setParents(result.data.parents);
setCommitter(result.data.committer || (result.data.commit && result.data.commit.committer));
setIsSpin(false);
}
})
.catch(error => {
console.log(error);
});
}
2020-11-10 16:42:32 +08:00
}, [projectsId , owner, sha]);
2020-06-03 09:56:07 +08:00
return (
<div className="main">
<Spin spinning={isSpin}>
<Infos>
<div className="commitinfos">
2020-11-10 16:42:32 +08:00
<div className="f-wrap-between">
{commit && commit.message &&
<pre className="task-hide" style={{marginBottom:"0px",height:"28px",whiteSpace:"pre-wrap"}}>{commit.message}</pre>
}
2021-03-18 17:28:53 +08:00
<Button type="primary" onClick={()=>{history.push(`/projects/${owner}/${projectsId}/tree/${truncateCommitId(sha)}`)}} className="ml30">浏览代码</Button>
2020-11-10 16:42:32 +08:00
</div>
2020-06-03 09:56:07 +08:00
</div>
<div className="f-wrap-between" style={{ alignItems: "center" }}>
<ul className="df">
<User
url={(committer && getImageUrl(`/${committer.image_url}`))|| "https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3025493530,1989042357&fm=26&gp=0.jpg"}
2020-06-03 09:56:07 +08:00
name={committer && committer.name}
/>
2020-11-10 16:42:32 +08:00
{committer && committer.time_from_now && <li className="ml20 mt2">{committer.time_from_now}</li>}
2020-06-03 09:56:07 +08:00
</ul>
<li className="df">
{
parents && parents.length > 0 && parents.map((item,key)=>{
return(
2020-11-11 16:09:57 +08:00
<Keys title="父节点" value={truncateCommitId(item.sha)} key={key} className="mr20"></Keys>
2020-06-03 09:56:07 +08:00
)
})
}
<Keys title="当前节点" value={truncateCommitId(sha)}></Keys>
</li>
</div>
</Infos>
2020-11-10 16:42:32 +08:00
<Files
history={history}
data={data}
owner={owner}
projectsId={projectsId}
/>
2020-06-03 09:56:07 +08:00
</Spin>
2020-05-29 17:00:42 +08:00
</div>
2020-06-03 09:56:07 +08:00
);
};