-
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.
Add WeatherCards component for daily forecast
- Loading branch information
1 parent
6ef8b13
commit d3cc921
Showing
17 changed files
with
213 additions
and
23 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
...components/chart/ForecastDaysSelector.tsx → src/components/ForecastDaysSelector.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react'; | ||
import { DailyWeatherData } from '../../domain/types/WeatherData'; | ||
import Typography from '@mui/material/Typography'; | ||
import { Box } from '@mui/system'; | ||
import { Theme, Grid } from '@mui/material'; | ||
import { weatherCodeToIcon } from '../../utils/weatherIconMapping'; | ||
|
||
export const WeatherCards: React.FC<{ forecastData: DailyWeatherData[]; palette: Theme['palette'] }> = ({ forecastData, palette }) => { | ||
const formatDate = (dateString: string): string => { | ||
const date = new Date(dateString); | ||
const options: Intl.DateTimeFormatOptions = { day: 'numeric', month: 'short' }; | ||
return date.toLocaleDateString('en-EN', options); | ||
}; | ||
|
||
const formatSunshineDuration = (seconds: number) => { | ||
const hours = seconds / 3600; | ||
return hours.toFixed(2); | ||
}; | ||
|
||
return ( | ||
<Box mt={3} sx={{ overflowX: 'auto', display: 'flex', justifyContent: 'space-around', '&::-webkit-scrollbar': { display: 'none' }}}> | ||
<Grid container pb={1} spacing={0} sx={{ width: 'auto', flexWrap: 'nowrap', justifyContent: 'stretch', height: 220 }}> | ||
{forecastData.map((forecast, index) => { | ||
const { Icon, color } = weatherCodeToIcon(forecast.weatherCode, palette.icon); | ||
return ( | ||
<Grid item key={index} sx={{ minWidth: 160, flexShrink: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'left', borderLeft: '1px solid', borderColor: palette.background.box }}> | ||
<Box sx={{ display: 'flex', alignItems: 'left', justifyContent: 'stretch', textAlign: 'left', p: 1, backgroundColor: palette.background.box, borderRadius: 2 }}> | ||
<Icon size={56} color={color} /> | ||
<Typography variant="subtitle2" sx={{ mb: 1, ml: 1 }}> | ||
{formatDate(forecast.timestamp)} | ||
</Typography> | ||
</Box> | ||
<Box pl={2}> | ||
<Typography variant="h6" sx={{ mt: 1 }}> | ||
{forecast.temperatureMax}°C / {forecast.temperatureMin}°C | ||
</Typography> | ||
<Typography variant="subtitle1"> | ||
{forecast.precipitationProbability}% rain | ||
</Typography> | ||
<Typography variant="body2"> | ||
<Typography variant="caption">Wind: </Typography> | ||
{forecast.windSpeed} km/h | ||
</Typography> | ||
<Typography variant="body2"> | ||
<Typography variant="caption">Sunshine: </Typography> | ||
{formatSunshineDuration(forecast.sunshineDuration)} hrs | ||
</Typography> | ||
<Typography variant="body2"> | ||
<Typography variant="caption">Precip: </Typography> | ||
{forecast.precipitation} mm | ||
</Typography> | ||
</Box> | ||
</Grid> | ||
); | ||
})} | ||
</Grid> | ||
</Box> | ||
); | ||
}; |
10 changes: 5 additions & 5 deletions
10
src/components/chart/WeatherChart.tsx → src/components/hourly/WeatherChart.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
export enum ForecastModeEnum { | ||
DAILY = 'daily', | ||
HOURLY = 'hourly', | ||
} | ||
|
||
export type WidgetProps = { | ||
theme: string; | ||
mode: ForecastModeEnum; | ||
} |
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
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,48 @@ | ||
import { IconType } from 'react-icons'; | ||
import { WiDaySunny, WiDayCloudy, WiCloud, WiFog, WiSprinkle, WiRain, WiRainMix, WiSnow, WiSnowflakeCold, WiThunderstorm } from 'react-icons/wi'; | ||
|
||
type ColorPalette = { | ||
sun: string; | ||
rain: string; | ||
cloud: string; | ||
snow: string; | ||
} | ||
|
||
type WeatherIcon = { | ||
Icon: IconType; | ||
color: string; | ||
} | ||
|
||
export const weatherCodeToIcon = (code: number, color_palette: ColorPalette): WeatherIcon => { | ||
switch (code) { | ||
case 0: return { Icon: WiDaySunny, color: color_palette.sun }; | ||
case 1: | ||
case 2: | ||
case 3: return { Icon: WiDayCloudy, color: color_palette.sun }; | ||
case 45: | ||
case 48: return { Icon: WiFog, color: color_palette.cloud }; | ||
case 51: | ||
case 53: | ||
case 55: return { Icon: WiSprinkle, color: color_palette.rain }; | ||
case 56: | ||
case 57: return { Icon: WiRainMix, color: color_palette.rain }; // Freezing Drizzle | ||
case 61: | ||
case 63: | ||
case 65: return { Icon: WiRain, color: color_palette.rain }; // Rain | ||
case 66: | ||
case 67: return { Icon: WiRainMix, color: color_palette.rain }; // Freezing Rain | ||
case 71: | ||
case 73: | ||
case 75: return { Icon: WiSnow, color: color_palette.snow }; | ||
case 77: return { Icon: WiSnowflakeCold, color: color_palette.snow }; | ||
case 80: | ||
case 81: | ||
case 82: return { Icon: WiRain, color: color_palette.rain }; | ||
case 85: | ||
case 86: return { Icon: WiSnow, color: color_palette.snow }; | ||
case 95: | ||
case 96: | ||
case 99: return { Icon: WiThunderstorm, color: color_palette.rain }; | ||
default: return { Icon: WiCloud, color: color_palette.cloud }; | ||
} | ||
}; |