mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-10 19:32:25 +00:00
[sdoc file view] added 'star/unstar' (#5525)
This commit is contained in:
parent
4e100a20df
commit
94e2076447
@ -1,11 +1,16 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { EventBus, EXTERNAL_EVENT } from '@seafile/sdoc-editor';
|
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';
|
import InternalLinkDialog from '../../components/dialog/internal-link-dialog';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
repoID: PropTypes.string.isRequired,
|
repoID: PropTypes.string.isRequired,
|
||||||
docPath: PropTypes.string.isRequired,
|
docPath: PropTypes.string.isRequired,
|
||||||
|
isStarred: PropTypes.bool.isRequired,
|
||||||
|
toggleStar: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExternalOperations extends React.Component {
|
class ExternalOperations extends React.Component {
|
||||||
@ -20,16 +25,37 @@ class ExternalOperations extends React.Component {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const eventBus = EventBus.getInstance();
|
const eventBus = EventBus.getInstance();
|
||||||
this.unsubscribeInternalLinkEvent = eventBus.subscribe(EXTERNAL_EVENT.INTERNAL_LINK_CLICK, this.onInternalLinkToggle);
|
this.unsubscribeInternalLinkEvent = eventBus.subscribe(EXTERNAL_EVENT.INTERNAL_LINK_CLICK, this.onInternalLinkToggle);
|
||||||
|
this.unsubscribeStar = eventBus.subscribe(EXTERNAL_EVENT.TOGGLE_STAR, this.toggleStar);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.unsubscribeInternalLinkEvent();
|
this.unsubscribeInternalLinkEvent();
|
||||||
|
this.unsubscribeStar();
|
||||||
}
|
}
|
||||||
|
|
||||||
onInternalLinkToggle = () => {
|
onInternalLinkToggle = () => {
|
||||||
this.setState({isShowInternalLinkDialog: !this.state.isShowInternalLinkDialog});
|
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() {
|
render() {
|
||||||
const { repoID, docPath } = this.props;
|
const { repoID, docPath } = this.props;
|
||||||
const { isShowInternalLinkDialog } = this.state;
|
const { isShowInternalLinkDialog } = this.state;
|
||||||
|
@ -3,12 +3,31 @@ import { SimpleEditor } from '@seafile/sdoc-editor';
|
|||||||
import ExternalOperations from './external-operations';
|
import ExternalOperations from './external-operations';
|
||||||
|
|
||||||
export default class SdocEditor extends React.Component {
|
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() {
|
render() {
|
||||||
const { repoID, docPath } = window.seafile;
|
const { repoID, docPath } = window.seafile;
|
||||||
|
const { isStarred } = this.state;
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<SimpleEditor />
|
<SimpleEditor isStarred={isStarred} />
|
||||||
<ExternalOperations repoID={repoID} docPath={docPath} />
|
<ExternalOperations
|
||||||
|
repoID={repoID}
|
||||||
|
docPath={docPath}
|
||||||
|
isStarred={isStarred}
|
||||||
|
toggleStar={this.toggleStar}
|
||||||
|
/>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ window.seafile = {
|
|||||||
parentFolderURL: `${siteRoot}library/${repoID}/${Utils.encodePath(repoName + parentDir)}`,
|
parentFolderURL: `${siteRoot}library/${repoID}/${Utils.encodePath(repoName + parentDir)}`,
|
||||||
assetsUrl,
|
assetsUrl,
|
||||||
isShowInternalLink: true,
|
isShowInternalLink: true,
|
||||||
|
isStarIconShown: true // for star/unstar
|
||||||
};
|
};
|
||||||
|
|
||||||
ReactDom.render(
|
ReactDom.render(
|
||||||
|
Loading…
Reference in New Issue
Block a user