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.
1 line
5.6 KiB
1 line
5.6 KiB
{"ast":null,"code":"import _asyncToGenerator from \"@babel/runtime/helpers/asyncToGenerator\";\nimport { City, Weather } from \"../../data/stub\";\nimport { setWeatherList } from \"./setWeatherList\";\nimport { setWeatherSearched } from \"./setWeatherSearched\";\nexport var getWeatherList = function getWeatherList() {\n return function () {\n var _ref = _asyncToGenerator(function* (dispatch) {\n try {\n var cityPromise = yield fetch('https://iut-weather-api.azurewebsites.net/cities');\n var cityListJson = yield cityPromise.json();\n var cityList = cityListJson.map(function (elt) {\n return new City(elt[\"name\"], elt[\"latitude\"], elt[\"longitude\"]);\n });\n var promises = cityList.map(function (city) {\n return fetch('https://iut-weather-api.azurewebsites.net/weather/city/name/' + city.name);\n });\n Promise.all(promises).then(function (values) {\n var prom = values.map(function () {\n var _ref2 = _asyncToGenerator(function* (resp) {\n var weatherJson = yield resp.json();\n return new Weather(weatherJson[\"at\"], weatherJson[\"visibility\"], weatherJson[\"weatherType\"], weatherJson[\"weatherDescription\"], weatherJson[\"temperature\"], weatherJson[\"temperatureFeelsLike\"], weatherJson[\"humidity\"], weatherJson[\"windSpeed\"], weatherJson[\"pressure\"], new City(weatherJson[\"city\"][\"name\"], weatherJson[\"city\"][\"latitude\"], weatherJson[\"city\"][\"longitude\"]));\n });\n return function (_x2) {\n return _ref2.apply(this, arguments);\n };\n }());\n Promise.all(prom).then(function (values) {\n dispatch(setWeatherList(values));\n dispatch(setWeatherSearched(values));\n });\n });\n } catch (error) {\n console.log('Error---------', error);\n }\n });\n return function (_x) {\n return _ref.apply(this, arguments);\n };\n }();\n};","map":{"version":3,"names":["City","Weather","setWeatherList","setWeatherSearched","getWeatherList","dispatch","cityPromise","fetch","cityListJson","json","cityList","map","elt","promises","city","name","Promise","all","then","values","prom","resp","weatherJson","error","console","log"],"sources":["/Users/thomaschazot/Documents/But2A/LaSuperMeteo/iut-expo-starter/redux/actions/getWeatherList.ts"],"sourcesContent":["import { City, Weather } from '../../data/stub';\nimport {GET_CITIES} from '../constants';\nimport { setWeatherList } from './setWeatherList';\nimport { setWeatherSearched } from './setWeatherSearched';\n\nexport const getWeatherList = () => {\n return async dispatch => {\n\n try {\n const cityPromise = await fetch('https://iut-weather-api.azurewebsites.net/cities');\n\n const cityListJson = await cityPromise.json();\n\n const cityList: City[] = cityListJson.map((elt: { [x: string]: any; }) => new City(elt[\"name\"], elt[\"latitude\"], elt[\"longitude\"]));\n\n const promises = cityList.map( (city) =>{\n return fetch('https://iut-weather-api.azurewebsites.net/weather/city/name/'+city.name);\n })\n Promise.all(promises).then((values) => {\n const prom = values.map(async resp => {\n const weatherJson = await resp.json();\n return new Weather(weatherJson[\"at\"], weatherJson[\"visibility\"], weatherJson[\"weatherType\"], weatherJson[\"weatherDescription\"], weatherJson[\"temperature\"], weatherJson[\"temperatureFeelsLike\"], weatherJson[\"humidity\"], weatherJson[\"windSpeed\"], weatherJson[\"pressure\"], new City(weatherJson[\"city\"][\"name\"], weatherJson[\"city\"][\"latitude\"], weatherJson[\"city\"][\"longitude\"]));\n });\n Promise.all(prom).then((values) => {\n dispatch(setWeatherList(values));\n dispatch(setWeatherSearched(values))\n })\n\n })\n } catch (error) {\n console.log('Error---------', error);\n //You can dispatch to another action if you want to display an error message in the application\n //dispatch(fetchDataRejected(error))\n }\n }\n}"],"mappings":";AAAA,SAASA,IAAI,EAAEC,OAAO;AAEtB,SAASC,cAAc;AACvB,SAASC,kBAAkB;AAE3B,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAc,GAAS;EAClC;IAAA,6BAAO,WAAMC,QAAQ,EAAI;MAEvB,IAAI;QACF,IAAMC,WAAW,SAASC,KAAK,CAAC,kDAAkD,CAAC;QAEnF,IAAMC,YAAY,SAASF,WAAW,CAACG,IAAI,EAAE;QAE7C,IAAMC,QAAgB,GAAGF,YAAY,CAACG,GAAG,CAAC,UAACC,GAA0B;UAAA,OAAK,IAAIZ,IAA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