From 712404ddcad1931a1f6518c8f546bbf9eddcae07 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 4 Jul 2023 20:40:55 +0300 Subject: [PATCH] Show download client field only when download clients are set --- .../Indexer/Edit/EditIndexerModalContent.js | 37 +++++++++++-------- .../Edit/EditIndexerModalContentConnector.js | 20 ++++++++-- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/frontend/src/Indexer/Edit/EditIndexerModalContent.js b/frontend/src/Indexer/Edit/EditIndexerModalContent.js index 5afc22a08..4a2ec4c0e 100644 --- a/frontend/src/Indexer/Edit/EditIndexerModalContent.js +++ b/frontend/src/Indexer/Edit/EditIndexerModalContent.js @@ -26,6 +26,8 @@ function EditIndexerModalContent(props) { isTesting, saveError, item, + hasUsenetDownloadClients, + hasTorrentDownloadClients, onInputChange, onFieldChange, onModalClose, @@ -54,6 +56,7 @@ function EditIndexerModalContent(props) { } = item; const indexerDisplayName = implementationName === definitionName ? implementationName : `${implementationName} (${definitionName})`; + const showDownloadClientInput = downloadClientId.value > 0 || protocol.value === 'usenet' && hasUsenetDownloadClients || protocol.value === 'torrent' && hasTorrentDownloadClients; return ( @@ -158,22 +161,24 @@ function EditIndexerModalContent(props) { /> - - {translate('DownloadClient')} + {showDownloadClientInput ? + + {translate('DownloadClient')} - - + + : null + } {translate('Tags')} @@ -241,6 +246,8 @@ EditIndexerModalContent.propTypes = { isTesting: PropTypes.bool.isRequired, saveError: PropTypes.object, item: PropTypes.object.isRequired, + hasUsenetDownloadClients: PropTypes.bool.isRequired, + hasTorrentDownloadClients: PropTypes.bool.isRequired, onInputChange: PropTypes.func.isRequired, onFieldChange: PropTypes.func.isRequired, onModalClose: PropTypes.func.isRequired, diff --git a/frontend/src/Indexer/Edit/EditIndexerModalContentConnector.js b/frontend/src/Indexer/Edit/EditIndexerModalContentConnector.js index c76dd5ce4..66fdbbc15 100644 --- a/frontend/src/Indexer/Edit/EditIndexerModalContentConnector.js +++ b/frontend/src/Indexer/Edit/EditIndexerModalContentConnector.js @@ -3,17 +3,23 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import { createSelector } from 'reselect'; import { saveIndexer, setIndexerFieldValue, setIndexerValue, testIndexer } from 'Store/Actions/indexerActions'; -import { toggleAdvancedSettings } from 'Store/Actions/settingsActions'; +import { fetchDownloadClients, toggleAdvancedSettings } from 'Store/Actions/settingsActions'; import createIndexerSchemaSelector from 'Store/Selectors/createIndexerSchemaSelector'; import EditIndexerModalContent from './EditIndexerModalContent'; function createMapStateToProps() { return createSelector( (state) => state.settings.advancedSettings, + (state) => state.settings.downloadClients, createIndexerSchemaSelector(), - (advancedSettings, indexer) => { + (advancedSettings, downloadClients, indexer) => { + const usenetDownloadClients = downloadClients.items.filter((downloadClient) => downloadClient.protocol === 'usenet'); + const torrentDownloadClients = downloadClients.items.filter((downloadClient) => downloadClient.protocol === 'torrent'); + return { advancedSettings, + hasUsenetDownloadClients: usenetDownloadClients.length > 0, + hasTorrentDownloadClients: torrentDownloadClients.length > 0, ...indexer }; } @@ -25,7 +31,8 @@ const mapDispatchToProps = { setIndexerFieldValue, saveIndexer, testIndexer, - toggleAdvancedSettings + toggleAdvancedSettings, + dispatchFetchDownloadClients: fetchDownloadClients }; class EditIndexerModalContentConnector extends Component { @@ -33,6 +40,10 @@ class EditIndexerModalContentConnector extends Component { // // Lifecycle + componentDidMount() { + this.props.dispatchFetchDownloadClients(); + } + componentDidUpdate(prevProps, prevState) { if (prevProps.isSaving && !this.props.isSaving && !this.props.saveError) { this.props.onModalClose(); @@ -90,7 +101,8 @@ EditIndexerModalContentConnector.propTypes = { toggleAdvancedSettings: PropTypes.func.isRequired, saveIndexer: PropTypes.func.isRequired, testIndexer: PropTypes.func.isRequired, - onModalClose: PropTypes.func.isRequired + onModalClose: PropTypes.func.isRequired, + dispatchFetchDownloadClients: PropTypes.func.isRequired }; export default connect(createMapStateToProps, mapDispatchToProps)(EditIndexerModalContentConnector);