From 0ee26e58460f31ac55e13754f335f150538cf52a Mon Sep 17 00:00:00 2001 From: mrg Date: Wed, 16 Aug 2023 16:16:34 +0200 Subject: [PATCH] fix errors after merge --- frontend/src/App.tsx | 2 -- frontend/src/DayView.tsx | 29 ++++++++++++++++------ frontend/src/HomePage.tsx | 29 ++++++---------------- frontend/src/{ => Menubar}/AddActivity.tsx | 0 frontend/src/Menubar/LogoutButton.tsx | 21 ++++++++++++++++ frontend/src/{ => Menubar}/MenuBar.tsx | 6 +++-- frontend/src/{ => Menubar}/WeatherAPI.tsx | 2 +- 7 files changed, 56 insertions(+), 33 deletions(-) rename frontend/src/{ => Menubar}/AddActivity.tsx (100%) create mode 100644 frontend/src/Menubar/LogoutButton.tsx rename frontend/src/{ => Menubar}/MenuBar.tsx (70%) rename frontend/src/{ => Menubar}/WeatherAPI.tsx (99%) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 26f8b8a..f440aee 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -7,7 +7,6 @@ import RegisterPage from "./Register/Register.tsx"; import HomePage from "./HomePage.tsx"; import ProtectedRoute from "./ProtectedRoutes/ProtectedRoute.tsx"; import {useState} from "react"; - import MenuBar from "./MenuBar.tsx"; function App() { @@ -16,7 +15,6 @@ function App() { return ( <> - }/> }/> diff --git a/frontend/src/DayView.tsx b/frontend/src/DayView.tsx index b922af6..d9d1a69 100644 --- a/frontend/src/DayView.tsx +++ b/frontend/src/DayView.tsx @@ -19,9 +19,9 @@ type ActivityDataProps = { dayActivity: Activity } -export default function CurrentDay({ weather }) { +export default function DayView({ weather }) { - const [dayActivities, setDayActivity] = useState<[]>([]); + const [dayActivities, setDayActivity] = useState([]); useEffect(() => { axios({ @@ -58,27 +58,42 @@ export default function CurrentDay({ weather }) { const dayAfterTomorrowWeather = getForecastByDate(new Date(new Date().setDate(new Date().getDate() + 2)).toISOString().split('T')[0]); function isWarm() { - if (weather.current.temp_c >= 25) return true; + if (weather.current.temp_c >= 25) { + return true; + } } function isMiddle() { - if (weather.current.temp_c <= 24 && weather.current.temp_c >= 17) return true; + if (weather.current.temp_c <= 24 && weather.current.temp_c >= 17){ + return true; + } } function isCold() { - if (weather.current.temp_c <= 16) return true; + if (weather.current.temp_c <= 16) { + return true; + } } function isRaining() { - if (weather.current.precip_mm > 0) return true; + if (weather.current.precip_mm > 0) { + return true; + } } const filterAcitivities = dayActivities.filter(activity => + // (activity.possibleWhenRaining === isRaining() || !isRaining()) && + (activity.possibleWhenWarm === isWarm()) && + (activity.possibleWhenMiddle === isMiddle()) && + (activity.possibleWhenCold === isCold()) + ); + +/* const filterAcitivities = dayActivities.filter(activity => (activity.possibleWhenRaining || !isRaining()) && (activity.possibleWhenWarm || !isWarm()) && (activity.possibleWhenMiddle || !isMiddle()) && (activity.possibleWhenCold || !isCold()) - ); + );*/ return (
diff --git a/frontend/src/HomePage.tsx b/frontend/src/HomePage.tsx index 71c416f..86bde28 100644 --- a/frontend/src/HomePage.tsx +++ b/frontend/src/HomePage.tsx @@ -1,9 +1,8 @@ -import WeatherData from "./WeatherAPI.tsx"; -import AddActivity from "./AddActivity.tsx"; -import CurrentDay from "./DayView.tsx"; -import {FormEvent, useEffect, useState} from "react"; + +import DayView from "./DayView.tsx"; +import {useEffect, useState} from "react"; import axios from "axios"; -import {useNavigate} from "react-router-dom"; +import MenuBar from "./Menubar/MenuBar.tsx"; export default function HomePage(){ @@ -19,23 +18,11 @@ export default function HomePage(){ }); }, []); - const nav = useNavigate(); - function logout(event:FormEvent){ - event.preventDefault() - axios.post("/api/user/logout") - .then((response) => console.log(response.data)) - .then(()=>nav("/")) - .catch((error) => console.log(error)) - } return ( -
-
- -
- - - -
+ <> + + + ) } \ No newline at end of file diff --git a/frontend/src/AddActivity.tsx b/frontend/src/Menubar/AddActivity.tsx similarity index 100% rename from frontend/src/AddActivity.tsx rename to frontend/src/Menubar/AddActivity.tsx diff --git a/frontend/src/Menubar/LogoutButton.tsx b/frontend/src/Menubar/LogoutButton.tsx new file mode 100644 index 0000000..b6f81cd --- /dev/null +++ b/frontend/src/Menubar/LogoutButton.tsx @@ -0,0 +1,21 @@ +import {useNavigate} from "react-router-dom"; +import {FormEvent} from "react"; +import axios from "axios"; + + +export default function LogoutButton() { + const nav = useNavigate(); + function logout(event:FormEvent){ + event.preventDefault() + axios.post("/api/user/logout") + .then((response) => console.log(response.data)) + .then(()=>nav("/")) + .catch((error) => console.log(error)) + } + + return( +
+ +
+ ); +} \ No newline at end of file diff --git a/frontend/src/MenuBar.tsx b/frontend/src/Menubar/MenuBar.tsx similarity index 70% rename from frontend/src/MenuBar.tsx rename to frontend/src/Menubar/MenuBar.tsx index 393c7b9..915266e 100644 --- a/frontend/src/MenuBar.tsx +++ b/frontend/src/Menubar/MenuBar.tsx @@ -1,6 +1,7 @@ import WeatherApi from "./WeatherAPI.tsx"; import AddActivity from "./AddActivity.tsx"; import {Box} from '@mui/material'; +import LogoutButton from "./LogoutButton.tsx"; const styles = { menubar: { @@ -11,8 +12,9 @@ const styles = { export default function MenuBar() { return - - + + + } \ No newline at end of file diff --git a/frontend/src/WeatherAPI.tsx b/frontend/src/Menubar/WeatherAPI.tsx similarity index 99% rename from frontend/src/WeatherAPI.tsx rename to frontend/src/Menubar/WeatherAPI.tsx index eb2ccee..55872ea 100644 --- a/frontend/src/WeatherAPI.tsx +++ b/frontend/src/Menubar/WeatherAPI.tsx @@ -3027,7 +3027,7 @@ export default function WeatherApi() { useEffect(() => { axios({ - url: "https://api.weatherapi.com/v1/forecast.json?key=6cc628764c7547e298d143025230108&q=Bielefeld&days=3&aqi=yes&alerts=yes", + url: "https://api.weatherapi.com/v1/forecast.json?key=6cc628764c7547e298d143025230108&q=Nordpol&days=3&aqi=yes&alerts=yes", method: "get" }).then(function (response) { setWeather(response.data);