"use client"; import { useState } from "react"; import { usePathname, useRouter } from "next/navigation"; import clsx from "clsx"; import { useChannels, useFeatureFlags, useInbox, useSdk, type Channel, } from "@lynkd/messaging-inbox-sdk"; import { useUi } from "@/lib/ui-state"; import { Avatar, CountBadge } from "@/components/ui/primitives"; import { Hash, Lock, ChevronDown, ChevronRight, Plus, MessageSquarePlus, Send, Bookmark, MessagesSquare, Inbox as InboxIcon, Sliders, Circle, PanelLeftClose, } from "lucide-react"; export function Sidebar() { const { starred, channels, dms } = useChannels(); const { me, brandName, channelById } = useSdk(); const flags = useFeatureFlags(); const router = useRouter(); const pathname = usePathname(); const { openProfile, setThemingOpen, openModal, toggleSidebarCollapsed } = useUi(); const { items: openInbox } = useInbox("OPEN"); const quick = [ flags.threads && { icon: MessagesSquare, label: "Threads", href: "/threads" }, flags.inbox && { icon: InboxIcon, label: "Inbox", href: "/inbox", badge: openInbox.length }, flags.drafts && { icon: Send, label: "Drafts & sent", href: "/drafts" }, flags.savedItems && { icon: Bookmark, label: "Saved", href: "/saved" }, ].filter(Boolean) as { icon: typeof Hash; label: string; href: string; badge?: number }[]; return ( ); } function ChannelGroup({ title, items, activePath, onOpen, footer, defaultOpen, me, channelById, }: { title: string; items: Channel[]; activePath: string; onOpen: (c: Channel) => void; footer?: React.ReactNode; defaultOpen?: boolean; me?: string; channelById: (id: string) => Channel | undefined; }) { const [open, setOpen] = useState(defaultOpen ?? true); return (
{open && (
{items.map((c) => ( onOpen(c)} meId={me} /> ))} {footer}
)}
); } function ChannelRow({ channel, active, onOpen, meId, }: { channel: Channel; active: boolean; onOpen: () => void; meId?: string; }) { const { userById } = useSdk(); const unread = channel.unreadCount ?? 0; const isDm = channel.kind === "dm"; const other = isDm ? channel.memberIds.find((id) => id !== meId) : undefined; const otherUser = other ? userById(other) : undefined; return ( ); } function SidebarAction({ icon: Icon, label, onClick, }: { icon: typeof Hash; label: string; onClick: () => void; }) { return ( ); }