Skip to content

Commit

Permalink
Fields are reseted after creation of a movie
Browse files Browse the repository at this point in the history
  • Loading branch information
Krisssssssssssssssssssssss committed Oct 25, 2024
1 parent b1aad52 commit 29bd3a4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
10 changes: 7 additions & 3 deletions backend/src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<script type="module" crossorigin src="/assets/index-f40OySzR.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-DiwrgTda.css">
<script
src="https://kit.fontawesome.com/9d18197c84.js"
crossorigin="anonymous"
></script>
<title>Movie Library</title>
<script type="module" crossorigin src="/assets/index-2Ve-UDLH.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-I2B_RJ5A.css">
</head>
<body>
<div id="root"></div>
Expand Down
61 changes: 32 additions & 29 deletions frontend/src/Component/App/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import axios from "axios";
import {useEffect, useState} from "react";
import {Link} from "react-router-dom";
import {Link, useNavigate} from "react-router-dom";

export default function Header() {
const navigate = useNavigate();

const [isLoggedIn, setIsLoggedIn] = useState(false);
const [userName, setUserName] = useState('');

Expand All @@ -22,34 +24,35 @@ export default function Header() {
setIsLoggedIn(false);
})
}

const logout = () => {
const host = window.location.host === 'localhost:5173' ? 'http://localhost:8080' : window.location.origin
window.open(host + "/api/auth/logout", '_self');
};
const handleButtonClick = () => {
if (isLoggedIn) {
logout();
} else {
login();
}
};
axios.post(`/api/auth/logout`, {}).then(() => {
navigate("/")
})};
const handleButtonClick = () => {
if (isLoggedIn) {
logout();
} else {
login();
}
};

useEffect(() => {
loadUser()
}, []);
useEffect(() => {
loadUser()
}, []);

return (
<nav>
<Link to="/" className="navbar-title">
<i className="fa-duotone fa-solid fa-video"></i>
<h1>Movie Library</h1>
</Link>
<div className={"navbar-user"}>
<p>Hello {userName}</p>
<button onClick={handleButtonClick}>
{isLoggedIn ? 'Logout' : 'Login'}
</button>
</div>
</nav>
);
}
return (
<nav>
<Link to="/" className="navbar-title">
<i className="fa-duotone fa-solid fa-video"></i>
<h1>Movie Library</h1>
</Link>
<div className={"navbar-user"}>
<p>Hello {userName}</p>
<button onClick={handleButtonClick}>
{isLoggedIn ? 'Logout' : 'Login'}
</button>
</div>
</nav>
);
}
2 changes: 1 addition & 1 deletion frontend/tsconfig.app.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"root":["./src/app.tsx","./src/main.tsx","./src/vite-env.d.ts"],"version":"5.6.3"}
{"root":["./src/main.tsx","./src/vite-env.d.ts","./src/component/app.tsx","./src/component/protectedroutes.tsx","./src/component/app/details.tsx","./src/component/app/editmovieform.tsx","./src/component/app/footer.tsx","./src/component/app/header.tsx","./src/component/app/main.tsx","./src/component/app/details/moviecontrols.tsx","./src/component/app/details/moviedetails.tsx","./src/component/app/details/moviedetails/personlist.tsx","./src/component/app/details/moviedetails/personlist/person.tsx","./src/component/app/main/createbutton.tsx","./src/component/app/main/listheaders.tsx","./src/component/app/main/watchedtab.tsx","./src/component/app/main/wishlisttab.tsx","./src/component/app/main/tab/movielist/listelement.tsx","./src/component/app/main/tab/movielist/watchedlist.tsx","./src/component/app/main/tab/movielist/wishlist.tsx","./src/hooks/usefetch.ts","./src/type/movieratingtype.tsx","./src/type/movietype.tsx","./src/type/persontype.tsx","./src/type/ratingtype.tsx"],"version":"5.6.3"}

0 comments on commit 29bd3a4

Please sign in to comment.