import React, { Component } from 'react'; import { seafileAPI } from '../../utils/seafile-api'; import { Utils } from '../../utils/utils'; import { gettext, siteRoot, loginUrl, isPro } from '../../utils/constants'; class Content extends Component { render() { const {loading, errorMsg, items} = this.props.data; if (loading) { return ; } else if (errorMsg) { return

{errorMsg}

; } else { const emptyTip = (

{gettext('You have not shared any libraries')}

{gettext("You can share libraries with your friends and colleagues by clicking the share icon of your own libraries in your home page or creating a new library in groups you are in.")}

); const table = (
{/*icon*/} {gettext("Name")} {/* TODO: sort by name */} {gettext("Share To")} {gettext("Permission")}
); return items.length ? table : emptyTip; } } } class TableBody extends Component { constructor(props) { super(props); this.state = { items: this.props.items }; } componentDidMount() { document.addEventListener('click', this.clickDocument); } clickDocument(e) { // TODO: click 'outside' to hide ` {permOption({perm: 'rw'})} {permOption({perm: 'r'})} {data.show_admin ? permOption({perm: 'admin'}) : ''} {isPro ? permOption({perm: 'cloud-edit'}) : ''} {isPro ? permOption({perm: 'preview'}) : ''} ) : ( {data.cur_perm_text} ) } ); return item; } } class ShareAdminLibraries extends Component { constructor(props) { super(props); this.state = { loading: true, errorMsg: '', items: [] }; } componentDidMount() { seafileAPI.listSharedRepos().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 (

{gettext("Libraries")}

); } } export default ShareAdminLibraries;