mirror of
https://github.com/mue/mue.git
synced 2026-07-14 12:34:03 +02:00
fix: revert using api to get temperature format
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user