import React, { Component } from 'react'; import { Link } from '@reach/router'; import { Modal, ModalHeader, ModalBody } from 'reactstrap'; import { seafileAPI } from '../../utils/seafile-api'; import { Utils } from '../../utils/utils'; import { gettext, siteRoot, loginUrl, canGenerateShareLink } from '../../utils/constants'; class Content extends Component { constructor(props) { super(props); this.state = { modalOpen: false, modalContent: '' }; } // required by `Modal`, and can only set the 'open' state toggleModal = () => { this.setState({ modalOpen: !this.state.modalOpen }); } showModal = (options) => { this.toggleModal(); this.setState({ modalContent: options.content }); } render() { const {loading, errorMsg, items} = this.props.data; if (loading) { return ; } else if (errorMsg) { return

{errorMsg}

; } else { const emptyTip = (

{gettext("You don't have any upload links")}

{gettext("You can generate an upload link from any folder. Anyone who receives this link can upload files to this folder.")}

); const table = (
{/*icon*/} {gettext("Name")} {gettext("Library")} {gettext("Visits")} {/*Operations*/}
{gettext('Link')} {this.state.modalContent}
); return items.length ? table : emptyTip; } } } class TableBody extends Component { constructor(props) { super(props); this.state = { //items: this.props.items }; } render() { let listItems = this.props.items.map(function(item, index) { return ; }, this); return ( {listItems} ); } } class Item extends Component { constructor(props) { super(props); this.state = { showOpIcon: false, deleted: false }; } handleMouseOver = () => { this.setState({showOpIcon: true}); } handleMouseOut = () => { this.setState({showOpIcon: false}); } viewLink = (e) => { e.preventDefault(); this.props.showModal({content: this.props.data.link}); } removeLink = (e) => { e.preventDefault(); const data = this.props.data; seafileAPI.deleteUploadLink(data.token) .then((res) => { this.setState({ deleted: true }); // TODO: show feedback msg // gettext("Successfully deleted 1 item") }) .catch((error) => { // TODO: show feedback msg }); } render() { if (this.state.deleted) { return null; } const data = this.props.data; const icon_size = Utils.isHiDPI() ? 48 : 24; data.icon_url = Utils.getFolderIconUrl({ is_readonly: false, size: icon_size }); data.url = `${siteRoot}library/${data.repo_id}/${data.repo_name}${Utils.encodePath(data.path)}`; let iconVisibility = this.state.showOpIcon ? '' : ' invisible'; let linkIconClassName = 'sf2-icon-link op-icon' + iconVisibility; let deleteIconClassName = 'sf2-icon-delete op-icon' + iconVisibility; const item = ( {data.obj_name} {data.repo_name} {data.view_cnt} ); return item; } } class ShareAdminUploadLinks extends Component { constructor(props) { super(props); this.state = { loading: true, errorMsg: '', items: [] }; } componentDidMount() { seafileAPI.listUploadLinks().then((res) => { // res: {data: Array(2), status: 200, statusText: "OK", headers: {…}, config: {…}, …} this.setState({ loading: false, items: res.data }); }).catch((error) => { if (error.response) { if (error.response.status == 403) { this.setState({ loading: false, errorMsg: gettext("Permission denied") }); location.href = `${loginUrl}?next=${encodeURIComponent(location.href)}`; } else { this.setState({ loading: false, errorMsg: gettext("Error") }); } } else { this.setState({ loading: false, errorMsg: gettext("Please check the network.") }); } }); } render() { return (
    { canGenerateShareLink ?
  • {gettext('Share Links')}
  • : '' }
  • {gettext('Upload Links')}
); } } export default ShareAdminUploadLinks;