parent
11832a418c
commit
3d44abdf7c
@ -0,0 +1,8 @@
|
||||
import { City } from '../../data/stub';
|
||||
import {GET_CITIES} from '../constants';
|
||||
|
||||
export const getCity = () => {
|
||||
return {
|
||||
type: GET_CITIES,
|
||||
};
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
import { City } from '../../data/stub';
|
||||
import {FETCH_FAVORITE_CITY} from '../constants';
|
||||
|
||||
export const getCityList = () => {
|
||||
return {
|
||||
type: FETCH_FAVORITE_CITY,
|
||||
};
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
import { City } from '../../data/stub';
|
||||
import {FETCH_CITIES} from '../constants';
|
||||
|
||||
export const setCityList = (cityList: City[]) => {
|
||||
return {
|
||||
type: FETCH_CITIES,
|
||||
payload: cityList,
|
||||
};
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
import { City } from '../../data/stub';
|
||||
import {ADD_FAVORITE_CITY} from '../constants';
|
||||
|
||||
export const setFavoriteCity = (city: City | null) => {
|
||||
return {
|
||||
type: ADD_FAVORITE_CITY,
|
||||
payload: city,
|
||||
};
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
export const FETCH_CITIES = "FETCH_CITIES"
|
||||
export const ADD_FAVORITE_CITY = "ADD_FAVORITE_CITY"
|
||||
export const FETCH_FAVORITE_CITY = "FETCH_FAVORITE_CITY"
|
||||
export const GET_CITIES = "GET_CITIES"
|
||||
|
@ -0,0 +1,26 @@
|
||||
import { City } from "../../data/stub";
|
||||
import { ADD_FAVORITE_CITY, FETCH_CITY, FETCH_FAVORITE_CITY, GET_CITIES } from "../constants";
|
||||
|
||||
const initialState = {
|
||||
city: [],
|
||||
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_CITY:
|
||||
// @ts-ignore
|
||||
return {...state, city: action.payload};
|
||||
case FETCH_FAVORITE_CITY:
|
||||
return {...state, favoriteCity: state.favoriteCity}
|
||||
case GET_CITIES:
|
||||
return {...state, city: state.city}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export default appReducer;
|
@ -0,0 +1,14 @@
|
||||
import {configureStore} from '@reduxjs/toolkit'
|
||||
import appReducer from './reducers/appReducer';
|
||||
|
||||
// Reference here all your application reducers
|
||||
const reducer = {
|
||||
appReducer: appReducer,
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const store = configureStore({
|
||||
reducer,
|
||||
},);
|
||||
|
||||
export default store;
|
Loading…
Reference in new issue