mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-12-30 09:41:10 +01:00
Typings cleanup and improvements
(cherry picked from commit b2c43fb2a67965d68d3d35b72302b0cddb5aca23)
This commit is contained in:
@@ -108,7 +108,7 @@ function sort(items, state) {
|
||||
return _.orderBy(items, clauses, orders);
|
||||
}
|
||||
|
||||
function createCustomFiltersSelector(type, alternateType) {
|
||||
export function createCustomFiltersSelector(type, alternateType) {
|
||||
return createSelector(
|
||||
(state) => state.customFilters.items,
|
||||
(customFilters) => {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { createSelector } from 'reselect';
|
||||
import createIndexerSelector from './createIndexerSelector';
|
||||
import { createIndexerSelectorForHook } from './createIndexerSelector';
|
||||
|
||||
function createIndexerAppProfileSelector(indexerId) {
|
||||
return createSelector(
|
||||
(state) => state.settings.appProfiles.items,
|
||||
createIndexerSelector(indexerId),
|
||||
createIndexerSelectorForHook(indexerId),
|
||||
(appProfiles, indexer = {}) => {
|
||||
return appProfiles.find((profile) => {
|
||||
return profile.id === indexer.appProfileId;
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import { createSelector } from 'reselect';
|
||||
|
||||
function createIndexerSelector(id) {
|
||||
if (id == null) {
|
||||
return createSelector(
|
||||
(state, { indexerId }) => indexerId,
|
||||
(state) => state.indexers.itemMap,
|
||||
(state) => state.indexers.items,
|
||||
(indexerId, itemMap, allIndexers) => {
|
||||
return allIndexers[itemMap[indexerId]];
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function createIndexerSelectorForHook(indexerId) {
|
||||
return createSelector(
|
||||
(state) => state.indexers.itemMap,
|
||||
(state) => state.indexers.items,
|
||||
(itemMap, allIndexers) => {
|
||||
return allIndexers[itemMap[id]];
|
||||
return indexerId ? allIndexers[itemMap[indexerId]]: undefined;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function createIndexerSelector() {
|
||||
return createSelector(
|
||||
(state, { indexerId }) => indexerId,
|
||||
(state) => state.indexers.itemMap,
|
||||
(state) => state.indexers.items,
|
||||
(indexerId, itemMap, allIndexers) => {
|
||||
return allIndexers[itemMap[indexerId]];
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
const scrollPositions = {
|
||||
indexerIndex: 0
|
||||
};
|
||||
|
||||
export default scrollPositions;
|
||||
5
frontend/src/Store/scrollPositions.ts
Normal file
5
frontend/src/Store/scrollPositions.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
const scrollPositions: Record<string, number> = {
|
||||
indexerIndex: 0,
|
||||
};
|
||||
|
||||
export default scrollPositions;
|
||||
@@ -1,28 +0,0 @@
|
||||
const thunks = {};
|
||||
|
||||
function identity(payload) {
|
||||
return payload;
|
||||
}
|
||||
|
||||
export function createThunk(type, identityFunction = identity) {
|
||||
return function(payload = {}) {
|
||||
return function(dispatch, getState) {
|
||||
const thunk = thunks[type];
|
||||
|
||||
if (thunk) {
|
||||
return thunk(getState, identityFunction(payload), dispatch);
|
||||
}
|
||||
|
||||
throw Error(`Thunk handler has not been registered for ${type}`);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export function handleThunks(handlers) {
|
||||
const types = Object.keys(handlers);
|
||||
|
||||
types.forEach((type) => {
|
||||
thunks[type] = handlers[type];
|
||||
});
|
||||
}
|
||||
|
||||
39
frontend/src/Store/thunks.ts
Normal file
39
frontend/src/Store/thunks.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Dispatch } from 'redux';
|
||||
import AppState from 'App/State/AppState';
|
||||
|
||||
type GetState = () => AppState;
|
||||
type Thunk = (
|
||||
getState: GetState,
|
||||
identityFn: never,
|
||||
dispatch: Dispatch
|
||||
) => unknown;
|
||||
|
||||
const thunks: Record<string, Thunk> = {};
|
||||
|
||||
function identity<T, TResult>(payload: T): TResult {
|
||||
return payload as unknown as TResult;
|
||||
}
|
||||
|
||||
export function createThunk(type: string, identityFunction = identity) {
|
||||
return function <T>(payload?: T) {
|
||||
return function (dispatch: Dispatch, getState: GetState) {
|
||||
const thunk = thunks[type];
|
||||
|
||||
if (thunk) {
|
||||
const finalPayload = payload ?? {};
|
||||
|
||||
return thunk(getState, identityFunction(finalPayload), dispatch);
|
||||
}
|
||||
|
||||
throw Error(`Thunk handler has not been registered for ${type}`);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export function handleThunks(handlers: Record<string, Thunk>) {
|
||||
const types = Object.keys(handlers);
|
||||
|
||||
types.forEach((type) => {
|
||||
thunks[type] = handlers[type];
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user