mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-27 23:06:29 -04:00
Upgrade react-dnd and DnD Components to TypeScript
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
import { createSelector } from 'reselect';
|
||||
import AppState from 'App/State/AppState';
|
||||
import Series from 'Series/Series';
|
||||
import ImportList from 'typings/ImportList';
|
||||
import createAllSeriesSelector from './createAllSeriesSelector';
|
||||
|
||||
function createProfileInUseSelector(profileProp: string) {
|
||||
return createSelector(
|
||||
(_: AppState, { id }: { id: number }) => id,
|
||||
createAllSeriesSelector(),
|
||||
(state: AppState) => state.settings.importLists.items,
|
||||
(id, series, lists) => {
|
||||
if (!id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
series.some((s) => s[profileProp as keyof Series] === id) ||
|
||||
lists.some((list) => list[profileProp as keyof ImportList] === id)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default createProfileInUseSelector;
|
||||
@@ -1,7 +1,7 @@
|
||||
import _ from 'lodash';
|
||||
import { createSelector } from 'reselect';
|
||||
import ModelBase from 'App/ModelBase';
|
||||
import {
|
||||
AppSectionItemSchemaState,
|
||||
AppSectionProviderState,
|
||||
AppSectionSchemaState,
|
||||
} from 'App/State/AppSectionState';
|
||||
@@ -11,30 +11,26 @@ import selectSettings, {
|
||||
} from 'Store/Selectors/selectSettings';
|
||||
import getSectionState from 'Utilities/State/getSectionState';
|
||||
|
||||
type SchemaState<T> = AppSectionSchemaState<T> | AppSectionItemSchemaState<T>;
|
||||
|
||||
function selector<
|
||||
T extends ModelBaseSetting,
|
||||
S extends AppSectionProviderState<T> & AppSectionSchemaState<T>
|
||||
S extends AppSectionProviderState<T> & SchemaState<T>
|
||||
>(id: number | undefined, section: S) {
|
||||
if (!id) {
|
||||
const item = _.isArray(section.schema)
|
||||
? section.selectedSchema
|
||||
: section.schema;
|
||||
const settings = selectSettings(
|
||||
Object.assign({ name: '' }, item),
|
||||
section.pendingChanges ?? {},
|
||||
section.saveError
|
||||
);
|
||||
|
||||
if (id) {
|
||||
const {
|
||||
isSchemaFetching: isFetching,
|
||||
isSchemaPopulated: isPopulated,
|
||||
schemaError: error,
|
||||
isFetching,
|
||||
isPopulated,
|
||||
error,
|
||||
isSaving,
|
||||
saveError,
|
||||
isTesting,
|
||||
pendingChanges,
|
||||
} = section;
|
||||
|
||||
const item = section.items.find((i) => i.id === id)!;
|
||||
const settings = selectSettings<T>(item, pendingChanges, saveError);
|
||||
|
||||
return {
|
||||
isFetching,
|
||||
isPopulated,
|
||||
@@ -43,24 +39,31 @@ function selector<
|
||||
saveError,
|
||||
isTesting,
|
||||
...settings,
|
||||
pendingChanges,
|
||||
item: settings.settings,
|
||||
};
|
||||
}
|
||||
|
||||
const item =
|
||||
'selectedSchema' in section
|
||||
? section.selectedSchema
|
||||
: (section.schema as T);
|
||||
|
||||
const settings = selectSettings(
|
||||
Object.assign({ name: '' }, item),
|
||||
section.pendingChanges ?? {},
|
||||
section.saveError
|
||||
);
|
||||
|
||||
const {
|
||||
isFetching,
|
||||
isPopulated,
|
||||
error,
|
||||
isSchemaFetching: isFetching,
|
||||
isSchemaPopulated: isPopulated,
|
||||
schemaError: error,
|
||||
isSaving,
|
||||
saveError,
|
||||
isTesting,
|
||||
pendingChanges,
|
||||
} = section;
|
||||
|
||||
const item = section.items.find((i) => i.id === id)!;
|
||||
const settings = selectSettings<T>(item, pendingChanges, saveError);
|
||||
|
||||
return {
|
||||
isFetching,
|
||||
isPopulated,
|
||||
@@ -69,13 +72,14 @@ function selector<
|
||||
saveError,
|
||||
isTesting,
|
||||
...settings,
|
||||
pendingChanges,
|
||||
item: settings.settings,
|
||||
};
|
||||
}
|
||||
|
||||
export default function createProviderSettingsSelector<
|
||||
T extends ModelBase,
|
||||
S extends AppSectionProviderState<T> & AppSectionSchemaState<T>
|
||||
S extends AppSectionProviderState<T> & SchemaState<T>
|
||||
>(sectionName: string) {
|
||||
// @ts-expect-error - This isn't fully typed
|
||||
return createSelector(
|
||||
@@ -87,7 +91,7 @@ export default function createProviderSettingsSelector<
|
||||
|
||||
export function createProviderSettingsSelectorHook<
|
||||
T extends ModelBaseSetting,
|
||||
S extends AppSectionProviderState<T> & AppSectionSchemaState<T>
|
||||
S extends AppSectionProviderState<T> & SchemaState<T>
|
||||
>(sectionName: string, id: number | undefined) {
|
||||
return createSelector(
|
||||
(state: AppState) => state.settings,
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { createSelector } from 'reselect';
|
||||
import AppState from 'App/State/AppState';
|
||||
import createAllSeriesSelector from './createAllSeriesSelector';
|
||||
|
||||
function createQualityProfileInUseSelector(id: number | undefined) {
|
||||
return createSelector(
|
||||
createAllSeriesSelector(),
|
||||
(state: AppState) => state.settings.importLists.items,
|
||||
(series, lists) => {
|
||||
if (!id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
series.some((s) => s.qualityProfileId === id) ||
|
||||
lists.some((list) => list.qualityProfileId === id)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default createQualityProfileInUseSelector;
|
||||
Reference in New Issue
Block a user