1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-05 17:14:28 +00:00
seahub/frontend/src/components/file-view/file-view.js

136 lines
3.6 KiB
JavaScript
Raw Normal View History

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 { Utils } from '../../utils/utils';
import toaster from '../toast';
import FileInfo from './file-info';
import FileToolbar from './file-toolbar';
import CommentPanel from './comment-panel';
import '../../css/file-view.css';
const propTypes = {
2019-04-22 03:31:39 +00:00
onSave: PropTypes.func,
2019-04-19 03:57:07 +00:00
content: PropTypes.object.isRequired,
2019-04-19 13:32:54 +00:00
isSaving: PropTypes.bool,
2019-04-22 03:31:39 +00:00
needSave: PropTypes.bool,
participants: PropTypes.array,
onParticipantsChange: PropTypes.func,
};
const { isStarred, isLocked, lockedByMe,
repoID, filePath, enableWatermark, userNickName
} = window.app.pageOptions;
2019-04-19 14:32:19 +00:00
class FileView extends React.Component {
constructor(props) {
super(props);
this.state = {
isStarred: isStarred,
isLocked: isLocked,
lockedByMe: lockedByMe,
2019-04-19 14:32:19 +00:00
isCommentPanelOpen: false,
};
}
toggleCommentPanel = () => {
this.setState({
isCommentPanelOpen: !this.state.isCommentPanelOpen
});
}
toggleStar = () => {
if (this.state.isStarred) {
2019-03-27 03:28:00 +00:00
seafileAPI.unstarItem(repoID, filePath).then((res) => {
this.setState({
isStarred: false
});
}).catch((error) => {
const errorMsg = Utils.getErrorMsg(error);
toaster.danger(errorMsg);
});
} else {
seafileAPI.starItem(repoID, filePath).then((res) => {
this.setState({
isStarred: true
});
}).catch((error) => {
const errorMsg = Utils.getErrorMsg(error);
toaster.danger(errorMsg);
});
}
}
toggleLockFile = () => {
if (this.state.isLocked) {
seafileAPI.unlockfile(repoID, filePath).then((res) => {
this.setState({
isLocked: false,
lockedByMe: false
});
}).catch((error) => {
const errorMsg = Utils.getErrorMsg(error);
toaster.danger(errorMsg);
});
} else {
seafileAPI.lockfile(repoID, filePath).then((res) => {
this.setState({
isLocked: true,
lockedByMe: true
});
}).catch((error) => {
const errorMsg = Utils.getErrorMsg(error);
toaster.danger(errorMsg);
});
}
}
render() {
return (
<div className="h-100 d-flex flex-column">
2019-04-19 14:40:47 +00:00
<div className="file-view-header d-flex justify-content-between align-items-center">
<FileInfo
isStarred={this.state.isStarred}
isLocked={this.state.isLocked}
toggleStar={this.toggleStar}
/>
<FileToolbar
isLocked={this.state.isLocked}
lockedByMe={this.state.lockedByMe}
2019-04-22 03:31:39 +00:00
onSave={this.props.onSave}
2019-04-19 14:32:19 +00:00
isSaving={this.props.isSaving}
2019-04-22 03:31:39 +00:00
needSave={this.props.needSave}
toggleLockFile={this.toggleLockFile}
toggleCommentPanel={this.toggleCommentPanel}
/>
</div>
<div className="file-view-body flex-auto d-flex o-hidden">
{this.props.content}
{this.state.isCommentPanelOpen &&
<CommentPanel
toggleCommentPanel={this.toggleCommentPanel}
participants={this.props.participants}
onParticipantsChange={this.props.onParticipantsChange}
/>
}
</div>
</div>
);
}
}
if (enableWatermark) {
watermark.init({
watermark_txt: `${siteName} ${userNickName}`,
watermark_alpha: 0.075
});
}
FileView.propTypes = propTypes;
export default FileView;