import React, { Component } from 'react'; import classnames from 'classnames'; import moment from 'moment'; class IconWithData extends Component { render() { const { props } = this; return (

{props.text}

); } } export default class WeatherTile extends Component { constructor(props) { super(props); let ship = window.ship; let api = window.api; this.state = { latlng: '' }; } locationSubmit() { console.log('location submit'); navigator.geolocation.getCurrentPosition((res) => { console.log(res); let latlng = `${res.coords.latitude},${res.coords.longitude}`; this.setState({ latlng }, (err) => { console.log(err); }, { maximumAge: Infinity, timeout: 10000 }); api.action('weather', 'json', latlng); }); } renderWrapper(child) { return (
{child}
); } renderNoData() { return this.renderWrapper((

Weather

)); } renderWithData(data) { let c = data.currently; let d = data.daily.data[0]; let da = moment.unix(d.sunsetTime).format('h:mm a') || ''; return this.renderWrapper((

Weather

{Math.round(c.temperature)}°

)); } render() { let data = !!this.props.data ? this.props.data : {}; if ('currently' in data && 'daily' in data) { return this.renderWithData(data); } return this.renderNoData(); } } window.weatherTile = WeatherTile;