1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-20 01:49:50 +00:00
seahub/frontend/src/file-history.js

99 lines
3.0 KiB
JavaScript
Raw Normal View History

2018-12-25 02:39:57 +00:00
import React, { Fragment } from 'react';
2018-09-12 09:01:48 +00:00
import ReactDOM from 'react-dom';
2018-12-25 02:39:57 +00:00
import axios from 'axios';
2019-03-04 14:34:29 +00:00
import { siteRoot, filePath, fileName, historyRepoID } from './utils/constants';
2018-12-25 02:39:57 +00:00
import { Utils } from './utils/utils';
import CommonToolbar from './components/toolbar/common-toolbar';
2018-09-12 09:01:48 +00:00
import SidePanel from './pages/file-history/side-panel';
import MainPanel from './pages/file-history/main-panel';
2019-03-04 14:34:29 +00:00
import { seafileAPI } from './utils/seafile-api';
2018-12-25 02:39:57 +00:00
2018-09-12 09:01:48 +00:00
import './assets/css/fa-solid.css';
import './assets/css/fa-regular.css';
import './assets/css/fontawesome.css';
import './css/layout.css';
import './css/file-history.css';
2018-09-19 01:57:17 +00:00
import './css/toolbar.css';
import './css/search.css';
2018-09-12 09:01:48 +00:00
class FileHistory extends React.Component {
constructor(props) {
super(props);
this.state = {
renderingContent: true,
2018-12-25 02:39:57 +00:00
newMarkdownContent: '',
oldMarkdownContent: ''
2018-09-12 09:01:48 +00:00
};
}
2019-04-26 03:34:11 +00:00
onSearchedClick = (searchedItem) => {
Utils.handleSearchedItemClick(searchedItem);
2018-12-25 02:39:57 +00:00
}
2018-09-26 09:27:14 +00:00
setDiffContent = (newMarkdownContent, oldMarkdownContent)=> {
2018-09-26 09:27:14 +00:00
this.setState({
renderingContent: false,
newMarkdownContent: newMarkdownContent,
2018-12-25 02:39:57 +00:00
oldMarkdownContent: oldMarkdownContent,
2018-09-12 09:01:48 +00:00
});
}
2018-09-26 09:27:14 +00:00
2018-12-25 02:39:57 +00:00
onHistoryItemClick = (item, preItem)=> {
2018-09-12 09:01:48 +00:00
this.setState({renderingContent: true});
2018-12-25 02:39:57 +00:00
if (preItem) {
axios.all([
2019-03-04 14:34:29 +00: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);
2018-12-25 02:39:57 +00:00
}));
2019-03-04 14:34:29 +00:00
}));
2018-12-25 02:39:57 +00:00
} else {
2019-03-04 14:34:29 +00: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, '');
}));
})
2018-12-25 02:39:57 +00:00
}
2018-09-12 09:01:48 +00:00
}
render() {
return(
2018-12-25 02:39:57 +00:00
<Fragment>
<div id="header" className="history-header">
<div className="title">
<a href="javascript:window.history.back()" className="go-back" title="Back">
<span className="fas fa-chevron-left"></span>
</a>
<span className="name">{fileName}</span>
</div>
<div className='toolbar'>
<CommonToolbar onSearchedClick={this.onSearchedClick} />
</div>
</div>
<div id="main" className="history-content">
<MainPanel
newMarkdownContent={this.state.newMarkdownContent}
oldMarkdownContent={this.state.oldMarkdownContent}
renderingContent={this.state.renderingContent}
/>
2019-02-15 03:42:57 +00:00
<SidePanel onItemClick={this.onHistoryItemClick}/>
2018-12-25 02:39:57 +00:00
</div>
</Fragment>
2018-09-12 09:01:48 +00:00
);
}
}
ReactDOM.render (
<FileHistory />,
document.getElementById('wrapper')
);