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
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-07-18 11:58:42 +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
|
|
|
|
2024-07-18 11:58:42 +08:00
|
|
|
onHistoryItemClick = (item, preItem) => {
|
|
|
|
this.setState({ renderingContent: true });
|
2023-12-08 12:07:52 +08:00
|
|
|
seafileAPI.getFileRevision(historyRepoID, item.commit_id, item.path).then((res) => {
|
2018-12-25 10:39:57 +08:00
|
|
|
axios.all([
|
2023-12-08 12:07:52 +08:00
|
|
|
seafileAPI.getFileContent(res.data),
|
|
|
|
]).then(axios.spread((content1) => {
|
|
|
|
this.setDiffContent(content1.data, '');
|
2018-12-25 10:39:57 +08:00
|
|
|
}));
|
2023-12-08 12:07:52 +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 (
|
2023-11-20 15:25:29 +08:00
|
|
|
<div className="history-content flex-fill d-flex h-100">
|
2024-03-07 15:37:09 +08:00
|
|
|
<div className="flex-fill d-flex flex-column text-truncate">
|
2023-11-20 15:25:29 +08:00
|
|
|
<div className="history-header file-history-header flex-shrink-0">
|
2024-03-07 15:37:09 +08:00
|
|
|
<div className="title d-flex mw-100">
|
2023-10-31 21:06:39 +08:00
|
|
|
<a href="#" className="go-back" title="Back" onClick={this.onBackClick}>
|
2024-06-28 08:39:44 +08:00
|
|
|
<span className="sf3-font sf3-font-down rotate-90 d-inline-block"></span>
|
2023-10-31 21:06:39 +08:00
|
|
|
</a>
|
2024-03-07 15:37:09 +08:00
|
|
|
<span className="name text-truncate" title={fileName}>{fileName}</span>
|
2023-10-31 21:06:39 +08:00
|
|
|
</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'));
|