diff --git a/frontend/src/DayView.tsx b/frontend/src/DayView.tsx index 3d921dc..0ac188b 100644 --- a/frontend/src/DayView.tsx +++ b/frontend/src/DayView.tsx @@ -23,14 +23,6 @@ export default function DayView(props: WeatherProps) { ) } - // function getCurrentDate(): string { - // const today = new Date(); - // const year = today.getFullYear(); - // const month = (today.getMonth() + 1).toString().padStart(2, '0'); - // const day = today.getDate().toString().padStart(2, '0'); - // return `${year}-${month}-${day}`; - // } - function getForecastByDate(date: string) { return props.weather?.forecast?.forecastday?.find(day => day.date === date); } @@ -38,7 +30,7 @@ export default function DayView(props: WeatherProps) { const tomorrowWeather = getForecastByDate(new Date(new Date().setDate(new Date().getDate() + 1)).toISOString().split('T')[0]); const dayAfterTomorrowWeather = getForecastByDate(new Date(new Date().setDate(new Date().getDate() + 2)).toISOString().split('T')[0]); - function isWarm() { + function isWarmToday() { if (props.weather != undefined) { if (props.weather.current.temp_c >= 25) { return true; @@ -46,15 +38,46 @@ export default function DayView(props: WeatherProps) { } } - function isMiddle() { + function isWarmTomorrow() { + if (props.weather != undefined) { + if (props.weather.forecast.forecastday[1].day.maxtemp_c >= 25) { + return true; + } + } + } + + function isWarmDayAfterTomorrow() { + if (props.weather != undefined) { + if (props.weather.forecast.forecastday[2].day.maxtemp_c >= 25) { + return true; + } + } + } + + function isMiddleToday() { if (props.weather != undefined) { if (props.weather.current.temp_c >= 10 && props.weather.current.temp_c <= 24) { return true; } } } + function isMiddleTomorrow() { + if (props.weather != undefined) { + if (props.weather.forecast.forecastday[1].day.maxtemp_c >= 10 && props.weather.forecast.forecastday[1].day.maxtemp_c <= 24) { + return true; + } + } + } - function isCold() { + function isMiddleDayAfterTomorrow() { + if (props.weather != undefined) { + if (props.weather.forecast.forecastday[2].day.maxtemp_c >= 10 && props.weather.forecast.forecastday[2].day.maxtemp_c <= 24) { + return true; + } + } + } + + function isColdToday() { if (props.weather != undefined) { if (props.weather.current.temp_c < 10) { return true; @@ -62,27 +85,67 @@ export default function DayView(props: WeatherProps) { } } - function isRaining() { + + function isColdTomorrow() { + if (props.weather != undefined) { + if (props.weather.forecast.forecastday[1].day.maxtemp_c < 10) { + return true; + } + } + } + + function isColdDayAfterTomorrow() { + if (props.weather != undefined) { + if (props.weather.forecast.forecastday[2].day.maxtemp_c < 10) { + return true; + } + } + } + + function isRainingToday() { if (props.weather != undefined) { if (props.weather.current.precip_mm > 0) { return true; } } } + function isRainingTomorrow() { + if (props.weather != undefined) { + if (props.weather.forecast.forecastday[1].day.daily_chance_of_rain > 0) { + return true; + } + } + } - const filterAcitivities = props.dayActivities.filter((activity) =>{ - return (activity.possibleWhenWarm === isWarm() || - activity.possibleWhenMiddle === isMiddle() || - activity.possibleWhenCold === isCold()) && - (activity.possibleWhenRaining ? true : activity.possibleWhenRaining === !isRaining) - }); + function isRainingDayAfterTomorrow() { + if (props.weather != undefined) { + if (props.weather.forecast.forecastday[2].day.daily_chance_of_rain > 0) { + return true; + } + } + } + + const filterAcitivitiesToday = props.dayActivities.filter(activity => + (activity.possibleWhenRaining || !isRainingToday()) && + (activity.possibleWhenWarm || !isWarmToday()) && + (activity.possibleWhenMiddle || !isMiddleToday()) && + (activity.possibleWhenCold || !isColdToday()) + ); + + const filterAcitivitiesTomorrow = props.dayActivities.filter(activity => + (activity.possibleWhenRaining || !isRainingTomorrow()) && + (activity.possibleWhenWarm || !isWarmTomorrow()) && + (activity.possibleWhenMiddle || !isMiddleTomorrow()) && + (activity.possibleWhenCold || !isColdTomorrow()) + ); + + const filterAcitivitiesDayAfterTomorrow = props.dayActivities.filter(activity => + (activity.possibleWhenRaining || !isRainingDayAfterTomorrow()) && + (activity.possibleWhenWarm || !isWarmDayAfterTomorrow()) && + (activity.possibleWhenMiddle || !isMiddleDayAfterTomorrow()) && + (activity.possibleWhenCold || !isColdDayAfterTomorrow()) + ); - // const filterAcitivities = props.dayActivities.filter(activity => - // (activity.possibleWhenRaining || !isRaining()) && - // (activity.possibleWhenWarm || !isWarm()) && - // (activity.possibleWhenMiddle || !isMiddle()) && - // (activity.possibleWhenCold || !isCold()) - // ); return props.weather === undefined ?