-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathheader.tsx
158 lines (152 loc) · 5.43 KB
/
header.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { ReactNode, forwardRef, ComponentPropsWithoutRef } from "react";
import Link from "next/link";
import PearHeroLogo from "./ui/PearHeroLogo.svg";
import {
NavigationMenu,
NavigationMenuContent,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
NavigationMenuTrigger,
navigationMenuTriggerStyle,
} from "@/components/ui/navigation-menu";
import { cn } from "@/lib/utils";
import DarkModeToggle from "./ui/darkmode-toggle";
import AuthButton from "./ui/authbutton";
import MobileMenu from "./ui/mobile-menu";
import { redirect } from "next/navigation";
import { createClient } from "@/utils/supabase/server";
import DownloadButton from "./ui/downloadbutton";
const NavItem = ({
href,
target = "_self",
children,
}: {
href: string;
target?: React.HTMLAttributeAnchorTarget;
children: ReactNode;
}) => (
<NavigationMenuLink
asChild
className={navigationMenuTriggerStyle()}
href={href}
target={target}
>
<Link href={href}>{children}</Link>
</NavigationMenuLink>
);
const DropdownNavItem = ({
trigger,
children,
}: {
trigger: string;
children: ReactNode;
}) => (
<NavigationMenuItem>
<NavigationMenuTrigger>{trigger}</NavigationMenuTrigger>
<NavigationMenuContent>{children}</NavigationMenuContent>
</NavigationMenuItem>
);
const ListItem = forwardRef<
HTMLAnchorElement,
ComponentPropsWithoutRef<"a"> & { title: string; href: string }
>(({ className, title, children, href, ...props }, ref) => (
<li>
<NavigationMenuLink asChild>
<Link
ref={ref}
href={href}
className={cn(
"block select-none space-y-1 rounded-md p-3 leading-none no-underline outline-none transition-colors hover:bg-secondary-300/10 hover:text-accent-foreground focus:bg-secondary-300/10 focus:text-accent-foreground",
className,
)}
{...props}
>
<div className="text-sm font-medium leading-none">{title}</div>
<p className="line-clamp-2 text-sm leading-snug text-gray-600/90 dark:text-gray-500">
{children}
</p>
</Link>
</NavigationMenuLink>
</li>
));
ListItem.displayName = "ListItem";
export default async function Header() {
const supabase = createClient();
const {
data: { user },
error,
} = await supabase.auth.getUser();
const handleSignOut = async () => {
"use server";
const supabase = createClient();
await supabase.auth.signOut();
redirect("/");
};
return (
<header className="fixed left-0 right-0 top-0 z-50 p-4 transition-all duration-300 ease-in-out">
<div className="mx-auto max-w-[1070px]">
<nav
className="rounded-2xl border-[1.5px] border-gray-200 bg-background px-2 transition-all duration-300 ease-in-out dark:border-gray-50"
aria-label="Main navigation"
>
<div className="flex h-12 items-center justify-between">
<div className="flex items-center">
<Link
href="/"
className="flex flex-shrink-0 items-center"
aria-label="PearAI Home"
>
<PearHeroLogo className="mb-1 h-7" />
<div className="ml-1 text-2xl font-bold">PearAI</div>
</Link>
<nav className="ml-4 hidden md:block" aria-label="Main menu">
<NavigationMenu>
<NavigationMenuList className="text-black/60 dark:text-gray-500">
<DropdownNavItem trigger="Resources">
<ul className="grid w-[400px] gap-3 bg-background p-4 md:w-[500px] md:grid-cols-2 lg:w-[600px]">
<ListItem href="/blog" title="Blog">
Read insights on PearAI's development by our
contributors
</ListItem>
<ListItem href="/faq" title="FAQ">
Frequently asked questions about PearAI
</ListItem>
<ListItem href="/changelog" title="Changelog">
See what's new in PearAI
</ListItem>
<ListItem href="/beta" title="Beta">
Download the latest beta version
</ListItem>
<ListItem href="/docs" title="Documentation">
Learn how to use PearAI effectively
</ListItem>
<ListItem
href="https://github.com/trypear/pearai-master"
title="GitHub"
>
Explore our open source code
</ListItem>
</ul>
</DropdownNavItem>
<NavItem href="/about">About</NavItem>
<NavItem href="/tools">Tools</NavItem>
<NavItem href="/pricing">Pricing</NavItem>
</NavigationMenuList>
</NavigationMenu>
</nav>
</div>
<div className="hidden items-center space-x-4 lg:flex">
<DownloadButton user={user} />
<AuthButton user={user} handleSignOut={handleSignOut} />
<DarkModeToggle />
</div>
<div className="lg:hidden">
<MobileMenu user={user} handleSignOut={handleSignOut} />
</div>
</div>
</nav>
</div>
</header>
);
}