From 63f9338d2fc2ced5db478c7edf52b2d11dcdbf15 Mon Sep 17 00:00:00 2001 From: Qstick Date: Fri, 5 Apr 2019 23:03:42 -0400 Subject: [PATCH] Fixed: Improve Selection of Executing Commands in Artist list --- .../Artist/Index/ArtistIndexItemConnector.js | 17 +++++++---------- .../src/Store/Selectors/createArtistSelector.js | 5 ++--- .../createExecutingCommandsSelector.js | 13 +++++++++++++ 3 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 frontend/src/Store/Selectors/createExecutingCommandsSelector.js diff --git a/frontend/src/Artist/Index/ArtistIndexItemConnector.js b/frontend/src/Artist/Index/ArtistIndexItemConnector.js index eb1f2d0b9..8b997b631 100644 --- a/frontend/src/Artist/Index/ArtistIndexItemConnector.js +++ b/frontend/src/Artist/Index/ArtistIndexItemConnector.js @@ -4,9 +4,8 @@ import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; import { createSelector } from 'reselect'; -import { isCommandExecuting } from 'Utilities/Command'; import createArtistSelector from 'Store/Selectors/createArtistSelector'; -import createCommandsSelector from 'Store/Selectors/createCommandsSelector'; +import createExecutingCommandsSelector from 'Store/Selectors/createCommandsSelector'; import createQualityProfileSelector from 'Store/Selectors/createQualityProfileSelector'; import createLanguageProfileSelector from 'Store/Selectors/createLanguageProfileSelector'; import createMetadataProfileSelector from 'Store/Selectors/createMetadataProfileSelector'; @@ -40,28 +39,26 @@ function createMapStateToProps() { createLanguageProfileSelector(), createMetadataProfileSelector(), selectShowSearchAction(), - createCommandsSelector(), + createExecutingCommandsSelector(), ( artist, qualityProfile, languageProfile, metadataProfile, showSearchAction, - commands + executingCommands ) => { - const isRefreshingArtist = commands.some((command) => { + const isRefreshingArtist = executingCommands.some((command) => { return ( command.name === commandNames.REFRESH_ARTIST && - command.body.artistId === artist.id && - isCommandExecuting(command) + command.body.artistId === artist.id ); }); - const isSearchingArtist = commands.some((command) => { + const isSearchingArtist = executingCommands.some((command) => { return ( command.name === commandNames.ARTIST_SEARCH && - command.body.artistId === artist.id && - isCommandExecuting(command) + command.body.artistId === artist.id ); }); diff --git a/frontend/src/Store/Selectors/createArtistSelector.js b/frontend/src/Store/Selectors/createArtistSelector.js index bc49a9349..4b45118b8 100644 --- a/frontend/src/Store/Selectors/createArtistSelector.js +++ b/frontend/src/Store/Selectors/createArtistSelector.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import { createSelector } from 'reselect'; import createAllArtistSelector from './createAllArtistSelector'; @@ -6,8 +5,8 @@ function createArtistSelector() { return createSelector( (state, { artistId }) => artistId, createAllArtistSelector(), - (artistId, artist) => { - return _.find(artist, { id: artistId }); + (artistId, allArtists) => { + return allArtists.find((artist) => artist.id === artistId ); } ); } diff --git a/frontend/src/Store/Selectors/createExecutingCommandsSelector.js b/frontend/src/Store/Selectors/createExecutingCommandsSelector.js new file mode 100644 index 000000000..266865a8a --- /dev/null +++ b/frontend/src/Store/Selectors/createExecutingCommandsSelector.js @@ -0,0 +1,13 @@ +import { createSelector } from 'reselect'; +import { isCommandExecuting } from 'Utilities/Command'; + +function createExecutingCommandsSelector() { + return createSelector( + (state) => state.commands.items, + (commands) => { + return commands.filter((command) => isCommandExecuting(command)); + } + ); +} + +export default createExecutingCommandsSelector;