import React, { Component } from 'react'; import classnames from 'classnames'; import moment from 'moment'; export default class WeatherTile extends Component { constructor(props) { super(props); this.state = { latlng: '', manualEntry: false, error: false }; let api = window.api; } // geolocation and manual input functions locationSubmit() { navigator.geolocation.getCurrentPosition((res) => { let latlng = `${res.coords.latitude},${res.coords.longitude}`; this.setState({ latlng }, (err) => { console.log(err); }, { maximumAge: Infinity, timeout: 10000 }); api.action("clock", "json", latlng); api.action('weather', 'json', latlng); }); } manualLocationSubmit() { event.preventDefault(); let gpsInput = document.getElementById('gps'); let latlngNoSpace = gpsInput.value.replace(/\s+/g, ''); let latlngParse = /-?[0-9]+(?:\.[0-9]*)?,-?[0-9]+(?:\.[0-9]*)?/g; if (latlngParse.test(latlngNoSpace)) { let latlng = latlngNoSpace; this.setState({latlng}, (err) => {console.log(err)}, {maximumAge: Infinity, timeout: 10000}); api.action("clock", "json", latlng); api.action('weather', 'json', latlng); this.setState({manualEntry: !this.state.manualEntry}); } else { this.setState({error: true}); return false; } } // set appearance based on weather setColors(data) { let weatherStyle = { gradient1: "", gradient2: "", text: "" }; switch (data.daily.icon) { case "clear-day": weatherStyle = { gradient1: "#A5CEF0", gradient2: "#FEF4E0", text: "black" } break; case "clear-night": weatherStyle = { gradient1: "#56668e", gradient2: "#000080", text: "white" } break; case "rain": weatherStyle = { gradient1: "#b1b2b3", gradient2: "#b0c7ff", text: "black" }; break; case "snow": weatherStyle = { gradient1: "#eee", gradient2: "#f9f9f9", text: "black" }; break; case "sleet": weatherStyle = { gradient1: "#eee", gradient2: "#f9f9f9", text: "black" }; break; case "wind": weatherStyle = { gradient1: "#eee", gradient2: "#fff", text: "black" }; break; case "fog": weatherStyle = { gradient1: "#eee", gradient2: "#fff", text: "black" }; break; case "cloudy": weatherStyle = { gradient1: "#eee", gradient2: "#b1b2b3", text: "black" }; break; case "partly-cloudy-day": weatherStyle = { gradient1: "#fcc440", gradient2: "#b1b2b3", text: "black" }; break; case "partly-cloudy-night": weatherStyle = { gradient1: "#7f7f7f", gradient2: "#56668e", text: "white" }; break; default: weatherStyle = { gradient1: "white", gradient2: "white", text: "black" }; } return weatherStyle; } // all tile views renderWrapper(child, weatherStyle = { gradient1: "white", gradient2: "white", text: "black" } ) { return (
Please try again.
} if (location.protocol === "https:") { secureCheck = this.locationSubmit()}>Detect -> } return this.renderWrapper(Please enter your{" "} latitude and longitude .
{error}Weather
-> Set location
Weather
this.setState({ manualEntry: !this.state.manualEntry }) }> ->{c.summary}
{Math.round(c.temperature)}°
Sunset at {da}