1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-26 22:56:23 -04:00

New: refresh only selected or filtered series

Closes #5611
This commit is contained in:
Stevie Robinson
2023-05-21 23:05:30 +02:00
committed by GitHub
parent a117001de6
commit bf90c3cbdd
8 changed files with 139 additions and 58 deletions
@@ -0,0 +1,73 @@
import React, { useCallback, useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useSelect } from 'App/SelectContext';
import ClientSideCollectionAppState from 'App/State/ClientSideCollectionAppState';
import SeriesAppState, { SeriesIndexAppState } from 'App/State/SeriesAppState';
import { REFRESH_SERIES } from 'Commands/commandNames';
import PageToolbarButton from 'Components/Page/Toolbar/PageToolbarButton';
import { icons } from 'Helpers/Props';
import { executeCommand } from 'Store/Actions/commandActions';
import createCommandExecutingSelector from 'Store/Selectors/createCommandExecutingSelector';
import createSeriesClientSideCollectionItemsSelector from 'Store/Selectors/createSeriesClientSideCollectionItemsSelector';
import getSelectedIds from 'Utilities/Table/getSelectedIds';
interface SeriesIndexRefreshSeriesButtonProps {
isSelectMode: boolean;
selectedFilterKey: string;
}
function SeriesIndexRefreshSeriesButton(
props: SeriesIndexRefreshSeriesButtonProps
) {
const isRefreshing = useSelector(
createCommandExecutingSelector(REFRESH_SERIES)
);
const {
items,
totalItems,
}: SeriesAppState & SeriesIndexAppState & ClientSideCollectionAppState =
useSelector(createSeriesClientSideCollectionItemsSelector('seriesIndex'));
const dispatch = useDispatch();
const { isSelectMode, selectedFilterKey } = props;
const [selectState] = useSelect();
const { selectedState } = selectState;
const selectedSeriesIds = useMemo(() => {
return getSelectedIds(selectedState);
}, [selectedState]);
const seriesToRefresh =
isSelectMode && selectedSeriesIds.length > 0
? selectedSeriesIds
: items.map((m) => m.id);
let refreshLabel = 'Update All';
if (selectedSeriesIds.length > 0) {
refreshLabel = 'Update Selected';
} else if (selectedFilterKey !== 'all') {
refreshLabel = 'Update Filtered';
}
const onPress = useCallback(() => {
dispatch(
executeCommand({
name: REFRESH_SERIES,
seriesIds: seriesToRefresh,
})
);
}, [dispatch, seriesToRefresh]);
return (
<PageToolbarButton
label={refreshLabel}
isSpinning={isRefreshing}
isDisabled={!totalItems}
iconName={icons.REFRESH}
onPress={onPress}
/>
);
}
export default SeriesIndexRefreshSeriesButton;