34 lines
962 B
TypeScript
34 lines
962 B
TypeScript
import { createSelector } from "@reduxjs/toolkit";
|
|
import { RootState } from "../store";
|
|
import {
|
|
AdvancedSearchFilters,
|
|
FilterField,
|
|
FetchStatus,
|
|
} from "./advancedSearchSlice";
|
|
|
|
export const selectFilters = (state: RootState): AdvancedSearchFilters =>
|
|
state.advancedSearch.filters;
|
|
|
|
export const selectPagination = (state: RootState) =>
|
|
state.advancedSearch.pagination;
|
|
|
|
export const selectPaginationModel = createSelector(
|
|
[selectPagination],
|
|
pagination => ({
|
|
page: Math.max(0, (pagination.page ?? 1) - 1),
|
|
pageSize: pagination.limit ?? 10,
|
|
})
|
|
);
|
|
|
|
export const selectSort = (state: RootState) => state.advancedSearch.sort;
|
|
|
|
export const selectFilterValue = (
|
|
state: RootState,
|
|
field: string
|
|
): FilterField | undefined => state.advancedSearch.filters[field];
|
|
|
|
export const selectStatus = (state: RootState): FetchStatus =>
|
|
state.advancedSearch.status;
|
|
|
|
export const selectError = (state: RootState) => state.advancedSearch.error;
|