import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { icons } from 'Helpers/Props'; import Button from 'Components/Link/Button'; import Link from 'Components/Link/Link'; import Icon from 'Components/Icon'; import LoadingIndicator from 'Components/Loading/LoadingIndicator'; import TextInput from 'Components/Form/TextInput'; import PageContent from 'Components/Page/PageContent'; import PageContentBodyConnector from 'Components/Page/PageContentBodyConnector'; import AddNewArtistSearchResultConnector from './AddNewArtistSearchResultConnector'; import styles from './AddNewArtist.css'; class AddNewArtist extends Component { // // Lifecycle constructor(props, context) { super(props, context); this.state = { term: props.term || '', isFetching: false }; } componentDidMount() { const term = this.state.term; if (term) { this.props.onArtistLookupChange(term); } } componentDidUpdate(prevProps) { const { term, isFetching } = this.props; if (term && term !== prevProps.term) { this.setState({ term, isFetching: true }); this.props.onArtistLookupChange(term); } else if (isFetching !== prevProps.isFetching) { this.setState({ isFetching }); } } // // Listeners onSearchInputChange = ({ value }) => { const hasValue = !!value.trim(); this.setState({ term: value, isFetching: hasValue }, () => { if (hasValue) { this.props.onArtistLookupChange(value); } else { this.props.onClearArtistLookup(); } }); } onClearArtistLookupPress = () => { this.setState({ term: '' }); this.props.onClearArtistLookup(); } // // Render render() { const { error, items } = this.props; const term = this.state.term; const isFetching = this.state.isFetching; return (
{ isFetching && } { !isFetching && !!error &&
Failed to load search results, please try again.
} { !isFetching && !error && !!items.length &&
{ items.map((item) => { return ( ); }) }
} { !isFetching && !error && !items.length && !!term &&
Couldn't find any results for '{term}'
You can also search using MusicBrainz ID of a show. eg. lidarr:71663
Why can't I find my artist?
} { !term &&
It's easy to add a new artist, just start typing the name the artist you want to add.
You can also search using MusicBrainz ID of a show. eg. lidarr:cc197bad-dc9c-440d-a5b5-d52ba2e14234
}
); } } AddNewArtist.propTypes = { term: PropTypes.string, isFetching: PropTypes.bool.isRequired, error: PropTypes.object, isAdding: PropTypes.bool.isRequired, addError: PropTypes.object, items: PropTypes.arrayOf(PropTypes.object).isRequired, onArtistLookupChange: PropTypes.func.isRequired, onClearArtistLookup: PropTypes.func.isRequired }; export default AddNewArtist;