source: frontend/src/pages/LandingPage/components/NavbarLanding.jsx@ b3d5fed

Last change on this file since b3d5fed was ff01f66, checked in by Andrej <asumanovski@…>, 5 months ago

Fixed landing page

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[3ebe47c]1import React, { useEffect, useState } from "react";
2import { Link, useNavigate } from "react-router-dom";
[793ce2c]3import logo from "../../../assets/logo.png";
4
5const NavbarLanding = () => {
[3ebe47c]6 const navigate = useNavigate();
7 const [isAuthed, setIsAuthed] = useState(() =>
8 Boolean(localStorage.getItem("authToken")),
9 );
10
11 useEffect(() => {
12 const onStorage = (e) => {
13 if (e.key === "authToken") {
14 setIsAuthed(Boolean(e.newValue));
15 }
16 };
17 window.addEventListener("storage", onStorage);
18 return () => window.removeEventListener("storage", onStorage);
19 }, []);
20
21 const onLogout = () => {
22 localStorage.removeItem("authToken");
23 localStorage.removeItem("authUser");
24 setIsAuthed(false);
25 navigate("/", { replace: true });
26 };
27
[793ce2c]28 return (
[ff01f66]29 <div className="navbar bg-primary text-primary-content shadow-sm">
[793ce2c]30 <div className="navbar-start">
[ff01f66]31 <Link
32 className="btn btn-ghost text-primary-content"
33 aria-label="Trekr home"
34 to="/"
35 >
[793ce2c]36 <img src={logo} alt="Trekr" className="h-12 w-auto rounded-2xl" />
[3ebe47c]37 </Link>
[793ce2c]38 </div>
39 <div className="navbar-end">
[3ebe47c]40 {isAuthed ? (
41 <div className="flex items-center gap-2 mr-6">
[ff01f66]42 <Link
43 className="btn btn-outline border-primary-content text-primary-content"
44 to="/dashboard"
45 >
[3ebe47c]46 Dashboard
47 </Link>
[ff01f66]48 <button
49 className="btn btn-outline border-primary-content text-primary-content"
50 onClick={onLogout}
51 >
[3ebe47c]52 Logout
53 </button>
54 </div>
55 ) : (
56 <Link
[ff01f66]57 className="btn btn-tertiary text-blue-200! px-8 mr-6"
[3ebe47c]58 to="/login"
59 >
60 Start Tracking
61 </Link>
62 )}
[793ce2c]63 </div>
64 </div>
65 );
66};
67
68export default NavbarLanding;
Note: See TracBrowser for help on using the repository browser.