Skip to content

Commit

Permalink
added temperature display and day cycle containers
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardomcv committed Jul 21, 2020
1 parent 8ab1f20 commit 1503bbf
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/components/DataSection/DataSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,30 @@ const DataSection: FunctionComponent<DataSectionProps> = ({
);
}

const { main, weather } = data;
const { main, weather, sys } = data;

const tempValue = main.temp.toFixed();
const tempSymbol = selectedTemperatureUnit === 'celsius' ? '°C' : '°F';
const weatherIcon = weather[0].icon; // first element is the "primary"

// convert to UNIX timestamp with miliseconds
const sunriseDate = new Date(sys.sunrise * 1000).toLocaleTimeString();
const sunsetDate = new Date(sys.sunset * 1000).toLocaleTimeString();

return (
<section className="data-section">
<span>{`${tempValue} ${tempSymbol}`}</span>
<img
className="weather-icon"
alt="weather-icon"
src={`${OPEN_WEATHER_ICONS_ENDPOINT}${weatherIcon}@2x.png`}
/>
<div className="temperature-display">
<span>{`${tempValue} ${tempSymbol}`}</span>
<img
className="weather-icon"
alt="weather-icon"
src={`${OPEN_WEATHER_ICONS_ENDPOINT}${weatherIcon}@2x.png`}
/>
</div>
<div className="day-cycle">
<span>{`Sunrise: ${sunriseDate}`}</span>
<span>{`Sunset: ${sunsetDate}`}</span>
</div>
</section>
);
};
Expand Down

0 comments on commit 1503bbf

Please sign in to comment.