1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-01 15:23:05 +00:00

[sdoc file view] added 'star/unstar' (#5525)

This commit is contained in:
llj 2023-06-30 21:51:27 +08:00 committed by GitHub
parent 4e100a20df
commit 94e2076447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 2 deletions

View File

@ -1,11 +1,16 @@
import React from 'react';
import PropTypes from 'prop-types';
import { EventBus, EXTERNAL_EVENT } from '@seafile/sdoc-editor';
import { seafileAPI } from '../../utils/seafile-api';
import { Utils } from '../../utils/utils';
import toaster from '../../components/toast';
import InternalLinkDialog from '../../components/dialog/internal-link-dialog';
const propTypes = {
repoID: PropTypes.string.isRequired,
docPath: PropTypes.string.isRequired,
isStarred: PropTypes.bool.isRequired,
toggleStar: PropTypes.func.isRequired
};
class ExternalOperations extends React.Component {
@ -20,16 +25,37 @@ class ExternalOperations extends React.Component {
componentDidMount() {
const eventBus = EventBus.getInstance();
this.unsubscribeInternalLinkEvent = eventBus.subscribe(EXTERNAL_EVENT.INTERNAL_LINK_CLICK, this.onInternalLinkToggle);
this.unsubscribeStar = eventBus.subscribe(EXTERNAL_EVENT.TOGGLE_STAR, this.toggleStar);
}
componentWillUnmount() {
this.unsubscribeInternalLinkEvent();
this.unsubscribeStar();
}
onInternalLinkToggle = () => {
this.setState({isShowInternalLinkDialog: !this.state.isShowInternalLinkDialog});
}
toggleStar = () => {
const { isStarred, repoID, docPath } = this.props;
if (isStarred) {
seafileAPI.unstarItem(repoID, docPath).then((res) => {
this.props.toggleStar(false);
}).catch((error) => {
const errorMsg = Utils.getErrorMsg(error);
toaster.danger(errorMsg);
});
} else {
seafileAPI.starItem(repoID, docPath).then((res) => {
this.props.toggleStar(true);
}).catch((error) => {
const errorMsg = Utils.getErrorMsg(error);
toaster.danger(errorMsg);
});
}
}
render() {
const { repoID, docPath } = this.props;
const { isShowInternalLinkDialog } = this.state;

View File

@ -3,12 +3,31 @@ import { SimpleEditor } from '@seafile/sdoc-editor';
import ExternalOperations from './external-operations';
export default class SdocEditor extends React.Component {
constructor(props) {
super(props);
const { isStarred } = window.app.pageOptions;
this.state = {
isStarred: isStarred
};
}
toggleStar = (isStarred) => {
this.setState({isStarred: isStarred});
}
render() {
const { repoID, docPath } = window.seafile;
const { isStarred } = this.state;
return (
<Fragment>
<SimpleEditor />
<ExternalOperations repoID={repoID} docPath={docPath} />
<SimpleEditor isStarred={isStarred} />
<ExternalOperations
repoID={repoID}
docPath={docPath}
isStarred={isStarred}
toggleStar={this.toggleStar}
/>
</Fragment>
);
}

View File

@ -31,6 +31,7 @@ window.seafile = {
parentFolderURL: `${siteRoot}library/${repoID}/${Utils.encodePath(repoName + parentDir)}`,
assetsUrl,
isShowInternalLink: true,
isStarIconShown: true // for star/unstar
};
ReactDom.render(