2018-12-11 08:42:30 +08:00
|
|
|
import React, { Component, Fragment } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import moment from 'moment';
|
2019-05-30 16:18:06 +08:00
|
|
|
import { siteRoot } from '../../utils/constants';
|
|
|
|
// import { seafileAPI } from '../../utils/seafile-api';
|
|
|
|
// import Toast from '../toast';
|
2018-12-11 08:42:30 +08:00
|
|
|
import ModalPortal from '../modal-portal';
|
|
|
|
import WikiDeleteDialog from '../dialog/wiki-delete-dialog';
|
2019-05-30 16:18:06 +08:00
|
|
|
// import Rename from '../rename';
|
2018-12-11 08:42:30 +08:00
|
|
|
|
2019-05-27 18:35:34 +08:00
|
|
|
import { Utils } from '../../utils/utils';
|
|
|
|
|
2018-12-11 11:20:40 +08:00
|
|
|
const propTypes = {
|
2018-12-11 08:42:30 +08:00
|
|
|
wiki: PropTypes.object.isRequired,
|
2019-05-30 16:18:06 +08:00
|
|
|
// renameWiki: PropTypes.func.isRequired,
|
2018-12-11 08:42:30 +08:00
|
|
|
deleteWiki: PropTypes.func.isRequired,
|
2018-12-11 11:20:40 +08:00
|
|
|
isItemFreezed: PropTypes.bool.isRequired,
|
|
|
|
onFreezedItem: PropTypes.func.isRequired,
|
|
|
|
onUnfreezedItem: PropTypes.func.isRequired,
|
2018-12-11 08:42:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class WikiListItem extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
isShowDeleteDialog: false,
|
2019-05-30 16:18:06 +08:00
|
|
|
// isRenameing: false,
|
2018-12-11 13:22:52 +08:00
|
|
|
highlight: false,
|
2019-05-30 16:18:06 +08:00
|
|
|
// permission: this.props.wiki.permission,
|
2018-12-11 08:42:30 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-05-30 16:18:06 +08:00
|
|
|
// clickMenuToggle = (e) => {
|
|
|
|
// e.preventDefault();
|
|
|
|
// this.onMenuToggle(e);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// onMenuToggle = (e) => {
|
|
|
|
// let targetType = e.target.dataset.toggle;
|
|
|
|
// if (targetType !== 'item') {
|
|
|
|
// if (this.props.isItemFreezed) {
|
|
|
|
// this.setState({
|
|
|
|
// highlight: false,
|
|
|
|
// isShowMenuControl: false,
|
|
|
|
// isShowWikiMenu: !this.state.isShowWikiMenu
|
|
|
|
// });
|
|
|
|
// this.props.onUnfreezedItem();
|
|
|
|
// } else {
|
|
|
|
// this.setState({
|
|
|
|
// isShowWikiMenu: !this.state.isShowWikiMenu
|
|
|
|
// });
|
|
|
|
// this.props.onFreezedItem();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2018-12-11 08:42:30 +08:00
|
|
|
|
|
|
|
onMouseEnter = () => {
|
2018-12-11 11:20:40 +08:00
|
|
|
if (!this.props.isItemFreezed) {
|
2019-05-30 16:18:06 +08:00
|
|
|
this.setState({ highlight: true });
|
2018-12-11 08:42:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onMouseLeave = () => {
|
2018-12-11 11:20:40 +08:00
|
|
|
if (!this.props.isItemFreezed) {
|
2019-05-30 16:18:06 +08:00
|
|
|
this.setState({ highlight: false });
|
2018-12-11 08:42:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-30 16:18:06 +08:00
|
|
|
// changePerm = (permission) => {
|
|
|
|
// let wiki = this.props.wiki;
|
|
|
|
// seafileAPI.updateWikiPermission(wiki.slug, permission).then(() => {
|
|
|
|
// this.setState({permission: permission});
|
|
|
|
// }).catch((error) => {
|
|
|
|
// if(error.response) {
|
|
|
|
// let errorMsg = error.response.data.error_msg;
|
|
|
|
// Toast.danger(errorMsg);
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
|
|
|
// onRenameToggle = (e) => {
|
|
|
|
// this.props.onFreezedItem();
|
|
|
|
// this.setState({
|
|
|
|
// isShowWikiMenu: false,
|
|
|
|
// isShowMenuControl: false,
|
|
|
|
// isRenameing: true,
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
|
|
|
// onRenameConfirm = (newName) => {
|
|
|
|
// this.renameWiki(newName);
|
|
|
|
// this.onRenameCancel();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// onRenameCancel = () => {
|
|
|
|
// this.props.onUnfreezedItem();
|
|
|
|
// this.setState({isRenameing: false});
|
|
|
|
// }
|
2018-12-11 13:22:52 +08:00
|
|
|
|
2018-12-11 08:42:30 +08:00
|
|
|
onDeleteToggle = () => {
|
2018-12-11 13:28:41 +08:00
|
|
|
this.props.onUnfreezedItem();
|
2018-12-11 08:42:30 +08:00
|
|
|
this.setState({
|
|
|
|
isShowDeleteDialog: !this.state.isShowDeleteDialog,
|
|
|
|
});
|
|
|
|
}
|
2018-12-11 13:22:52 +08:00
|
|
|
|
|
|
|
onDeleteCancel = () => {
|
2018-12-11 13:28:41 +08:00
|
|
|
this.props.onUnfreezedItem();
|
2018-12-11 13:22:52 +08:00
|
|
|
this.setState({
|
|
|
|
isShowDeleteDialog: !this.state.isShowDeleteDialog,
|
|
|
|
});
|
|
|
|
}
|
2018-12-11 08:42:30 +08:00
|
|
|
|
2019-05-30 16:18:06 +08:00
|
|
|
// renameWiki = (newName) => {
|
|
|
|
// let wiki = this.props.wiki;
|
|
|
|
// this.props.renameWiki(wiki, newName);
|
|
|
|
// }
|
2018-12-11 08:42:30 +08:00
|
|
|
|
|
|
|
deleteWiki = () => {
|
|
|
|
let wiki = this.props.wiki;
|
|
|
|
this.props.deleteWiki(wiki);
|
|
|
|
this.setState({
|
|
|
|
isShowDeleteDialog: !this.state.isShowDeleteDialog,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let wiki = this.props.wiki;
|
|
|
|
let userProfileURL = `${siteRoot}profile/${encodeURIComponent(wiki.owner)}/`;
|
2019-05-27 18:35:34 +08:00
|
|
|
let fileIconUrl = Utils.getDefaultLibIconUrl(false);
|
2019-05-30 16:18:06 +08:00
|
|
|
let deleteIcon = `action-icon sf2-icon-x3 ${this.state.highlight ? '' : 'invisible'}`;
|
2018-12-11 08:42:30 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2018-12-11 13:22:52 +08:00
|
|
|
<tr className={this.state.highlight ? 'tr-highlight' : ''} onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}>
|
2019-05-27 18:35:34 +08:00
|
|
|
<td><img src={fileIconUrl} width="24" alt="" /></td>
|
2018-12-11 11:20:40 +08:00
|
|
|
<td className="name">
|
2019-05-30 16:18:06 +08:00
|
|
|
<a href={wiki.link}>{wiki.name}</a>
|
|
|
|
{/*this.state.isRenameing ?
|
2019-01-30 17:37:13 +08:00
|
|
|
<Rename wiki={wiki} name={wiki.name} onRenameConfirm={this.onRenameConfirm} onRenameCancel={this.onRenameCancel}/> :
|
2019-01-28 16:32:32 +08:00
|
|
|
<a href={wiki.link}>{wiki.name}</a>
|
2019-05-30 16:18:06 +08:00
|
|
|
*/}
|
2018-12-11 08:42:30 +08:00
|
|
|
</td>
|
2019-01-28 16:32:32 +08:00
|
|
|
<td><a href={userProfileURL} target='_blank'>{wiki.owner_nickname}</a></td>
|
2018-12-11 08:42:30 +08:00
|
|
|
<td>{moment(wiki.updated_at).fromNow()}</td>
|
2018-12-28 11:12:24 +08:00
|
|
|
<td className="text-center cursor-pointer">
|
2019-05-30 16:18:06 +08:00
|
|
|
<span className={deleteIcon} onClick={this.onDeleteToggle}></span>
|
2018-12-11 08:42:30 +08:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
{this.state.isShowDeleteDialog &&
|
|
|
|
<ModalPortal>
|
|
|
|
<WikiDeleteDialog
|
2018-12-11 13:22:52 +08:00
|
|
|
toggleCancel={this.onDeleteCancel}
|
2018-12-11 08:42:30 +08:00
|
|
|
handleSubmit={this.deleteWiki}
|
|
|
|
/>
|
|
|
|
</ModalPortal>
|
|
|
|
}
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-11 11:20:40 +08:00
|
|
|
WikiListItem.propTypes = propTypes;
|
2018-12-11 08:42:30 +08:00
|
|
|
|
2019-04-17 10:34:43 +08:00
|
|
|
export default WikiListItem;
|