Skip to content

Commit

Permalink
Merge pull request #21 from MarvinBo44/iHopeSo
Browse files Browse the repository at this point in the history
fix errors after merge
  • Loading branch information
MarvinBo44 authored Aug 16, 2023
2 parents 504b13c + 0ee26e5 commit 7c7a14e
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 33 deletions.
2 changes: 0 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -16,7 +15,6 @@ function App() {

return (
<>
<MenuBar/>
<Routes>
<Route path={"/"} element={<LoginPage setUser={setUser}/>}/>
<Route path={"/register"} element={<RegisterPage/>}/>
Expand Down
29 changes: 22 additions & 7 deletions frontend/src/DayView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Activity[]>([]);

useEffect(() => {
axios({
Expand Down Expand Up @@ -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 (
<div className={"flex-container"}>
Expand Down
29 changes: 8 additions & 21 deletions frontend/src/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -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(){

Expand All @@ -19,23 +18,11 @@ export default function HomePage(){
});
}, []);

const nav = useNavigate();
function logout(event:FormEvent<HTMLFormElement>){
event.preventDefault()
axios.post("/api/user/logout")
.then((response) => console.log(response.data))
.then(()=>nav("/"))
.catch((error) => console.log(error))
}

return (
<div>
<form onSubmit={logout}>
<button>logout</button>
</form>
<WeatherData weather={weather}/>
<AddActivity/>
<CurrentDay weather={weather}/>
</div>
<>
<MenuBar/>
<DayView weather={weather}/>
</>
)
}
File renamed without changes.
21 changes: 21 additions & 0 deletions frontend/src/Menubar/LogoutButton.tsx
Original file line number Diff line number Diff line change
@@ -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<HTMLFormElement>){
event.preventDefault()
axios.post("/api/user/logout")
.then((response) => console.log(response.data))
.then(()=>nav("/"))
.catch((error) => console.log(error))
}

return(
<form onSubmit={logout}>
<button>logout</button>
</form>
);
}
6 changes: 4 additions & 2 deletions frontend/src/MenuBar.tsx → frontend/src/Menubar/MenuBar.tsx
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -11,8 +12,9 @@ const styles = {
export default function MenuBar() {
return <Box>
<Box style={styles.menubar}>
<WeatherApi></WeatherApi>
<AddActivity></AddActivity>
<WeatherApi/>
<AddActivity/>
<LogoutButton/>
</Box>
</Box>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7c7a14e

Please sign in to comment.