"use client" import Link from "next/link" import { usePathname, useSearchParams } from "next/navigation" import { useSubscriptions } from "@/lib/queries/use-subscriptions" import { useUnreadCounts } from "@/lib/queries/use-unread-counts" import { useCustomFeeds } from "@/lib/queries/use-custom-feeds" import { useUserInterfaceStore } from "@/lib/stores/user-interface-store" import { classNames } from "@/lib/utilities" const NAVIGATION_LINK_CLASS = "block whitespace-nowrap px-2 py-1 text-text-secondary transition-colors hover:bg-background-tertiary hover:text-text-primary" const ACTIVE_LINK_CLASS = "bg-background-tertiary text-text-primary" function getFaviconUrl(feedUrl: string): string | null { try { const hostname = new URL(feedUrl).hostname return `https://www.google.com/s2/favicons?domain=${hostname}&sz=16` } catch { return null } } function FeedFavicon({ feedUrl }: { feedUrl: string }) { const faviconUrl = getFaviconUrl(feedUrl) if (!faviconUrl) return null return ( ) } function displayNameForSubscription(subscription: { customTitle: string | null feedTitle: string feedUrl: string }): string { if (subscription.customTitle) return subscription.customTitle if (subscription.feedTitle) return subscription.feedTitle try { return new URL(subscription.feedUrl).hostname } catch { return subscription.feedUrl || "untitled feed" } } function UnreadBadge({ count }: { count: number }) { if (count === 0) return null return ( {count > 999 ? "999+" : count} ) } function sidebarFocusClass( focusedPanel: string, focusedSidebarIndex: number, navIndex: number ): string { return focusedPanel === "sidebar" && focusedSidebarIndex === navIndex ? "bg-background-tertiary text-text-primary" : "" } export function SidebarContent() { const pathname = usePathname() const searchParameters = useSearchParams() const { data } = useSubscriptions() const { data: unreadCounts } = useUnreadCounts() const { data: customFeedsData } = useCustomFeeds() const setAddFeedDialogOpen = useUserInterfaceStore( (state) => state.setAddFeedDialogOpen ) const toggleSidebar = useUserInterfaceStore((state) => state.toggleSidebar) const showFeedFavicons = useUserInterfaceStore( (state) => state.showFeedFavicons ) const expandedFolderIdentifiers = useUserInterfaceStore( (state) => state.expandedFolderIdentifiers ) const toggleFolderExpansion = useUserInterfaceStore( (state) => state.toggleFolderExpansion ) const focusedPanel = useUserInterfaceStore((state) => state.focusedPanel) const focusedSidebarIndex = useUserInterfaceStore( (state) => state.focusedSidebarIndex ) function closeSidebarOnMobile() { if (typeof window !== "undefined" && window.innerWidth < 768) { toggleSidebar() } } const folders = data?.folders ?? [] const subscriptions = data?.subscriptions ?? [] const ungroupedSubscriptions = subscriptions.filter( (subscription) => !subscription.folderIdentifier ) const totalUnreadCount = Object.values(unreadCounts ?? {}).reduce( (sum, count) => sum + count, 0 ) function getFolderUnreadCount(folderIdentifier: string): number { return subscriptions .filter( (subscription) => subscription.folderIdentifier === folderIdentifier ) .reduce( (sum, subscription) => sum + (unreadCounts?.[subscription.feedIdentifier] ?? 0), 0 ) } const activeFeedIdentifier = searchParameters.get("feed") const activeFolderIdentifier = searchParameters.get("folder") const activeCustomFeedIdentifier = searchParameters.get("custom_feed") let navIndex = 0 return ( ) }