Improved error handling, improved sidebar for mobile

This commit is contained in:
pascalyazid committed 2026-05-15 18:38:58 +02:00
1 parent 167baf9e82
commit 3135131ae4
3 files changed
+247 -95

No files matched your search

+2 -2
View File
@@ -3,10 +3,10 @@
export default function AuthError({ export default function AuthError({
error, error,
reset, reset,
}: { }: Readonly<{
error: Error & { digest?: string }; error: Error & { digest?: string };
reset: () => void; reset: () => void;
}) { }>) {
return ( return (
<div className="flex flex-1 items-center justify-center"> <div className="flex flex-1 items-center justify-center">
<div className="flex flex-col items-center gap-4 text-center"> <div className="flex flex-col items-center gap-4 text-center">
+4 -3
View File
@@ -4,9 +4,9 @@ import { getSignedAvatarUrl } from "@/utils/assets/avatars";
export default async function AuthLayout({ export default async function AuthLayout({
children, children,
}: { }: Readonly<{
children: React.ReactNode; children: React.ReactNode;
}) { }>) {
const supabase = await createClient(); const supabase = await createClient();
const { const {
data: { user }, data: { user },
@@ -37,7 +37,8 @@ export default async function AuthLayout({
email={user?.email ?? ""} email={user?.email ?? ""}
avatarUrl={avatarURL} avatarUrl={avatarURL}
/> />
<main className="flex-1 overflow-y-auto">{children}</main> {/* Mobile: top padding for hamburger button */}
<main className="flex-1 overflow-y-auto pt-12 md:pt-0">{children}</main>
</div> </div>
); );
} }
+241 -90
View File
@@ -1,92 +1,101 @@
"use client"; "use client";
import { cn } from "@/lib/utils";
import { ScrollArea } from "@/components/ui/scroll-area";
import { motion, AnimatePresence } from "framer-motion";
import {
ChevronsUpDown,
LogOut,
MessagesSquare,
UserCircle,
UserPlus,
X,
Menu,
} from "lucide-react";
import Image from "next/image";
import Link from "next/link"; import Link from "next/link";
import { usePathname } from "next/navigation"; import { usePathname } from "next/navigation";
import { useState, useCallback } from "react";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { Separator } from "@/components/ui/separator";
import { signOut } from "@/utils/profile/profile"; import { signOut } from "@/utils/profile/profile";
import Image from "next/image";
const variants = {
open: {
x: 0,
opacity: 1,
transition: { x: { stiffness: 1000, velocity: -100 } },
},
closed: {
x: -20,
opacity: 0,
transition: { x: { stiffness: 100 } },
},
};
const staggerVariants = {
open: {
transition: { staggerChildren: 0.03, delayChildren: 0.02 },
},
};
const navItems = [ const navItems = [
{ {
label: "Rooms", label: "Rooms",
href: "/rooms", href: "/rooms",
icon: ( icon: MessagesSquare,
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth={1.5}
className="size-5"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M7.5 8.25h9m-9 3H12m-9.75 1.51c0 1.6 1.123 2.994 2.707 3.227 1.087.16 2.185.283 3.293.369V21l4.076-4.076a1.526 1.526 0 0 1 1.037-.443 48.282 48.282 0 0 0 5.68-.494c1.584-.233 2.707-1.626 2.707-3.228V6.741c0-1.602-1.123-2.995-2.707-3.228A48.394 48.394 0 0 0 12 3c-2.392 0-4.744.175-7.043.513C3.373 3.746 2.25 5.14 2.25 6.741v6.018Z"
/>
</svg>
),
}, },
{ {
label: "Friends", label: "Friends",
href: "/friends", href: "/friends",
icon: ( icon: UserPlus,
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth={1.5}
className="size-5"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M15 19.128a9.38 9.38 0 0 0 2.625.372 9.337 9.337 0 0 0 4.121-.952 4.125 4.125 0 0 0-7.533-2.493M15 19.128v-.003c0-1.113-.285-2.16-.786-3.07M15 19.128v.106A12.318 12.318 0 0 1 8.624 21c-2.331 0-4.512-.645-6.374-1.766l-.001-.109a6.375 6.375 0 0 1 11.964-3.07M12 6.375a3.375 3.375 0 1 1-6.75 0 3.375 3.375 0 0 1 6.75 0Zm8.25 2.25a2.625 2.625 0 1 1-5.25 0 2.625 2.625 0 0 1 5.25 0Z"
/>
</svg>
),
}, },
{ {
label: "Profile", label: "Profile",
href: "/profile", href: "/profile",
icon: ( icon: UserCircle,
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth={1.5}
className="size-5"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M15.75 6a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0ZM4.501 20.118a7.5 7.5 0 0 1 14.998 0A17.933 17.933 0 0 1 12 21.75c-2.676 0-5.216-.584-7.499-1.632Z"
/>
</svg>
),
}, },
]; ];
export function Sidebar({ function SidebarContent({
isCollapsed,
displayName, displayName,
email, email,
avatarUrl, avatarUrl,
onNavigate,
}: { }: {
isCollapsed: boolean;
displayName: string; displayName: string;
email: string; email: string;
avatarUrl: string; avatarUrl: string;
onNavigate?: () => void;
}) { }) {
const pathname = usePathname(); const pathname = usePathname();
return ( return (
<aside className="flex w-64 flex-col border-r border-neutral-200 bg-white"> <div className="flex h-full flex-col bg-white w-full">
{/* Brand */} {/* Header / brand */}
<div className="flex h-16 items-center gap-2 border-b border-neutral-200 px-6"> <div className="flex h-16.25 w-full shrink-0 items-center border-b border-neutral-200 px-2">
<Button
variant="ghost"
size="sm"
className="flex w-fit items-center gap-2 px-2"
asChild
>
<Link href="/rooms">
<div className="flex size-5 items-center justify-center">
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24" viewBox="0 0 24 24"
fill="currentColor" fill="currentColor"
className="size-6 text-neutral-900" className="size-5 text-neutral-900"
> >
<path <path
fillRule="evenodd" fillRule="evenodd"
@@ -94,72 +103,214 @@ export function Sidebar({
clipRule="evenodd" clipRule="evenodd"
/> />
</svg> </svg>
<span className="text-lg font-semibold tracking-tight">Fastchat</span> </div>
<motion.li variants={variants} className="flex items-center gap-2">
{!isCollapsed && (
<p className="text-sm font-semibold tracking-tight text-neutral-900">
Fastchat
</p>
)}
</motion.li>
</Link>
</Button>
</div> </div>
{/* Navigation */} {/* Navigation */}
<nav aria-label="Main navigation" className="flex-1 space-y-1 px-3 py-4"> <div className="flex h-full w-full flex-col">
<div className="flex grow flex-col">
<ScrollArea className="grow p-2">
<motion.ul
variants={staggerVariants}
className={cn("flex w-full flex-col gap-1")}
>
{navItems.map((item) => { {navItems.map((item) => {
const active = pathname === item.href; const active = pathname === item.href;
const Icon = item.icon;
return ( return (
<Link <Link
key={item.href} key={item.href}
href={item.href} href={item.href}
className={`flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium transition-colors ${ onClick={onNavigate}
className={cn(
"flex h-8 w-full flex-row items-center rounded-md px-2 py-1.5 transition hover:bg-neutral-100 hover:text-neutral-900",
active active
? "bg-neutral-100 text-neutral-900" ? "bg-neutral-100 text-neutral-900"
: "text-neutral-600 hover:bg-neutral-50 hover:text-neutral-900" : "text-neutral-600",
}`} )}
> >
{item.icon} <Icon className="h-4 w-4 shrink-0" />
{item.label} <motion.li variants={variants}>
{!isCollapsed && (
<p className="ml-2 text-sm font-medium">{item.label}</p>
)}
</motion.li>
</Link> </Link>
); );
})} })}
</nav> </motion.ul>
</ScrollArea>
</div>
{/* User section */} {/* User section */}
<div className="border-t border-neutral-200 p-4"> <div className="flex flex-col p-2">
<div className="flex items-center gap-3"> <Separator className="mb-2" />
<div className="flex size-9 items-center justify-center rounded-full bg-neutral-900 text-sm font-medium text-white"> <DropdownMenu modal={false}>
<DropdownMenuTrigger className="w-full">
<div className="flex h-8 w-full flex-row items-center gap-2 rounded-md px-2 py-1.5 transition hover:bg-neutral-100 hover:text-neutral-900">
<div className="relative size-4 shrink-0">
{avatarUrl ? (
<Image <Image
src={avatarUrl} src={avatarUrl}
alt="" alt=""
width={200} width={200}
height={200} height={200}
className="size-9 rounded-full object-cover" className="size-4 rounded-full object-cover"
/> />
) : (
<div className="flex size-4 items-center justify-center rounded-full bg-neutral-900 text-[8px] font-medium text-white">
{displayName.charAt(0).toUpperCase()}
</div> </div>
<div className="min-w-0 flex-1"> )}
<p className="truncate text-sm font-medium text-neutral-900"> </div>
<motion.li
variants={variants}
className="flex w-full items-center gap-2"
>
{!isCollapsed && (
<>
<p className="truncate text-sm font-medium">
{displayName} {displayName}
</p> </p>
<p className="truncate text-xs text-neutral-500">{email}</p> <ChevronsUpDown className="ml-auto h-4 w-4 text-neutral-400" />
</>
)}
</motion.li>
</div> </div>
</div> </DropdownMenuTrigger>
<form action={signOut}> <DropdownMenuContent sideOffset={5} align="start">
<button <div className="flex flex-row items-center gap-2 p-2">
type="submit" <div className="relative size-6 shrink-0">
className="mt-3 flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm text-neutral-600 transition-colors hover:bg-neutral-50 hover:text-neutral-900" {avatarUrl ? (
> <Image
<svg src={avatarUrl}
xmlns="http://www.w3.org/2000/svg" alt=""
viewBox="0 0 24 24" width={200}
fill="none" height={200}
stroke="currentColor" className="size-6 rounded-full object-cover"
strokeWidth={1.5}
className="size-4"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M15.75 9V5.25A2.25 2.25 0 0 0 13.5 3h-6a2.25 2.25 0 0 0-2.25 2.25v13.5A2.25 2.25 0 0 0 7.5 21h6a2.25 2.25 0 0 0 2.25-2.25V15m3 0 3-3m0 0-3-3m3 3H9"
/> />
</svg> ) : (
Sign out <div className="flex size-6 items-center justify-center rounded-full bg-neutral-900 text-[10px] font-medium text-white">
{displayName.charAt(0).toUpperCase()}
</div>
)}
</div>
<div className="flex flex-col text-left">
<span className="text-sm font-medium">{displayName}</span>
<span className="line-clamp-1 text-xs text-neutral-500">
{email}
</span>
</div>
</div>
<DropdownMenuSeparator />
<DropdownMenuItem asChild className="flex items-center gap-2">
<Link href="/profile">
<UserCircle className="h-4 w-4" /> Profile
</Link>
</DropdownMenuItem>
<DropdownMenuItem
className="flex items-center gap-2"
onSelect={(e) => e.preventDefault()}
>
<form action={signOut} className="contents">
<button type="submit" className="flex items-center gap-2">
<LogOut className="h-4 w-4" /> Sign out
</button> </button>
</form> </form>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
</div> </div>
</aside> );
}
export function Sidebar({
displayName,
email,
avatarUrl,
}: Readonly<{
displayName: string;
email: string;
avatarUrl: string;
}>) {
const [mobileOpen, setMobileOpen] = useState(false);
const closeMobile = useCallback(() => setMobileOpen(false), []);
return (
<>
{/* Mobile hamburger button — visible on small screens */}
<button
type="button"
onClick={() => setMobileOpen(true)}
className="fixed left-4 top-3.5 z-50 flex size-9 items-center justify-center rounded-lg bg-white shadow-sm border border-neutral-200 text-neutral-700 md:hidden"
aria-label="Open menu"
>
<Menu className="size-5" />
</button>
{/* Mobile overlay sidebar */}
<AnimatePresence>
{mobileOpen && (
<>
{/* Backdrop */}
<motion.div
className="fixed inset-0 z-40 bg-black/40 md:hidden"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
onClick={closeMobile}
/>
{/* Sidebar panel */}
<motion.div
className="fixed left-0 top-0 z-50 h-full w-64 bg-white shadow-xl md:hidden"
initial={{ x: "-100%" }}
animate={{ x: 0 }}
exit={{ x: "-100%" }}
transition={{ type: "tween", ease: "easeOut", duration: 0.2 }}
>
<div className="absolute right-2 top-2">
<button
type="button"
onClick={closeMobile}
className="flex size-8 items-center justify-center rounded-md text-neutral-400 hover:bg-neutral-100 hover:text-neutral-700"
aria-label="Close menu"
>
<X className="size-4" />
</button>
</div>
<SidebarContent
isCollapsed={false}
displayName={displayName}
email={email}
avatarUrl={avatarUrl}
onNavigate={closeMobile}
/>
</motion.div>
</>
)}
</AnimatePresence>
{/* Desktop sidebar — always open */}
<div className="hidden md:flex h-full w-64 shrink-0 border-r border-neutral-200">
<SidebarContent
isCollapsed={false}
displayName={displayName}
email={email}
avatarUrl={avatarUrl}
/>
</div>
</>
); );
} }