You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
import { Reducer } from 'redux'
|
|
|
|
import { RequestsActions } from '../actions/requests'
|
|
import { RequestsState } from '../types'
|
|
|
|
const initialState: RequestsState = {}
|
|
|
|
const reducer: Reducer<RequestsState, RequestsActions> = (state = initialState, action) => {
|
|
switch (action.type) {
|
|
case 'REQUESTS_START_REQUEST': {
|
|
const request = state[action.payload.id] ?? {}
|
|
|
|
return {
|
|
...state,
|
|
[action.payload.id]: {
|
|
...request,
|
|
fetching: true,
|
|
succeeded: false,
|
|
started: Date.now(),
|
|
},
|
|
}
|
|
}
|
|
case 'REQUESTS_FINISH_REQUEST': {
|
|
const request = state[action.payload.id] ?? {}
|
|
|
|
return {
|
|
...state,
|
|
[action.payload.id]: {
|
|
...request,
|
|
fetching: false,
|
|
succeeded: action.payload.succeeded,
|
|
},
|
|
}
|
|
}
|
|
default:
|
|
return state
|
|
}
|
|
}
|
|
|
|
export default reducer
|