|
1 | | -import React from 'react'; |
2 | | -import { Link, useNavigate } from 'react-router-dom'; |
3 | | -import { useAuth } from '../utils/auth'; |
4 | | -import { logout } from '../utils/firebase'; |
5 | | -import { Button } from '@/components/ui/button'; |
| 1 | +import { useEffect, useState } from "react"; |
| 2 | +import { Link, useNavigate } from "react-router-dom"; |
| 3 | +import { useAuth } from "../utils/auth"; |
| 4 | +import { logout } from "../utils/firebase"; |
| 5 | +import { Button } from "@/components/ui/button"; |
| 6 | +import { Moon, Sun } from "lucide-react"; |
6 | 7 | import { |
7 | 8 | DropdownMenu, |
8 | 9 | DropdownMenuContent, |
9 | 10 | DropdownMenuItem, |
10 | 11 | DropdownMenuLabel, |
11 | 12 | DropdownMenuSeparator, |
12 | 13 | DropdownMenuTrigger, |
13 | | -} from "@/components/ui/dropdown-menu" |
14 | | -import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar" |
| 14 | +} from "@/components/ui/dropdown-menu"; |
| 15 | +import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar"; |
15 | 16 |
|
16 | 17 | const Navbar: React.FC = () => { |
17 | 18 | const { currentUser } = useAuth(); |
18 | 19 | const navigate = useNavigate(); |
19 | 20 |
|
20 | 21 | const handleLogout = async () => { |
21 | 22 | await logout(); |
22 | | - navigate('/login'); |
| 23 | + navigate("/login"); |
23 | 24 | }; |
| 25 | + const [isDarkMode, setIsDarkMode] = useState(false); |
| 26 | + const toggleDarkMode = () => { |
| 27 | + setIsDarkMode(!isDarkMode); |
| 28 | + document.documentElement.classList.toggle("dark"); |
| 29 | + }; |
| 30 | + useEffect(() => { |
| 31 | + if ( |
| 32 | + window.matchMedia && |
| 33 | + window.matchMedia("(prefers-color-scheme: dark)").matches |
| 34 | + ) { |
| 35 | + setIsDarkMode(true); |
| 36 | + document.documentElement.classList.add("dark"); |
| 37 | + } |
| 38 | + }, []); |
24 | 39 |
|
25 | 40 | return ( |
26 | 41 | <div className="bg-background border-b"> |
27 | 42 | <div className="container flex h-16 items-center justify-between py-4"> |
28 | | - <Link to="/" className="font-bold text-2xl"> |
29 | | - PurePath |
30 | | - </Link> |
| 43 | + <Link to="/" className="flex items-center space-x-2"> |
| 44 | + <span className="font-bold text-xl tracking-tight text-primary transition-opacity duration-200"> |
| 45 | + Pure<span className="text-foreground">Path</span> |
| 46 | + </span> |
| 47 | + </Link> |
| 48 | + |
31 | 49 | <nav> |
| 50 | + <Button |
| 51 | + variant="ghost" |
| 52 | + size="icon" |
| 53 | + onClick={toggleDarkMode} |
| 54 | + className="ml-4" |
| 55 | + aria-label="Toggle dark mode" |
| 56 | + > |
| 57 | + {isDarkMode ? ( |
| 58 | + <Sun className="h-5 w-5 text-yellow-400" /> |
| 59 | + ) : ( |
| 60 | + <Moon className="h-5 w-5" /> |
| 61 | + )} |
| 62 | + </Button> |
| 63 | + |
32 | 64 | {currentUser ? ( |
33 | 65 | <DropdownMenu> |
34 | 66 | <DropdownMenuTrigger asChild> |
35 | | - <Button variant="ghost" className="relative h-8 w-8 rounded-full"> |
| 67 | + <Button |
| 68 | + variant="ghost" |
| 69 | + className="relative h-8 w-8 rounded-full" |
| 70 | + > |
36 | 71 | <Avatar> |
37 | 72 | <AvatarImage src="/placeholder.svg" alt="User" /> |
38 | | - <AvatarFallback>{currentUser.email?.charAt(0).toUpperCase()}</AvatarFallback> |
| 73 | + <AvatarFallback> |
| 74 | + {currentUser.email?.charAt(0).toUpperCase()} |
| 75 | + </AvatarFallback> |
39 | 76 | </Avatar> |
40 | 77 | </Button> |
41 | 78 | </DropdownMenuTrigger> |
|
0 commit comments