Skip to content

Commit

Permalink
Merge pull request #28 from MarvinBo44/dayViewTomorrow
Browse files Browse the repository at this point in the history
Day view tomorrow
  • Loading branch information
StefanZuehlsdorf committed Aug 22, 2023
2 parents 79fbbbd + 78e6163 commit 425da77
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 27 deletions.
117 changes: 90 additions & 27 deletions frontend/src/DayView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,66 +23,129 @@ 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);
}

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;
}
}
}

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;
}
}
}

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 ? <div>loading...</div> : (
<div className={"flex-container"}>
Expand All @@ -92,7 +155,7 @@ export default function DayView(props: WeatherProps) {
{/*<h2>{getCurrentDate()}</h2>*/}
<h2>Heute</h2>
<div className={"activityBox"}>
{filterAcitivities.map(daily =>
{filterAcitivitiesToday.map(daily =>
<ActivityCard key={daily.id} dayActivity={daily} />
)}
</div>
Expand All @@ -105,7 +168,7 @@ export default function DayView(props: WeatherProps) {
{/*<h2>{tomorrowWeather.date}</h2>*/}
<h2>Morgen</h2>
<div className={"activityBox"}>
{filterAcitivities.map(daily =>
{filterAcitivitiesTomorrow.map(daily =>
<ActivityCard key={daily.id} dayActivity={daily} />
)}
</div>
Expand All @@ -118,7 +181,7 @@ export default function DayView(props: WeatherProps) {
{/*<h2>{dayAfterTomorrowWeather.date}</h2>*/}
<h2>Übermorgen</h2>
<div className={"activityBox"}>
{filterAcitivities.map(daily =>
{filterAcitivitiesDayAfterTomorrow.map(daily =>
<ActivityCard key={daily.id} dayActivity={daily} />
)}
</div>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/Menubar/AddActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export default function AddActivity(props: SetDayActivity) {
);
}



return <>
<Button size={"small"}
color={"info"}
Expand Down

0 comments on commit 425da77

Please sign in to comment.