1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-21 10:30:03 +00:00
seahub/frontend/src/components/dir-view-mode/dir-column-file.js

93 lines
2.6 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import { SeafileMetadata } from '../../metadata';
import { Utils } from '../../utils/utils';
import { gettext, siteRoot, lang, mediaUrl } from '../../utils/constants';
import SeafileMarkdownViewer from '../seafile-markdown-viewer';
import './dir-column-file.css';
const propTypes = {
path: PropTypes.string.isRequired,
repoID: PropTypes.string.isRequired,
hash: PropTypes.string,
isFileLoading: PropTypes.bool.isRequired,
isFileLoadedErr: PropTypes.bool.isRequired,
2019-04-19 07:50:27 +00:00
filePermission: PropTypes.string,
content: PropTypes.string,
lastModified: PropTypes.string,
latestContributor: PropTypes.string,
onLinkClick: PropTypes.func.isRequired,
currentRepoInfo: PropTypes.object,
};
class DirColumnFile extends React.Component {
componentDidMount() {
if (this.props.hash) {
let hash = this.props.hash;
setTimeout(function() {
window.location.hash = hash;
}, 500);
}
}
onEditClick = (e) => {
e.preventDefault();
let { path, repoID } = this.props;
let url = siteRoot + 'lib/' + repoID + '/file' + Utils.encodePath(path) + '?mode=edit';
window.open(url);
};
2019-02-27 09:34:39 +00:00
onOpenFile = (e) => {
e.preventDefault();
let { path, repoID } = this.props;
let newUrl = siteRoot + 'lib/' + repoID + '/file' + Utils.encodePath(path);
window.open(newUrl, '_blank');
};
2019-02-27 09:34:39 +00:00
render() {
if (this.props.isFileLoadedErr) {
return (
<div className="message err-tip">{gettext('File does not exist.')}</div>
);
}
if (this.props.content === '__sf-metadata') {
window.sfMetadata = {
siteRoot,
lang,
mediaUrl,
};
return (
<div className="dir-column-file w-100 h-100 o-hidden d-flex">
<div className="dir-column-file-top"></div>
<SeafileMetadata repoID={this.props.repoID} currentRepoInfo={this.props.currentRepoInfo} />
</div>
);
}
return (
<SeafileMarkdownViewer
isTOCShow={false}
isFileLoading={this.props.isFileLoading}
markdownContent={this.props.content}
lastModified = {this.props.lastModified}
latestContributor={this.props.latestContributor}
onLinkClick={this.props.onLinkClick}
2019-04-08 05:32:46 +00:00
repoID={this.props.repoID}
path={this.props.path}
>
<span className='wiki-open-file position-fixed' onClick={this.onOpenFile}>
<i className="sf3-font sf3-font-expand-arrows-alt"></i>
</span>
</SeafileMarkdownViewer>
);
}
}
DirColumnFile.propTypes = propTypes;
export default DirColumnFile;