diff --git a/frontend/src/InteractiveImport/Interactive/InteractiveImportModalContent.js b/frontend/src/InteractiveImport/Interactive/InteractiveImportModalContent.js index 4d52272c7..dfb79de68 100644 --- a/frontend/src/InteractiveImport/Interactive/InteractiveImportModalContent.js +++ b/frontend/src/InteractiveImport/Interactive/InteractiveImportModalContent.js @@ -487,7 +487,7 @@ class InteractiveImportModalContent extends Component { diff --git a/frontend/src/InteractiveImport/Interactive/InteractiveImportRow.js b/frontend/src/InteractiveImport/Interactive/InteractiveImportRow.js index 8e89c4b9e..15975697a 100644 --- a/frontend/src/InteractiveImport/Interactive/InteractiveImportRow.js +++ b/frontend/src/InteractiveImport/Interactive/InteractiveImportRow.js @@ -441,7 +441,7 @@ class InteractiveImportRow extends Component { l.id) : []} modalTitle={modalTitle} onModalClose={this.onSelectLanguageModalClose} /> diff --git a/frontend/src/InteractiveImport/Language/SelectLanguageModal.js b/frontend/src/InteractiveImport/Language/SelectLanguageModal.js index 938d26a6d..f0164358e 100644 --- a/frontend/src/InteractiveImport/Language/SelectLanguageModal.js +++ b/frontend/src/InteractiveImport/Language/SelectLanguageModal.js @@ -1,6 +1,7 @@ import PropTypes from 'prop-types'; import React, { Component } from 'react'; import Modal from 'Components/Modal/Modal'; +import { sizes } from 'Helpers/Props'; import SelectLanguageModalContentConnector from './SelectLanguageModalContentConnector'; class SelectLanguageModal extends Component { @@ -19,6 +20,7 @@ class SelectLanguageModal extends Component { { - return { - key: language.id, - value: language.name + // + // Lifecycle + + constructor(props, context) { + super(props, context); + + const { + languageIds + } = props; + + this.state = { + languageIds }; - }); + } - return ( - - - {modalTitle} - Select Language - + // + // Listeners - - { - isFetching && - - } + onLanguageChange = ({ value, name }) => { + const { + languageIds + } = this.state; - { - !isFetching && !!error && - Unable to load languages - } + const changedId = parseInt(name); - { - isPopulated && !error && - - - Language + let newLanguages = languageIds; - - - - } - + if (value) { + newLanguages.push(changedId); + } - - - Cancel - - - - ); + if (!value) { + newLanguages = languageIds.filter((i) => i !== changedId); + } + + this.setState({ languageIds: newLanguages }); + }; + + onLanguageSelect = () => { + this.props.onLanguageSelect(this.state); + }; + + // + // Render + + render() { + const { + isFetching, + isPopulated, + error, + items, + modalTitle, + onModalClose + } = this.props; + + const { + languageIds + } = this.state; + + return ( + + + {modalTitle} + + + + { + isFetching && + + } + + { + !isFetching && !!error && + + Unable To Load Languages + + } + + { + isPopulated && !error && + + { + items.map(( language ) => { + return ( + + {language.name} + + + ); + }) + } + + } + + + + + Cancel + + + + Select Languages + + + + ); + } } SelectLanguageModalContent.propTypes = { - languageId: PropTypes.number.isRequired, + languageIds: PropTypes.arrayOf(PropTypes.number).isRequired, isFetching: PropTypes.bool.isRequired, isPopulated: PropTypes.bool.isRequired, error: PropTypes.object, @@ -86,4 +147,8 @@ SelectLanguageModalContent.propTypes = { onModalClose: PropTypes.func.isRequired }; +SelectLanguageModalContent.defaultProps = { + languages: [] +}; + export default SelectLanguageModalContent; diff --git a/frontend/src/InteractiveImport/Language/SelectLanguageModalContentConnector.js b/frontend/src/InteractiveImport/Language/SelectLanguageModalContentConnector.js index 5ed9660dc..1eda0b176 100644 --- a/frontend/src/InteractiveImport/Language/SelectLanguageModalContentConnector.js +++ b/frontend/src/InteractiveImport/Language/SelectLanguageModalContentConnector.js @@ -26,7 +26,7 @@ class SelectLanguageModalContentConnector extends Component { // // Listeners - onLanguageSelect = ({ value }) => { + onLanguageSelect = ({ languageIds }) => { const { ids, dispatchUpdateInteractiveImportItems, @@ -35,7 +35,7 @@ class SelectLanguageModalContentConnector extends Component { const languages = []; - value.forEach((languageId) => { + languageIds.forEach((languageId) => { const language = _.find(this.props.items, (item) => item.id === parseInt(languageId)); diff --git a/frontend/src/Store/Actions/releaseActions.js b/frontend/src/Store/Actions/releaseActions.js index 1a1009964..ee36d3e99 100644 --- a/frontend/src/Store/Actions/releaseActions.js +++ b/frontend/src/Store/Actions/releaseActions.js @@ -1,6 +1,7 @@ import { createAction } from 'redux-actions'; -import { filterBuilderTypes, filterBuilderValueTypes, filterTypes, sortDirections } from 'Helpers/Props'; +import { filterBuilderTypes, filterBuilderValueTypes, filterTypePredicates, filterTypes, sortDirections } from 'Helpers/Props'; import { createThunk, handleThunks } from 'Store/thunks'; +import sortByName from 'Utilities/Array/sortByName'; import createAjaxRequest from 'Utilities/createAjaxRequest'; import createFetchHandler from './Creators/createFetchHandler'; import createHandleActions from './Creators/createHandleActions'; @@ -37,6 +38,13 @@ export const defaultState = { return seeders * 1000000 + leechers; }, + languages: function(item, direction) { + if (item.languages.length > 1) { + return 10000; + } + + return item.languages[0].id; + }, rejections: function(item, direction) { const rejections = item.rejections; const releaseWeight = item.releaseWeight; @@ -95,6 +103,13 @@ export const defaultState = { return false; }, + languages: function(item, filterValue, type) { + const predicate = filterTypePredicates[type]; + + const languages = item.languages.map((language) => language.name); + + return predicate(languages, filterValue); + }, rejectionCount: function(item, value, type) { const rejectionCount = item.rejections.length; @@ -197,6 +212,25 @@ export const defaultState = { type: filterBuilderTypes.EXACT, valueType: filterBuilderValueTypes.QUALITY }, + { + name: 'languages', + label: 'Languages', + type: filterBuilderTypes.ARRAY, + optionsSelector: function(items) { + const genreList = items.reduce((acc, release) => { + release.languages.forEach((language) => { + acc.push({ + id: language.name, + name: language.name + }); + }); + + return acc; + }, []); + + return genreList.sort(sortByName); + } + }, { name: 'rejectionCount', label: 'Rejection Count',