-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split data and controls sections. added icon for weather condition
- Loading branch information
1 parent
9b72afd
commit 2ad5005
Showing
8 changed files
with
145 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.controls-section { | ||
display: flex; | ||
justify-content: space-evenly; | ||
width: 100%; | ||
margin-top: 2rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { FunctionComponent } from 'react'; | ||
import LocationSelector from '../LocationSelector'; | ||
import TemperatureToggle from '../TemperatureToggle'; | ||
import { TemperatureUnit, Location } from '../../sharedTypes'; | ||
import './ControlsSection.css'; | ||
|
||
interface ControlsSectionProps { | ||
selectedLocation: Location; | ||
selectedTemperatureUnit: TemperatureUnit; | ||
onTemperatureToggle: (unit: TemperatureUnit) => void; | ||
onLocationChange: (location: Location) => void; | ||
} | ||
|
||
const ControlsSection: FunctionComponent<ControlsSectionProps> = ({ | ||
selectedLocation, | ||
selectedTemperatureUnit, | ||
onTemperatureToggle, | ||
onLocationChange, | ||
}) => ( | ||
<section className="controls-section"> | ||
<LocationSelector | ||
value={selectedLocation} | ||
onChange={onLocationChange} | ||
/> | ||
<TemperatureToggle | ||
value={selectedTemperatureUnit} | ||
onToggle={onTemperatureToggle} | ||
/> | ||
</section> | ||
); | ||
|
||
export default ControlsSection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './ControlsSection'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.data-section { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
margin-top: 2rem; | ||
width: 100%; | ||
color: white; | ||
text-align: center; | ||
font-size: 8rem; | ||
font-weight: bold; | ||
} | ||
|
||
.data-section.placeholder { | ||
font-size: 3rem; | ||
} | ||
|
||
.weather-icon { | ||
margin-top: 2rem; | ||
height: 8rem; | ||
width: auto; | ||
} | ||
|
||
@media only screen and (max-width: 600px) { | ||
.data-section { | ||
font-size: 6rem; | ||
} | ||
|
||
.weather-icon { | ||
margin-top: 1rem; | ||
height: 6rem; | ||
width: auto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React, { FunctionComponent } from 'react'; | ||
import { TemperatureUnit, Location } from '../../sharedTypes'; | ||
import useOpenWeatherQuery from '../../hooks/useOpenWeather'; | ||
import './DataSection.css'; | ||
import { OPEN_WEATHER_ICONS_ENDPOINT } from '../../config'; | ||
|
||
interface DataSectionProps { | ||
selectedLocation: Location; | ||
selectedTemperatureUnit: TemperatureUnit; | ||
} | ||
|
||
const DataSection: FunctionComponent<DataSectionProps> = ({ | ||
selectedLocation, | ||
selectedTemperatureUnit, | ||
}) => { | ||
const { | ||
data, | ||
error, | ||
loading, | ||
} = useOpenWeatherQuery({ | ||
location: selectedLocation, | ||
temperatureUnit: selectedTemperatureUnit, | ||
}); | ||
|
||
if (loading) { | ||
return ( | ||
<section className="data-section placeholder"> | ||
<p>Loading...</p> | ||
</section> | ||
); | ||
} | ||
|
||
if (error || !data) { | ||
return ( | ||
<section className="data-section placeholder"> | ||
<p>Something went wrong...</p> | ||
{error && <p>{error.message}</p>} | ||
</section> | ||
); | ||
} | ||
|
||
const { main, weather } = data; | ||
|
||
const tempValue = main.temp.toFixed(); | ||
const tempSymbol = selectedTemperatureUnit === 'celsius' ? '°C' : '°F'; | ||
const weatherIcon = weather[0].icon; // first element is the "primary" | ||
|
||
return ( | ||
<section className="data-section"> | ||
<span>{`${tempValue} ${tempSymbol}`}</span> | ||
<img | ||
className="weather-icon" | ||
alt="weather-icon" | ||
src={`${OPEN_WEATHER_ICONS_ENDPOINT}${weatherIcon}@2x.png`} | ||
/> | ||
</section> | ||
); | ||
}; | ||
|
||
export default DataSection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './DataSection'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters