mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 07:01:12 +00:00
Revert "Update txt file save mechanism"
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import PropTypes from 'prop-types';
|
||||
import toaster from './components/toast';
|
||||
import { Utils } from './utils/utils';
|
||||
import { gettext } from './utils/constants';
|
||||
import FileView from './components/file-view/file-view';
|
||||
import FileViewTip from './components/file-view/file-view-tip';
|
||||
import { seafileAPI } from './utils/seafile-api';
|
||||
|
||||
import CodeMirror from 'react-codemirror';
|
||||
import 'codemirror/mode/javascript/javascript';
|
||||
@@ -24,7 +20,7 @@ import 'codemirror/lib/codemirror.css';
|
||||
import './css/text-file-view.css';
|
||||
|
||||
const {
|
||||
err, fileExt, fileContent, repoID, filePath, fileName
|
||||
err, fileExt, fileContent
|
||||
} = window.app.pageOptions;
|
||||
|
||||
const options = {
|
||||
@@ -34,76 +30,18 @@ const options = {
|
||||
theme: 'default',
|
||||
textWrapping: true,
|
||||
lineWrapping: true,
|
||||
readOnly: false, // set false to let user edit directly
|
||||
readOnly: true,
|
||||
cursorBlinkRate: -1 // hide the cursor
|
||||
};
|
||||
|
||||
class ViewFileText extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
content: fileContent,
|
||||
isContentChangedButNotSaved: false,
|
||||
isSaving: false,
|
||||
};
|
||||
this.onSaveChangedContent=this.onSaveChangedContent.bind(this);
|
||||
}
|
||||
|
||||
|
||||
updateContent = (newContent) => {
|
||||
this.setState({
|
||||
isContentChangedButNotSaved: true,
|
||||
content: newContent,
|
||||
});
|
||||
}
|
||||
|
||||
onSaveChangedContent () {
|
||||
let dirPath = '/';
|
||||
return (
|
||||
seafileAPI.getUpdateLink(repoID, dirPath).then((res) => {
|
||||
const uploadLink = res.data;
|
||||
this.setState({
|
||||
isSaving: true
|
||||
});
|
||||
return seafileAPI.updateFile(
|
||||
uploadLink,
|
||||
filePath,
|
||||
fileName,
|
||||
this.state.content
|
||||
).then(() => {
|
||||
toaster.success(gettext('Successfully saved'), {
|
||||
duration: 3
|
||||
});
|
||||
this.setState({
|
||||
isSaving: false,
|
||||
isContentChangedButNotSaved: false
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<FileView
|
||||
content={
|
||||
<FileContent
|
||||
content={this.state.content}
|
||||
updateContent={this.updateContent}
|
||||
/>
|
||||
}
|
||||
isSaving={this.state.isSaving}
|
||||
isContentChangedButNotSaved={this.state.isContentChangedButNotSaved}
|
||||
onSaveChangedContent={this.onSaveChangedContent}
|
||||
/>
|
||||
<FileView content={<FileContent />} />
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const propTypes = {
|
||||
updateContent: PropTypes.func.isRequired,
|
||||
content: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
class FileContent extends React.Component {
|
||||
render() {
|
||||
if (err) {
|
||||
@@ -113,17 +51,14 @@ class FileContent extends React.Component {
|
||||
<div className="file-view-content flex-1 text-file-view">
|
||||
<CodeMirror
|
||||
ref="code-mirror-editor"
|
||||
value={this.props.content}
|
||||
value={fileContent}
|
||||
options={options}
|
||||
onChange={this.props.updateContent}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
FileContent.propTypes = propTypes;
|
||||
|
||||
ReactDOM.render (
|
||||
<ViewFileText />,
|
||||
document.getElementById('wrapper')
|
||||
|
Reference in New Issue
Block a user