import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { inputTypes, kinds, sizes } from 'Helpers/Props'; import Label from 'Components/Label'; import Button from 'Components/Link/Button'; import ModalContent from 'Components/Modal/ModalContent'; import ModalHeader from 'Components/Modal/ModalHeader'; import ModalBody from 'Components/Modal/ModalBody'; import ModalFooter from 'Components/Modal/ModalFooter'; import Form from 'Components/Form/Form'; import FormGroup from 'Components/Form/FormGroup'; import FormLabel from 'Components/Form/FormLabel'; import FormInputGroup from 'Components/Form/FormInputGroup'; import styles from './TagsModalContent.css'; class TagsModalContent extends Component { // // Lifecycle constructor(props, context) { super(props, context); this.state = { tags: [], applyTags: 'add' }; } // // Lifecycle onInputChange = ({ name, value }) => { this.setState({ [name]: value }); } onApplyTagsPress = () => { const { tags, applyTags } = this.state; this.props.onApplyTagsPress(tags, applyTags); } // // Render render() { const { artistTags, tagList, onModalClose } = this.props; const { tags, applyTags } = this.state; const applyTagsOptions = [ { key: 'add', value: 'Add' }, { key: 'remove', value: 'Remove' }, { key: 'replace', value: 'Replace' } ]; return ( Tags
Tags Apply Tags Result
{ artistTags.map((t) => { const tag = _.find(tagList, { id: t }); if (!tag) { return null; } const removeTag = (applyTags === 'remove' && tags.indexOf(t) > -1) || (applyTags === 'replace' && tags.indexOf(t) === -1); return ( ); }) } { (applyTags === 'add' || applyTags === 'replace') && tags.map((t) => { const tag = _.find(tagList, { id: t }); if (!tag) { return null; } if (artistTags.indexOf(t) > -1) { return null; } return ( ); }) }
); } } TagsModalContent.propTypes = { artistTags: PropTypes.arrayOf(PropTypes.number).isRequired, tagList: PropTypes.arrayOf(PropTypes.object).isRequired, onModalClose: PropTypes.func.isRequired, onApplyTagsPress: PropTypes.func.isRequired }; export default TagsModalContent;