|
import { createReducer } from "@reduxjs/toolkit"; |
|
import { Poi } from "../types/Poi"; |
|
import { |
|
fetchPoiRequest, |
|
fetchPoiSuccess, |
|
fetchPoiFailure, |
|
} from "../actions/poiActions"; |
|
|
|
interface PoiState { |
|
data: Poi[] | null; |
|
loading: boolean; |
|
error: string | null; |
|
} |
|
|
|
const initialState: PoiState = { |
|
data: null, |
|
loading: false, |
|
error: null, |
|
}; |
|
|
|
const poiReducer = createReducer(initialState, (builder) => { |
|
builder |
|
.addCase(fetchPoiRequest, (state) => { |
|
state.loading = true; |
|
state.error = null; |
|
}) |
|
.addCase(fetchPoiSuccess, (state, action) => { |
|
state.loading = false; |
|
state.data = action.payload; |
|
}) |
|
.addCase(fetchPoiFailure, (state, action) => { |
|
state.loading = false; |
|
state.error = action.payload; |
|
}); |
|
}); |
|
|
|
export default poiReducer; |
|
|