2023-10-31 21:06:39 +08:00
|
|
|
import React from 'react';
|
2022-12-29 12:21:47 +08:00
|
|
|
import ReactDom from 'react-dom';
|
2018-12-25 10:39:57 +08:00
|
|
|
import axios from 'axios';
|
2019-05-15 14:56:46 +08:00
|
|
|
import { fileName, historyRepoID } from './utils/constants';
|
2018-09-12 17:01:48 +08:00
|
|
|
import SidePanel from './pages/file-history/side-panel';
|
|
|
|
import MainPanel from './pages/file-history/main-panel';
|
2019-03-04 22:34:29 +08:00
|
|
|
import { seafileAPI } from './utils/seafile-api';
|
2018-12-25 10:39:57 +08:00
|
|
|
|
2018-09-12 17:01:48 +08:00
|
|
|
import './css/layout.css';
|
|
|
|
import './css/file-history.css';
|
|
|
|
|
|
|
|
class FileHistory extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
renderingContent: true,
|
2018-12-25 10:39:57 +08:00
|
|
|
newMarkdownContent: '',
|
|
|
|
oldMarkdownContent: ''
|
2018-09-12 17:01:48 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-02-11 17:38:28 +08:00
|
|
|
setDiffContent = (newMarkdownContent, oldMarkdownContent)=> {
|
2018-09-26 02:27:14 -07:00
|
|
|
this.setState({
|
|
|
|
renderingContent: false,
|
2019-02-11 17:38:28 +08:00
|
|
|
newMarkdownContent: newMarkdownContent,
|
2018-12-25 10:39:57 +08:00
|
|
|
oldMarkdownContent: oldMarkdownContent,
|
2018-09-12 17:01:48 +08:00
|
|
|
});
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-09-12 17:01:48 +08:00
|
|
|
|
2018-09-26 02:27:14 -07:00
|
|
|
|
2018-12-25 10:39:57 +08:00
|
|
|
onHistoryItemClick = (item, preItem)=> {
|
2018-09-12 17:01:48 +08:00
|
|
|
this.setState({renderingContent: true});
|
2018-12-25 10:39:57 +08:00
|
|
|
if (preItem) {
|
|
|
|
axios.all([
|
2019-03-04 22:34:29 +08:00
|
|
|
seafileAPI.getFileRevision(historyRepoID, item.commit_id, item.path),
|
|
|
|
seafileAPI.getFileRevision(historyRepoID, preItem.commit_id, preItem.path)
|
|
|
|
]).then(axios.spread((res, res1) => {
|
|
|
|
axios.all([
|
|
|
|
seafileAPI.getFileContent(res.data),
|
|
|
|
seafileAPI.getFileContent(res1.data)
|
|
|
|
]).then(axios.spread((content1, content2) => {
|
|
|
|
this.setDiffContent(content1.data, content2.data);
|
2019-05-15 14:56:46 +08:00
|
|
|
}));
|
2018-12-25 10:39:57 +08:00
|
|
|
}));
|
|
|
|
} else {
|
2019-03-04 22:34:29 +08:00
|
|
|
seafileAPI.getFileRevision(historyRepoID, item.commit_id, item.path).then((res) => {
|
|
|
|
axios.all([
|
|
|
|
seafileAPI.getFileContent(res.data),
|
|
|
|
]).then(axios.spread((content1) => {
|
|
|
|
this.setDiffContent(content1.data, '');
|
|
|
|
}));
|
2019-05-15 14:56:46 +08:00
|
|
|
});
|
2018-12-25 10:39:57 +08:00
|
|
|
}
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-09-12 17:01:48 +08:00
|
|
|
|
2022-12-24 10:41:34 +08:00
|
|
|
onBackClick = (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
window.history.back();
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2022-12-24 10:41:34 +08:00
|
|
|
|
2018-09-12 17:01:48 +08:00
|
|
|
render() {
|
2023-10-31 21:06:39 +08:00
|
|
|
return (
|
|
|
|
<div className="history-content flex-fill d-flex">
|
|
|
|
<div className="flex-fill d-flex flex-column">
|
|
|
|
<div className="history-header file-history-header">
|
|
|
|
<div className="title">
|
|
|
|
<a href="#" className="go-back" title="Back" onClick={this.onBackClick}>
|
|
|
|
<span className="fas fa-chevron-left"></span>
|
|
|
|
</a>
|
|
|
|
<span className="name">{fileName}</span>
|
|
|
|
</div>
|
2018-12-25 10:39:57 +08:00
|
|
|
</div>
|
2020-11-02 13:56:35 +08:00
|
|
|
<MainPanel
|
2018-12-25 10:39:57 +08:00
|
|
|
newMarkdownContent={this.state.newMarkdownContent}
|
|
|
|
oldMarkdownContent={this.state.oldMarkdownContent}
|
|
|
|
renderingContent={this.state.renderingContent}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-10-31 21:06:39 +08:00
|
|
|
<SidePanel onItemClick={this.onHistoryItemClick}/>
|
|
|
|
</div>
|
2018-09-12 17:01:48 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-29 12:21:47 +08:00
|
|
|
ReactDom.render(<FileHistory />, document.getElementById('wrapper'));
|