2024-09-02 12:55:10 +08:00
|
|
|
import React, { Fragment } from 'react';
|
2023-05-12 14:12:28 +08:00
|
|
|
import { SimpleEditor } from '@seafile/sdoc-editor';
|
|
|
|
import ExternalOperations from './external-operations';
|
2024-01-06 14:17:43 +08:00
|
|
|
import { seafileAPI } from '../../../utils/seafile-api';
|
|
|
|
import Dirent from '../../../models/dirent';
|
2023-11-22 11:29:01 +08:00
|
|
|
import { Utils } from '../../../utils/utils';
|
2023-05-12 14:12:28 +08:00
|
|
|
|
2024-09-02 12:55:10 +08:00
|
|
|
export default class SdocEditor extends React.Component {
|
2023-06-30 21:51:27 +08:00
|
|
|
|
2024-09-02 12:55:10 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
const { isStarred, isSdocDraft } = window.app.pageOptions;
|
|
|
|
this.state = {
|
|
|
|
isStarred: isStarred,
|
|
|
|
isDraft: isSdocDraft,
|
|
|
|
direntList: []
|
|
|
|
};
|
|
|
|
}
|
2023-06-30 21:51:27 +08:00
|
|
|
|
2024-09-02 12:55:10 +08:00
|
|
|
componentDidMount() {
|
|
|
|
this.onSetFavicon();
|
|
|
|
this.getDirentList();
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleStar = (isStarred) => {
|
|
|
|
this.setState({ isStarred: isStarred });
|
|
|
|
};
|
|
|
|
|
|
|
|
onSetFavicon = (suffix) => {
|
2024-01-05 11:49:34 +08:00
|
|
|
let { docName } = window.seafile;
|
|
|
|
if (suffix) {
|
|
|
|
docName = docName + suffix;
|
|
|
|
}
|
2024-08-05 21:04:31 +08:00
|
|
|
const fileIcon = Utils.getFileIconUrl(docName);
|
2024-01-05 11:49:34 +08:00
|
|
|
document.getElementById('favicon').href = fileIcon;
|
2024-09-02 12:55:10 +08:00
|
|
|
};
|
2024-01-05 11:49:34 +08:00
|
|
|
|
2024-09-02 12:55:10 +08:00
|
|
|
onNewNotification = () => {
|
|
|
|
this.onSetFavicon('_notification');
|
2024-01-05 11:49:34 +08:00
|
|
|
};
|
|
|
|
|
2024-09-02 12:55:10 +08:00
|
|
|
onClearNotification = () => {
|
|
|
|
this.onSetFavicon();
|
|
|
|
};
|
2024-03-01 15:22:47 +08:00
|
|
|
|
2024-09-02 12:55:10 +08:00
|
|
|
getDirPath = () => {
|
|
|
|
const { docPath } = window.seafile;
|
|
|
|
const index = docPath.lastIndexOf('/');
|
|
|
|
if (index) {
|
|
|
|
return docPath.slice(0, index);
|
|
|
|
}
|
|
|
|
return '/';
|
|
|
|
};
|
2024-01-06 14:17:43 +08:00
|
|
|
|
2024-09-02 12:55:10 +08:00
|
|
|
getDirentList = () => {
|
|
|
|
const { repoID } = window.seafile;
|
|
|
|
const path = this.getDirPath();
|
|
|
|
seafileAPI.listDir(repoID, path, { 'with_thumbnail': true }).then(res => {
|
2024-01-06 14:17:43 +08:00
|
|
|
let direntList = [];
|
|
|
|
res.data.dirent_list.forEach(item => {
|
2024-09-02 12:55:10 +08:00
|
|
|
let dirent = new Dirent(item);
|
2024-01-06 14:17:43 +08:00
|
|
|
direntList.push(dirent);
|
|
|
|
});
|
2024-09-02 12:55:10 +08:00
|
|
|
this.setState({
|
|
|
|
direntList: direntList
|
|
|
|
});
|
2024-01-06 14:17:43 +08:00
|
|
|
}).catch((err) => {
|
|
|
|
Utils.getErrorMsg(err, true);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-09-02 12:55:10 +08:00
|
|
|
render() {
|
|
|
|
const { repoID, docPath, docName, docPerm } = window.seafile;
|
|
|
|
const { isStarred, isDraft, direntList } = this.state;
|
|
|
|
const dirPath = this.getDirPath();
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<SimpleEditor isStarred={isStarred} isDraft={isDraft} />
|
|
|
|
<ExternalOperations
|
|
|
|
repoID={repoID}
|
|
|
|
docPath={docPath}
|
|
|
|
docName={docName}
|
|
|
|
docPerm={docPerm}
|
|
|
|
isStarred={isStarred}
|
|
|
|
direntList={direntList}
|
|
|
|
dirPath={dirPath}
|
|
|
|
toggleStar={this.toggleStar}
|
|
|
|
onNewNotification={this.onNewNotification}
|
|
|
|
onClearNotification={this.onClearNotification}
|
|
|
|
/>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|