Skip to content

Commit

Permalink
fix: filterActivities
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinBo44 committed Aug 22, 2023
1 parent 6601cea commit 78e6163
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions frontend/src/DayView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ export default function DayView(props: WeatherProps) {
}
function isMiddleTomorrow() {
if (props.weather != undefined) {
if (props.weather.forecast.forecastday[1].day.maxtemp_c >= 10 && props.weather.forecast.forecastday[0].day.maxtemp_c <= 24) {
if (props.weather.forecast.forecastday[1].day.maxtemp_c >= 10 && props.weather.forecast.forecastday[1].day.maxtemp_c <= 24) {
return true;
}
}
}

function isMiddleDayAfterTomorrow() {
if (props.weather != undefined) {
if (props.weather.forecast.forecastday[2].day.maxtemp_c >= 10 && props.weather.forecast.forecastday[1].day.maxtemp_c <= 24) {
if (props.weather.forecast.forecastday[2].day.maxtemp_c >= 10 && props.weather.forecast.forecastday[2].day.maxtemp_c <= 24) {
return true;
}
}
Expand Down Expand Up @@ -111,40 +111,41 @@ export default function DayView(props: WeatherProps) {
}
function isRainingTomorrow() {
if (props.weather != undefined) {
if (props.weather.forecast.forecastday[1].day.daily_will_it_rain > 0) {
if (props.weather.forecast.forecastday[1].day.daily_chance_of_rain > 0) {
return true;
}
}
}

function isRainingDayAfterTomorrow() {
if (props.weather != undefined) {
if (props.weather.forecast.forecastday[2].day.daily_will_it_rain > 0) {
if (props.weather.forecast.forecastday[2].day.daily_chance_of_rain > 0) {
return true;
}
}
}

const filterAcitivitiesToday = props.dayActivities.filter((activity) =>{
return (activity.possibleWhenWarm === isWarmToday() ||
activity.possibleWhenMiddle === isMiddleToday() ||
activity.possibleWhenCold === isColdToday()) &&
(activity.possibleWhenRaining ? true : activity.possibleWhenRaining === !isRainingToday)
});

const filterAcitivitiesTomorrow = props.dayActivities.filter((activity) =>{
return (activity.possibleWhenWarm === isWarmTomorrow() ||
activity.possibleWhenMiddle === isMiddleTomorrow() ||
activity.possibleWhenCold === isColdTomorrow()) &&
(activity.possibleWhenRaining ? true : activity.possibleWhenRaining === !isRainingTomorrow())
});

const filterAcitivitiesDayAfterTomorrow = props.dayActivities.filter((activity) =>{
return (activity.possibleWhenWarm === isWarmDayAfterTomorrow() ||
activity.possibleWhenMiddle === isMiddleDayAfterTomorrow() ||
activity.possibleWhenCold === isColdDayAfterTomorrow()) &&
(activity.possibleWhenRaining ? true : activity.possibleWhenRaining === !isRainingDayAfterTomorrow())
});
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())
);


return props.weather === undefined ? <div>loading...</div> : (
<div className={"flex-container"}>
Expand Down

0 comments on commit 78e6163

Please sign in to comment.