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.
27 lines
835 B
27 lines
835 B
import { City } from "../../data/stub";
|
|
import { ADD_FAVORITE_CITY, FETCH_CITIES, FETCH_FAVORITE_CITY, GET_CITIES } from "../constants";
|
|
|
|
const initialState = {
|
|
cityList: [],
|
|
favoriteCity: null,
|
|
}
|
|
|
|
const appReducer = (state = initialState, action) => {
|
|
switch (action.type) {
|
|
case ADD_FAVORITE_CITY:
|
|
// @ts-ignore
|
|
return {...state, favoriteCity: state.favoriteCity = action.payload};
|
|
case FETCH_CITIES:
|
|
console.log(action.payload)
|
|
// @ts-ignore
|
|
return {...state, cityList: action.payload};
|
|
case FETCH_FAVORITE_CITY:
|
|
return {...state, favoriteCity: state.favoriteCity}
|
|
case GET_CITIES:
|
|
return {...state, cityList: action.payload}
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export default appReducer; |