import PropTypes from 'prop-types'; import { Component } from "react"; import { Modal, Button } from "react-bootstrap"; import Select from 'react-select'; import "./LibraryDialog.scss"; export default class LibraryDialog extends Component { static defaultProps = { platform: null, }; static propTypes = { onHide: PropTypes.func.isRequired, onSubmit: PropTypes.func.isRequired, platform: PropTypes.object, apiURL: PropTypes.string.isRequired, } constructor(props){ super(props); this.state = { availableFolders: [], selectedFolder: null, loadingFolders: true, error: "", }; } componentDidUpdate(){ if (this.props.platform !== null && this.props.platform.type == "library" && this.state.loadingFolders){ $.get(`${this.props.apiURL}/cloudlibrary/${this.props.platform.name}/listfolders`) .done(result => { result.folders.forEach(album => { album.label = `${album.name} (${album.images_count} images)`; album.value = album.url; }) this.setState({availableFolders: result.folders}); }) .fail((error) => { this.setState({loadingFolders: false, error: "Cannot load folders. Check your internet connection."}); }) .always(() => { this.setState({loadingFolders: false}); }); } } handleSelectFolder = (e) => this.setState({selectedFolder: e}); handleSubmit = e => this.props.onSubmit(this.state.selectedFolder); render() { const { onHide, platform, } = this.props; const title = "Import from " + (platform !== null ? platform.name : "Platform"); const isVisible = platform !== null && platform.type === "library"; return ( {title}

Import the images from your {platform === null ? "" : platform.name} library into a new task.