1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-11 20:01:10 +00:00
Files
seahub/frontend/src/pages/sdoc/sdoc-editor/index.js

95 lines
2.4 KiB
JavaScript
Raw Normal View History

import React, { Fragment } from 'react';
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';
import { Utils } from '../../../utils/utils';
export default class SdocEditor extends React.Component {
constructor(props) {
super(props);
const { isStarred, isSdocDraft } = window.app.pageOptions;
this.state = {
isStarred: isStarred,
isDraft: isSdocDraft,
direntList: []
};
}
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-01-05 11:49:34 +08:00
onNewNotification = () => {
this.onSetFavicon('_notification');
2024-01-05 11:49:34 +08:00
};
onClearNotification = () => {
this.onSetFavicon();
};
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
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 => {
let dirent = new Dirent(item);
2024-01-06 14:17:43 +08:00
direntList.push(dirent);
});
this.setState({
direntList: direntList
});
2024-01-06 14:17:43 +08:00
}).catch((err) => {
Utils.getErrorMsg(err, true);
});
};
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>
);
}
}