김건희

[Add] Weather Redux Setting

1 import { combineReducers } from "redux"; 1 import { combineReducers } from "redux";
2 import user from "./user.js"; 2 import user from "./user.js";
3 +import weather from "./weather";
3 4
4 const rootReducer = combineReducers({ 5 const rootReducer = combineReducers({
5 user, 6 user,
7 + weather,
6 }) 8 })
7 9
8 export default rootReducer; 10 export default rootReducer;
...\ No newline at end of file ...\ No newline at end of file
......
1 +import axios from "axios";
2 +
3 +const WEATHER_ADDRESS = 'weather/ADDRESS';
4 +const WEATHER_TODAY_INFORMATION = 'weather/TODAY_INFORMATION';
5 +
6 +export function coordinate(dataToSubmit) {
7 +
8 + const req = axios.post('http://localhost:4000/api/address', dataToSubmit)
9 + .then(res => res.data);
10 +
11 + return {
12 + type: WEATHER_ADDRESS,
13 + payload: req,
14 + }
15 +};
16 +
17 +export function information(dataToSubmit) {
18 +
19 + const req = axios.post('http://localhost:4000/api/mainpage', dataToSubmit)
20 + .then(res => res.data);
21 +
22 + return {
23 + type: WEATHER_TODAY_INFORMATION,
24 + payload: req,
25 + }
26 +};
27 +
28 +export default function (state = {}, action) {
29 + switch (action.type) {
30 + case WEATHER_ADDRESS:
31 + return { ...state, dot: action.payload };
32 + break;
33 + case WEATHER_TODAY_INFORMATION:
34 + return { ...state, todayInformation: action.payload };
35 + break;
36 + default:
37 + return state;
38 + }
39 +}
...\ No newline at end of file ...\ No newline at end of file