-
Notifications
You must be signed in to change notification settings - Fork 4
/
circulationEvents.ts
44 lines (38 loc) · 1.1 KB
/
circulationEvents.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { CirculationEventData } from "../interfaces";
import { RequestError } from "@thepalaceproject/web-opds-client/lib/DataFetcher";
import ActionCreator from "../actions";
export interface CirculationEventsState {
data: CirculationEventData[];
isFetching: boolean;
fetchError: RequestError;
isLoaded: boolean;
}
const initialState: CirculationEventsState = {
data: null,
isFetching: false,
fetchError: null,
isLoaded: false,
};
export default (state: CirculationEventsState = initialState, action) => {
switch (action.type) {
case ActionCreator.CIRCULATION_EVENTS_REQUEST:
return Object.assign({}, state, {
isFetching: true,
fetchError: null,
});
case ActionCreator.CIRCULATION_EVENTS_LOAD:
return Object.assign({}, state, {
data: action.data.circulation_events,
isFetching: false,
isLoaded: true,
});
case ActionCreator.CIRCULATION_EVENTS_FAILURE:
return Object.assign({}, state, {
fetchError: action.error,
isFetching: false,
isLoaded: true,
});
default:
return state;
}
};