(cherry picked from commit bf90c3cbddffca4f7ad07c3ae51fa705988cd80b) Closes #3717pull/4256/head
parent
0e7b368c3a
commit
cbb3cb78f9
@ -0,0 +1,8 @@
|
||||
import { CustomFilter } from './AppState';
|
||||
|
||||
interface ClientSideCollectionAppState {
|
||||
totalItems: number;
|
||||
customFilters: CustomFilter[];
|
||||
}
|
||||
|
||||
export default ClientSideCollectionAppState;
|
@ -0,0 +1,74 @@
|
||||
import React, { useCallback, useMemo } from 'react';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { useSelect } from 'App/SelectContext';
|
||||
import ArtistAppState, { ArtistIndexAppState } from 'App/State/ArtistAppState';
|
||||
import ClientSideCollectionAppState from 'App/State/ClientSideCollectionAppState';
|
||||
import { REFRESH_ARTIST } from 'Commands/commandNames';
|
||||
import PageToolbarButton from 'Components/Page/Toolbar/PageToolbarButton';
|
||||
import { icons } from 'Helpers/Props';
|
||||
import { executeCommand } from 'Store/Actions/commandActions';
|
||||
import createArtistClientSideCollectionItemsSelector from 'Store/Selectors/createArtistClientSideCollectionItemsSelector';
|
||||
import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector';
|
||||
import translate from 'Utilities/String/translate';
|
||||
import getSelectedIds from 'Utilities/Table/getSelectedIds';
|
||||
|
||||
interface ArtistIndexRefreshArtistsButtonProps {
|
||||
isSelectMode: boolean;
|
||||
selectedFilterKey: string;
|
||||
}
|
||||
|
||||
function ArtistIndexRefreshArtistsButton(
|
||||
props: ArtistIndexRefreshArtistsButtonProps
|
||||
) {
|
||||
const isRefreshing = useSelector(
|
||||
createCommandExecutingSelector(REFRESH_ARTIST)
|
||||
);
|
||||
const {
|
||||
items,
|
||||
totalItems,
|
||||
}: ArtistAppState & ArtistIndexAppState & ClientSideCollectionAppState =
|
||||
useSelector(createArtistClientSideCollectionItemsSelector('artistIndex'));
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const { isSelectMode, selectedFilterKey } = props;
|
||||
const [selectState] = useSelect();
|
||||
const { selectedState } = selectState;
|
||||
|
||||
const selectedArtistIds = useMemo(() => {
|
||||
return getSelectedIds(selectedState);
|
||||
}, [selectedState]);
|
||||
|
||||
const artistsToRefresh =
|
||||
isSelectMode && selectedArtistIds.length > 0
|
||||
? selectedArtistIds
|
||||
: items.map((m) => m.id);
|
||||
|
||||
let refreshLabel = translate('UpdateAll');
|
||||
|
||||
if (selectedArtistIds.length > 0) {
|
||||
refreshLabel = translate('UpdateSelected');
|
||||
} else if (selectedFilterKey !== 'all') {
|
||||
refreshLabel = translate('UpdateFiltered');
|
||||
}
|
||||
|
||||
const onPress = useCallback(() => {
|
||||
dispatch(
|
||||
executeCommand({
|
||||
name: REFRESH_ARTIST,
|
||||
artistIds: artistsToRefresh,
|
||||
})
|
||||
);
|
||||
}, [dispatch, artistsToRefresh]);
|
||||
|
||||
return (
|
||||
<PageToolbarButton
|
||||
label={refreshLabel}
|
||||
isSpinning={isRefreshing}
|
||||
isDisabled={!totalItems}
|
||||
iconName={icons.REFRESH}
|
||||
onPress={onPress}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default ArtistIndexRefreshArtistsButton;
|
@ -1,24 +1,41 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
|
||||
namespace NzbDrone.Core.Music.Commands
|
||||
{
|
||||
public class RefreshArtistCommand : Command
|
||||
{
|
||||
public int? ArtistId { get; set; }
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||
public int ArtistId
|
||||
{
|
||||
get => 0;
|
||||
set
|
||||
{
|
||||
if (ArtistIds.Empty())
|
||||
{
|
||||
ArtistIds.Add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<int> ArtistIds { get; set; }
|
||||
public bool IsNewArtist { get; set; }
|
||||
|
||||
public RefreshArtistCommand()
|
||||
{
|
||||
ArtistIds = new List<int>();
|
||||
}
|
||||
|
||||
public RefreshArtistCommand(int? artistId, bool isNewArtist = false)
|
||||
public RefreshArtistCommand(List<int> artistIds, bool isNewArtist = false)
|
||||
{
|
||||
ArtistId = artistId;
|
||||
ArtistIds = artistIds;
|
||||
IsNewArtist = isNewArtist;
|
||||
}
|
||||
|
||||
public override bool SendUpdatesToClient => true;
|
||||
|
||||
public override bool UpdateScheduledTask => !ArtistId.HasValue;
|
||||
public override bool UpdateScheduledTask => ArtistIds.Empty();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue