Skip to content

Commit d84d476

Browse files
committed
chore: refactor the account dropdown
1 parent 1dec307 commit d84d476

File tree

4 files changed

+51
-20
lines changed

4 files changed

+51
-20
lines changed

src/app/page.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export default async function Home() {
22
return (
33
<>
4-
<main className="flex min-h-screen flex-col items-center justify-between p-24"></main>
4+
<main className="flex min-h-screen flex-col items-center justify-between p-24">
5+
Welcome to CodeRacer! We will work on this landing page soon
6+
</main>
57
</>
68
);
79
}

src/components/footer.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import * as React from "react";
2-
32
import { cn } from "@/lib/utils";
4-
import { ModeToggle } from "@/components/mode-toggle";
53
import Link from "next/link";
64
import Image from "next/image";
75

@@ -41,7 +39,6 @@ export function Footer({ className }: React.HTMLAttributes<HTMLElement>) {
4139
.
4240
</p>
4341
</div>
44-
<ModeToggle />
4542
</div>
4643
</footer>
4744
);

src/components/header.tsx

+40-15
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,52 @@
33
import Image from "next/image";
44
import Link from "next/link";
55
import React, { useState } from "react";
6+
import { Button } from "@/components/ui/button";
7+
import {
8+
DropdownMenu,
9+
DropdownMenuContent,
10+
DropdownMenuItem,
11+
DropdownMenuTrigger,
12+
} from "@/components/ui/dropdown-menu";
13+
import { Icons } from "@/components/icons";
14+
import { SessionProvider, signOut, useSession } from "next-auth/react";
15+
import { LoginButton } from "./ui/buttons";
16+
import { ModeToggle } from "./mode-toggle";
617

7-
import { Button } from "./ui/button";
8-
import { SessionProvider, useSession } from "next-auth/react";
9-
import { LoginButton, LogoutButton } from "./ui/buttons";
18+
const AccountMenu = () => {
19+
const session = useSession();
20+
21+
return (
22+
<DropdownMenu>
23+
<DropdownMenuTrigger asChild>
24+
<Button variant="ghost" className="px-2 py-4 flex gap-4 items-center">
25+
<Image
26+
className="rounded-full"
27+
src={session?.data?.user.image ?? ""}
28+
alt="user avatar"
29+
height={30}
30+
width={30}
31+
/>
32+
<p className="text-gray-700 font-bold">{session?.data?.user?.name}</p>
33+
</Button>
34+
</DropdownMenuTrigger>
35+
<DropdownMenuContent align="end">
36+
<DropdownMenuItem onClick={() => signOut()}>
37+
<Icons.logout className="mr-2 h-4 w-4" />
38+
<span>Logout</span>
39+
</DropdownMenuItem>
40+
</DropdownMenuContent>
41+
</DropdownMenu>
42+
);
43+
};
1044

1145
const Header = () => {
1246
const [state, setState] = useState(false);
1347

1448
const navigation = [
1549
{ title: "Race", path: "/race" },
1650
{ title: "Leaderboard", path: "/" },
17-
{ title: "About", path: "/" },
51+
// { title: "About", path: "/about" },
1852
];
1953

2054
const session = useSession();
@@ -91,19 +125,10 @@ const Header = () => {
91125
<LoginButton />
92126
) : (
93127
<>
94-
<Image
95-
className="rounded-full"
96-
src={session?.data.user.image ?? ""}
97-
alt="user avatar"
98-
height={40}
99-
width={40}
100-
/>
101-
<p className="text-gray-700 font-bold">
102-
{session?.data.user?.name}
103-
</p>
104-
<LogoutButton />
128+
<AccountMenu />
105129
</>
106130
)}
131+
<ModeToggle />
107132
</div>
108133
</div>
109134
</nav>

src/components/icons.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
import { Laptop, Moon, SunMedium, type Icon as LucideIcon } from "lucide-react";
1+
import {
2+
Laptop,
3+
Moon,
4+
SunMedium,
5+
type Icon as LucideIcon,
6+
LogOut,
7+
} from "lucide-react";
28

39
export type Icon = LucideIcon;
410

511
export const Icons = {
612
sun: SunMedium,
713
moon: Moon,
814
laptop: Laptop,
15+
logout: LogOut,
916
};

0 commit comments

Comments
 (0)