import * as React from "react" import { useMedia } from "@/hooks/use-media" import { useAtom } from "jotai" import { buttonVariants } from "@/components/ui/button" import { cn } from "@/lib/utils" import { isCollapseAtom } from "@/store/sidebar" import { useAccountOrGuest } from "@/lib/providers/jazz-provider" import { LaIcon } from "@/components/custom/la-icon" import { Link, useLocation } from "@tanstack/react-router" import { PageSection } from "./partials/page-section" import { ProfileSection } from "./partials/profile-section" import { JournalSection } from "./partials/journal-section" import { LinkCollection } from "./partials/link-collection" interface SidebarItemProps { label: string url: string icon?: React.ReactNode onClick?: () => void children?: React.ReactNode } const useSidebarCollapse = ( isTablet: boolean, ): [boolean, React.Dispatch>] => { const [isCollapsed, setIsCollapsed] = useAtom(isCollapseAtom) const location = useLocation() React.useEffect(() => { if (isTablet) setIsCollapsed(true) }, [location.pathname, setIsCollapsed, isTablet]) React.useEffect(() => { setIsCollapsed(isTablet) }, [isTablet, setIsCollapsed]) return [isCollapsed, setIsCollapsed] } const SidebarItem: React.FC = ({ label, url, icon, onClick, children, }) => { const { pathname } = useLocation() const isActive = pathname === url return (
{icon && ( {icon} )} {label} {children}
) } SidebarItem.displayName = "SidebarItem" const LogoAndSearch: React.FC = () => { const { pathname } = useLocation() return (
Learn Anything
{pathname === "/search" ? ( "← Back" ) : ( )}
) } LogoAndSearch.displayName = "LogoAndSearch" const SidebarContent: React.FC = () => { const { me } = useAccountOrGuest() return ( ) } SidebarContent.displayName = "SidebarContent" const Sidebar: React.FC = () => { const isTablet = useMedia("(max-width: 1024px)") const [isCollapsed, setIsCollapsed] = useSidebarCollapse(isTablet) const sidebarClasses = cn( "h-full overflow-hidden transition-all duration-300 ease-in-out", isCollapsed ? "w-0" : "w-auto min-w-56", ) const sidebarInnerClasses = cn( "h-full w-60 min-w-60 transition-transform duration-300 ease-in-out", isCollapsed ? "-translate-x-full" : "translate-x-0", ) if (isTablet) { return ( <>
setIsCollapsed(true)} />
) } return (
) } Sidebar.displayName = "Sidebar" export { Sidebar, SidebarItem }