parent
7c0d344437
commit
62b948b24c
@ -0,0 +1,9 @@
|
|||||||
|
import AppSectionState from 'App/State/AppSectionState';
|
||||||
|
import Episode from 'Episode/Episode';
|
||||||
|
import { FilterBuilderProp } from './AppState';
|
||||||
|
|
||||||
|
interface CalendarAppState extends AppSectionState<Episode> {
|
||||||
|
filterBuilderProps: FilterBuilderProp<Episode>[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CalendarAppState;
|
@ -0,0 +1,56 @@
|
|||||||
|
import React, { useCallback } from 'react';
|
||||||
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
|
import { createSelector } from 'reselect';
|
||||||
|
import AppState from 'App/State/AppState';
|
||||||
|
import FilterModal from 'Components/Filter/FilterModal';
|
||||||
|
import { setCalendarFilter } from 'Store/Actions/calendarActions';
|
||||||
|
|
||||||
|
function createCalendarSelector() {
|
||||||
|
return createSelector(
|
||||||
|
(state: AppState) => state.calendar.items,
|
||||||
|
(calendar) => {
|
||||||
|
return calendar;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createFilterBuilderPropsSelector() {
|
||||||
|
return createSelector(
|
||||||
|
(state: AppState) => state.calendar.filterBuilderProps,
|
||||||
|
(filterBuilderProps) => {
|
||||||
|
return filterBuilderProps;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SeriesIndexFilterModalProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CalendarFilterModal(
|
||||||
|
props: SeriesIndexFilterModalProps
|
||||||
|
) {
|
||||||
|
const sectionItems = useSelector(createCalendarSelector());
|
||||||
|
const filterBuilderProps = useSelector(createFilterBuilderPropsSelector());
|
||||||
|
const customFilterType = 'calendar';
|
||||||
|
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
const dispatchSetFilter = useCallback(
|
||||||
|
(payload: unknown) => {
|
||||||
|
dispatch(setCalendarFilter(payload));
|
||||||
|
},
|
||||||
|
[dispatch]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FilterModal
|
||||||
|
// TODO: Don't spread all the props
|
||||||
|
{...props}
|
||||||
|
sectionItems={sectionItems}
|
||||||
|
filterBuilderProps={filterBuilderProps}
|
||||||
|
customFilterType={customFilterType}
|
||||||
|
dispatchSetFilter={dispatchSetFilter}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
@ -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];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
|||||||
|
import { Dispatch } from 'redux';
|
||||||
|
import AppState from 'App/State/AppState';
|
||||||
|
|
||||||
|
type GetState = () => AppState;
|
||||||
|
type Thunk = (
|
||||||
|
getState: GetState,
|
||||||
|
identity: unknown,
|
||||||
|
dispatch: Dispatch
|
||||||
|
) => unknown;
|
||||||
|
|
||||||
|
const thunks: Record<string, Thunk> = {};
|
||||||
|
|
||||||
|
function identity(payload: unknown) {
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createThunk(type: string, identityFunction = identity) {
|
||||||
|
return function (payload: unknown = {}) {
|
||||||
|
return function (dispatch: Dispatch, getState: 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: Record<string, Thunk>) {
|
||||||
|
const types = Object.keys(handlers);
|
||||||
|
|
||||||
|
types.forEach((type) => {
|
||||||
|
thunks[type] = handlers[type];
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in new issue