1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-26 07:22:34 +00:00
Files
seahub/frontend/src/file-history.js

73 lines
2.2 KiB
JavaScript
Raw Normal View History

import React from 'react';
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,
newMarkdownContent: newMarkdownContent,
2018-12-25 10:39:57 +08:00
oldMarkdownContent: oldMarkdownContent,
2018-09-12 17:01:48 +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
});
};
2018-09-12 17:01:48 +08:00
onBackClick = (event) => {
event.preventDefault();
window.history.back();
};
2018-09-12 17:01:48 +08:00
render() {
return (
<div className="history-content flex-fill d-flex h-100">
<div className="flex-fill d-flex flex-column text-truncate">
<div className="history-header file-history-header flex-shrink-0">
<div className="title d-flex mw-100">
<a href="#" className="go-back" title="Back" onClick={this.onBackClick}>
<span className="sf3-font sf3-font-down rotate-90 d-inline-block"></span>
</a>
<span className="name text-truncate" title={fileName}>{fileName}</span>
</div>
2018-12-25 10:39:57 +08:00
</div>
<MainPanel
2018-12-25 10:39:57 +08:00
newMarkdownContent={this.state.newMarkdownContent}
oldMarkdownContent={this.state.oldMarkdownContent}
renderingContent={this.state.renderingContent}
/>
</div>
<SidePanel onItemClick={this.onHistoryItemClick}/>
</div>
2018-09-12 17:01:48 +08:00
);
}
}
ReactDom.render(<FileHistory />, document.getElementById('wrapper'));