This repository has been archived by the owner on Dec 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
110 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,159 +1,126 @@ | ||
import { BrowserRouter as Router, Link, Route, Routes } from "react-router-dom"; | ||
import Inventory from "../Inventory.tsx"; | ||
import Settings from "../Settings.tsx"; | ||
import Friends from "../Friends.tsx"; | ||
import PetPage from "../PetPage.tsx"; | ||
import { useAuth } from "react-oidc-context"; | ||
import "./navbar.css"; | ||
import { useState } from "react"; | ||
|
||
const Navbar = () => { | ||
const auth = useAuth(); | ||
const [activePage, setActivePage] = useState("Pet Page"); | ||
const auth = useAuth(); | ||
const [activePage, setActivePage] = useState("Pet Page"); | ||
|
||
const loginButtonStyles = { | ||
color: "#fff", | ||
backgroundColor: "#006400", | ||
fontWeight: "bold", | ||
}; | ||
const loginButtonStyles = { | ||
color: "#fff", | ||
backgroundColor: "#006400", | ||
fontWeight: "bold", | ||
}; | ||
|
||
const navbarItemStyles = { | ||
marginRight: "20px", | ||
}; | ||
const navbarItemStyles = { | ||
marginRight: "20px", | ||
}; | ||
|
||
const handlePageClick = (page: string) => { | ||
setActivePage(page); | ||
}; | ||
const handlePageClick = (page: string) => { | ||
setActivePage(page); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Router> | ||
<nav className="navbar navbar-expand-lg navbar-dark bg-success"> | ||
<img | ||
src={"./android-chrome-192x192.png"} | ||
alt="Logo" | ||
style={{ width: "30px", height: "30px", marginLeft: "5px" }} | ||
/> | ||
<a className="navbar-brand px-2" href="#"> | ||
TEAMAGOCHI | ||
</a> | ||
<button | ||
className="navbar-toggler" | ||
type="button" | ||
data-toggle="collapse" | ||
data-target="#navbarSupportedContent" | ||
aria-controls="navbarSupportedContent" | ||
aria-expanded="false" | ||
aria-label="Toggle navigation" | ||
> | ||
<span className="navbar-toggler-icon"></span> | ||
</button> | ||
|
||
<div | ||
className="collapse navbar-collapse flex-row-reverse" | ||
id="navbarSupportedContent" | ||
style={navbarItemStyles} | ||
> | ||
<ul className="navbar-nav"> | ||
{auth.isAuthenticated ? ( | ||
<> | ||
<li | ||
className={`nav-item ${ | ||
activePage === "Pet Page" ? "active" : "" | ||
}`} | ||
> | ||
<Link | ||
className="nav-link" | ||
to="/PetPage" | ||
style={navbarItemStyles} | ||
onClick={() => handlePageClick("Pet Page")} | ||
> | ||
Pet Page | ||
</Link> | ||
</li> | ||
<li | ||
className={`nav-item ${ | ||
activePage === "Inventory" ? "active" : "" | ||
}`} | ||
> | ||
<Link | ||
className="nav-link" | ||
to="/inventory" | ||
style={navbarItemStyles} | ||
onClick={() => handlePageClick("Inventory")} | ||
> | ||
Inventory | ||
</Link> | ||
</li> | ||
<li | ||
className={`nav-item ${ | ||
activePage === "Friends" ? "active" : "" | ||
}`} | ||
> | ||
<Link | ||
className="nav-link" | ||
to="/Friends" | ||
style={navbarItemStyles} | ||
onClick={() => handlePageClick("Friends")} | ||
return ( | ||
<div> | ||
<Router> | ||
<nav className="navbar navbar-expand-lg navbar-dark bg-success"> | ||
<img | ||
src={"./android-chrome-192x192.png"} | ||
alt="Logo" | ||
style={{ width: "30px", height: "30px", marginLeft: "5px" }} | ||
/> | ||
<a className="navbar-brand px-2" href="#"> | ||
TEAMAGOCHI | ||
</a> | ||
<button | ||
className="navbar-toggler" | ||
type="button" | ||
data-toggle="collapse" | ||
data-target="#navbarSupportedContent" | ||
aria-controls="navbarSupportedContent" | ||
aria-expanded="false" | ||
aria-label="Toggle navigation" | ||
> | ||
Friends | ||
</Link> | ||
</li> | ||
<li | ||
className={`nav-item ${ | ||
activePage === "Settings" ? "active" : "" | ||
}`} | ||
> | ||
<Link | ||
className="nav-link" | ||
to="/Settings" | ||
style={navbarItemStyles} | ||
onClick={() => handlePageClick("Settings")} | ||
> | ||
Settings | ||
</Link> | ||
</li> | ||
<li className="navbar-item"> | ||
<Link | ||
className="nav-link" | ||
onClick={() => auth.removeUser()} | ||
to="/LandingPage" | ||
style={loginButtonStyles} | ||
<span className="navbar-toggler-icon"></span> | ||
</button> | ||
|
||
<div | ||
className="collapse navbar-collapse flex-row-reverse" | ||
id="navbarSupportedContent" | ||
style={navbarItemStyles} | ||
> | ||
Log out | ||
</Link> | ||
</li> | ||
</> | ||
) : ( | ||
<li className="navbar-item"> | ||
<a | ||
className="nav-link" | ||
href="#" | ||
onClick={() => auth.signinRedirect()} | ||
style={loginButtonStyles} | ||
> | ||
Log in | ||
</a> | ||
</li> | ||
)} | ||
</ul> | ||
</div> | ||
</nav> | ||
<Routes> | ||
<Route path="/inventory" element={<Inventory />} /> | ||
<Route | ||
path="/Settings" | ||
element={ | ||
<Settings | ||
username={auth.user?.profile?.preferred_username || "User"} | ||
/> | ||
} | ||
/> | ||
<Route path="/Friends" element={<Friends />} /> | ||
<Route path="/PetPage" element={<PetPage />} /> | ||
</Routes> | ||
</Router> | ||
</div> | ||
); | ||
<ul className="navbar-nav"> | ||
{auth.isAuthenticated ? ( | ||
<> | ||
<li | ||
className={`nav-item ${activePage === "Pet Page" ? "active" : "" | ||
}`} | ||
> | ||
<Link | ||
className="nav-link" | ||
to="/PetPage" | ||
style={navbarItemStyles} | ||
onClick={() => handlePageClick("Pet Page")} | ||
> | ||
Pet Page | ||
</Link> | ||
</li> | ||
<li | ||
className={`nav-item ${activePage === "Settings" ? "active" : "" | ||
}`} | ||
> | ||
<Link | ||
className="nav-link" | ||
to="/Settings" | ||
style={navbarItemStyles} | ||
onClick={() => handlePageClick("Settings")} | ||
> | ||
Settings | ||
</Link> | ||
</li> | ||
<li className="navbar-item"> | ||
<Link | ||
className="nav-link" | ||
onClick={() => auth.removeUser()} | ||
to="/LandingPage" | ||
style={loginButtonStyles} | ||
> | ||
Log out | ||
</Link> | ||
</li> | ||
</> | ||
) : ( | ||
<li className="navbar-item"> | ||
<a | ||
className="nav-link" | ||
href="#" | ||
onClick={() => auth.signinRedirect()} | ||
style={loginButtonStyles} | ||
> | ||
Log in | ||
</a> | ||
</li> | ||
)} | ||
</ul> | ||
</div> | ||
</nav> | ||
<Routes> | ||
<Route | ||
path="/Settings" | ||
element={ | ||
<Settings | ||
username={auth.user?.profile?.preferred_username || "User"} | ||
/> | ||
} | ||
/> | ||
|
||
<Route path="/PetPage" element={<PetPage />} /> | ||
</Routes> | ||
</Router> | ||
</div> | ||
); | ||
}; | ||
export default Navbar; |