1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-04 16:31:13 +00:00

[file view] code improvement (#3180)

* added component 'file-view.js'
This commit is contained in:
llj
2019-03-26 20:04:18 +08:00
committed by Daniel Pan
parent d01553a58f
commit d6470889c9
11 changed files with 155 additions and 909 deletions

View File

@@ -0,0 +1,108 @@
import React from 'react';
import PropTypes from 'prop-types';
import watermark from 'watermark-dom';
import { seafileAPI } from '../../utils/seafile-api';
import { siteName } from '../../utils/constants';
import FileInfo from './file-info';
import FileToolbar from './file-toolbar';
import CommentPanel from './comment-panel';
import '../../css/file-view.css';
const propTypes = {
content: PropTypes.object.isRequired
};
const { isStarred, isLocked, lockedByMe,
repoID, filePath, enableWatermark, userNickName
} = window.app.pageOptions;
class FileView extends React.Component {
constructor(props) {
super(props);
this.state = {
isStarred: isStarred,
isLocked: isLocked,
lockedByMe: lockedByMe,
isCommentPanelOpen: false
};
}
toggleCommentPanel = () => {
this.setState({
isCommentPanelOpen: !this.state.isCommentPanelOpen
});
}
toggleStar = () => {
if (this.state.isStarred) {
seafileAPI.unStarItem(repoID, filePath).then((res) => {
this.setState({
isStarred: false
});
});
} else {
seafileAPI.starItem(repoID, filePath).then((res) => {
this.setState({
isStarred: true
});
});
}
}
toggleLockFile = () => {
if (this.state.isLocked) {
seafileAPI.unlockfile(repoID, filePath).then((res) => {
this.setState({
isLocked: false,
lockedByMe: false
});
});
} else {
seafileAPI.lockfile(repoID, filePath).then((res) => {
this.setState({
isLocked: true,
lockedByMe: true
});
});
}
}
render() {
return (
<div className="h-100 d-flex flex-column">
<div className="file-view-header d-flex justify-content-between">
<FileInfo
isStarred={this.state.isStarred}
isLocked={this.state.isLocked}
toggleStar={this.toggleStar}
/>
<FileToolbar
isLocked={this.state.isLocked}
lockedByMe={this.state.lockedByMe}
toggleLockFile={this.toggleLockFile}
toggleCommentPanel={this.toggleCommentPanel}
/>
</div>
<div className="file-view-body flex-auto d-flex">
{this.props.content}
{this.state.isCommentPanelOpen &&
<CommentPanel toggleCommentPanel={this.toggleCommentPanel} />
}
</div>
</div>
);
}
}
if (enableWatermark) {
watermark.init({
watermark_txt: `${siteName} ${userNickName}`,
watermark_alpha: 0.075
});
}
FileView.propTypes = propTypes;
export default FileView;