weather.js 1.55 KB
import axios from "axios";

const WEATHER_ADDRESS = 'weather/ADDRESS';
const WEATHER_COORDINATE = 'weather/COORDINATE';
const WEATHER_TODAY_INFORMATION = 'weather/TODAY_INFORMATION';
const WEATHER_TOMMORROW_INFORMATION = 'weather/TOMMORROW_INFORMATION';

export function address() {
  const req = axios.post('/api/address')
    .then(res => res.data);

    return {
      type: WEATHER_ADDRESS,
      payload: req,
    }
}

export function coordinate(dataToSubmit) {

  const req = axios.post('/api/cordinate', dataToSubmit)
    .then(res => res.data);

    return {
      type: WEATHER_COORDINATE,
      payload: req,
    }
};

export function todayInformation(dataToSubmit) {
  const req = axios.post('/api/weather', dataToSubmit)
    .then(res => res.data);
    return {
      type: WEATHER_TODAY_INFORMATION,
      payload: req,
    } 
};

export function tommorrowInformation(dataToSubmit) {
  const req = axios.post('/api/tommorrow', dataToSubmit)
    .then(res => res.data);
    return {
      type: WEATHER_TOMMORROW_INFORMATION,
      payload: req,
    } 
};

export default function (state = {}, action) {
  switch (action.type) {
    case WEATHER_ADDRESS:
      return { ...state, address: action.payload };
      break;
    case WEATHER_COORDINATE:
      return { ...state, dot: action.payload };
      break;
    case WEATHER_TODAY_INFORMATION:
      return { ...state, todayInformation: action.payload };
      break;
    case WEATHER_TOMMORROW_INFORMATION:
      return { ...state, tommorrowInformation: action.payload };
      break;
    default:
      return state;
  }
}