-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from HubSpot/jmiller/getting-started-v2
Update getting started example
- Loading branch information
Showing
9 changed files
with
347 additions
and
201 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
65 changes: 43 additions & 22 deletions
65
...s/getting-started/getting-started-project/getting-started-app/components/WeatherCards.tsx
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 |
---|---|---|
@@ -1,42 +1,63 @@ | ||
import dayjs from 'dayjs'; | ||
import weatherStyles from '../styles/weather.module.css'; | ||
import { getWeatherIcon } from '../utils.ts'; | ||
import { ForecastData } from '../constants.ts'; | ||
|
||
export function CurrentWeatherCard({ weatherData }: any) { | ||
const { location, forecast } = weatherData; | ||
const { forecastday } = forecast; | ||
const currentDay = forecastday[0].day; | ||
interface WeatherProps { | ||
city: string; | ||
forecast: ForecastData[]; | ||
} | ||
interface CurrentWeatherCardProps { | ||
weatherData: WeatherProps; | ||
} | ||
|
||
export function CurrentWeatherCard({ weatherData }: CurrentWeatherCardProps) { | ||
const { forecast, city } = weatherData; | ||
const currentDay = forecast[0]; | ||
|
||
return ( | ||
<div className={weatherStyles.current}> | ||
<div className={weatherStyles.current} key={currentDay.time}> | ||
<div className={weatherStyles.condition}> | ||
<img | ||
src={getWeatherIcon(currentDay.condition.text.trim())} | ||
alt={currentDay.condition.text} | ||
src={getWeatherIcon(currentDay.weather_code.toString())} | ||
alt={`${city}-weather-icon-${currentDay.weather_code}`} | ||
/> | ||
<h3> | ||
{currentDay.avgtemp_f}° | ||
{currentDay.apparent_temperature_max}° | ||
<span className={weatherStyles.unit}>F</span> | ||
</h3> | ||
</div> | ||
<h2 className={weatherStyles.city}>{location.name}</h2> | ||
<span className={weatherStyles.country}>{location.country}</span> | ||
<h2 className={weatherStyles.city}>{city}</h2> | ||
</div> | ||
); | ||
} | ||
|
||
export function UpcomingWeatherCard({ weatherData }: any) { | ||
interface UpcomingWeatherCardProps { | ||
weatherData: WeatherProps; | ||
} | ||
|
||
export function UpcomingWeatherCard({ weatherData }: UpcomingWeatherCardProps) { | ||
const { city, forecast } = weatherData; | ||
|
||
return ( | ||
<div className={weatherStyles.card}> | ||
<span>{dayjs(weatherData.date).format('dddd')}</span> | ||
<img | ||
src={getWeatherIcon(weatherData.day.condition.text.trim())} | ||
alt={weatherData.day.condition.text} | ||
/> | ||
<h3> | ||
{weatherData.day.avgtemp_f}° | ||
<span className={weatherStyles.unit}>F</span> | ||
</h3> | ||
</div> | ||
<> | ||
{forecast?.map((weather, index: number) => { | ||
if (index === 0) return null; | ||
|
||
return ( | ||
<div className={weatherStyles.card} key={index}> | ||
<span>{dayjs(weather.time).format('dddd')}</span> | ||
<img | ||
src={getWeatherIcon(weather.weather_code.toString())} | ||
alt={`${city}-weather-icon-${weather.weather_code}`} | ||
/> | ||
<h3> | ||
{weather.apparent_temperature_max}° | ||
<span className={weatherStyles.unit}>F</span> | ||
</h3> | ||
</div> | ||
); | ||
})} | ||
</> | ||
); | ||
} |
Oops, something went wrong.