parent
3d44abdf7c
commit
0ed9dae07b
@ -1,8 +1,22 @@
|
|||||||
import { City } from '../../data/stub';
|
import { City } from '../../data/stub';
|
||||||
import {GET_CITIES} from '../constants';
|
import {GET_CITIES} from '../constants';
|
||||||
|
import { setCityList } from './setCityList';
|
||||||
|
|
||||||
export const getCity = () => {
|
export const getCityList = () => {
|
||||||
return {
|
return async dispatch => {
|
||||||
type: GET_CITIES,
|
|
||||||
};
|
try {
|
||||||
|
const cityPromise = await fetch('https://iut-weather-api.azurewebsites.net/cities');
|
||||||
|
|
||||||
|
const cityListJson = await cityPromise.json();
|
||||||
|
|
||||||
|
const cityList: City[] = cityListJson.map((elt: { [x: string]: any; }) => new City(elt["name"], elt["latitude"], elt["longitude"]));
|
||||||
|
|
||||||
|
dispatch(setCityList(cityList));
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Error---------', error);
|
||||||
|
//You can dispatch to another action if you want to display an error message in the application
|
||||||
|
//dispatch(fetchDataRejected(error))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue