fix: revert using api to get temperature format

This commit is contained in:
David Ralph
2021-07-23 10:55:20 +01:00
parent 5a91fa24e9
commit 37df7fb08c
2 changed files with 25 additions and 17 deletions

View File

@@ -61,10 +61,8 @@ export default class Weather extends React.PureComponent {
}
};
const tempFormat = localStorage.getItem('tempformat');
if (!this.state.weather.temp) {
data = await (await fetch(window.constants.PROXY_URL + `/weather/current?city=${this.state.location}&lang=${localStorage.getItem('language')}&format=${tempFormat}`)).json();
data = await (await fetch(window.constants.PROXY_URL + `/weather/current?city=${this.state.location}&lang=${localStorage.getItem('language')}`)).json();
}
if (data.cod === '404') {
@@ -73,27 +71,37 @@ export default class Weather extends React.PureComponent {
});
}
let tempText;
switch (tempFormat) {
let temp = data.main.temp;
let temp_min = data.main.temp_min;
let temp_max = data.main.temp_max;
let temp_text = 'K';
switch (localStorage.getItem('tempformat')) {
case 'celsius':
tempText = '°C';
temp = temp - 273.15;
temp_min = temp_min - 273.15;
temp_max = temp_max - 273.15;
temp_text = '°C';
break;
case 'fahrenheit':
tempText = '°F';
temp = ((temp - 273.15) * 1.8) + 32;
temp_min = ((temp_min - 273.15) * 1.8) + 32;
temp_max = ((temp_max - 273.15) * 1.8) + 32;
temp_text = '°F';
break;
default:
tempText = 'K';
// kelvin
default:
break;
}
this.setState({
icon: data.weather[0].icon,
temp_text: tempText,
temp_text: temp_text,
weather: {
temp: Math.round(data.main.temp),
temp: Math.round(temp),
description: data.weather[0].description,
temp_min: Math.round(data.main.temp_min),
temp_max: Math.round(data.main.temp_max),
temp_min: Math.round(temp_min),
temp_max: Math.round(temp_max),
humidity: data.main.humidity,
wind_speed: data.wind.speed,
wind_degrees: data.wind.deg,