import fs from 'fs'
const content = `'use client'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import { useState, useEffect } from 'react'
import { cn } from '@/lib/utils'
import { signOut } from '@/lib/auth-actions'
import type { SpaceMember, Space } from '@/lib/types'
import {
Menu, X, LayoutDashboard, ListChecks, FolderKanban, Settings2,
MessageSquare, Users, CreditCard, BookUser, Download, LogOut,
} from 'lucide-react'
function NavLink({
href, label, icon: Icon, badge, active,
}: {
href: string
label: string
icon: React.ElementType
badge?: number
active: boolean
}) {
return (
{label}
{badge && badge > 0 ? (
{badge}
) : null}
)
}
interface AppSidebarProps {
member: SpaceMember & { spaces: Space }
taskBadge?: number
commsBadge?: number
paymentBadge?: number
}
export function AppSidebar({ member, taskBadge = 0, commsBadge = 0, paymentBadge = 0 }: AppSidebarProps) {
const pathname = usePathname()
const space = member.spaces
const initials = member.display_name?.split(' ').map((n: string) => n[0]).join('').toUpperCase().slice(0, 2) || '??'
const isAdmin = member.role === 'admin' || member.role === 'board'
const [drawerOpen, setDrawerOpen] = useState(false)
// Auto-close the drawer whenever the route changes
useEffect(() => {
setDrawerOpen(false)
}, [pathname])
function isActive(href: string) {
return pathname === href || pathname.startsWith(href + '/')
}
async function handleSignOut() {
await signOut()
}
// navJsx is JSX stored in a variable — NOT a nested component.
// This avoids React remounting it on every parent render, which was
// causing the drawer to unmount before Next.js could navigate.
const navJsx = (
<>
{'{'}hs{'}'}
{space?.name || 'My Space'}
>
)
return (
<>
{/* Desktop sidebar */}
{/* Mobile: fixed top bar */}
hs
{space?.name}
{/* Mobile: slide-out drawer */}
{drawerOpen && (
setDrawerOpen(false)} aria-hidden="true" />
{space?.name}
{navJsx}
)}
>
)
}
`
fs.writeFileSync('/vercel/share/v0-project/components/app-sidebar.tsx', content, 'utf8')
console.log('Wrote app-sidebar.tsx successfully, length:', content.length)