import variables from 'modules/variables'; import { PureComponent } from 'react'; import Header from '../Header'; import Radio from '../Radio'; import Dropdown from '../Dropdown'; import Checkbox from '../Checkbox'; import { TextField } from '@mui/material'; import SettingsItem from '../SettingsItem'; export default class TimeSettings extends PureComponent { constructor() { super(); this.state = { location: localStorage.getItem('location') || '', windSpeed: localStorage.getItem('windspeed') !== 'true', }; } componentDidUpdate() { localStorage.setItem('location', this.state.location); } showReminder() { document.querySelector('.reminder-info').style.display = 'flex'; localStorage.setItem('showReminder', true); } changeLocation(e) { this.setState({ location: e.target.value, }); this.showReminder(); } getAuto() { navigator.geolocation.getCurrentPosition( async (position) => { const data = await ( await fetch( `${variables.constants.PROXY_URL}/weather/autolocation?lat=${position.coords.latitude}&lon=${position.coords.longitude}`, ) ).json(); this.setState({ location: data[0].name, }); this.showReminder(); }, (error) => { // firefox requires this 2nd function console.log(error); }, { enableHighAccuracy: true, }, ); } render() { const weatherType = localStorage.getItem('weatherType'); return ( <>
this.forceUpdate()} > this.changeLocation(e)} placeholder="London" varient="outlined" InputLabelProps={{ shrink: true }} /> this.getAuto()}> {variables.getMessage('modals.main.settings.sections.weather.auto')} {weatherType === '4' && ( this.setState({ windSpeed: localStorage.getItem('windspeed') !== 'true', }) } /> )} ); } }