import { Check, ChevronDown, Globe, Sparkles, Users } from 'lucide-react'; import type { ComponentType } from 'react'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { Tooltip, TooltipContent, TooltipTrigger, } from '@/components/ui/tooltip'; import type { FeedMode } from '@/hooks/useMixedFeed'; import { cn } from '@/lib/utils'; interface FeedModeOption { mode: FeedMode; label: string; icon: ComponentType<{ className?: string }>; } const OPTIONS: FeedModeOption[] = [ { mode: 'agora', label: 'Agora', icon: Sparkles }, { mode: 'all-nostr', label: 'All Nostr', icon: Globe }, { mode: 'following', label: 'Following', icon: Users }, ]; interface FeedModeSwitcherProps { value: FeedMode; onChange: (mode: FeedMode) => void; /** When false, Following mode is disabled (requires login). */ followingAvailable: boolean; /** Click handler for the disabled Following item (typically opens the auth dialog). */ onLoginRequested?: () => void; className?: string; } /** * The primary feed-mode picker rendered at the top-left of the home feed page. * * Visually anchored as the page heading — the active mode label is the largest * text on the page. Clicking opens a compact dropdown menu offering the three * modes; the active one is marked with a check. * * Logged-out users see "Following" greyed out; clicking it invokes * {@link FeedModeSwitcherProps.onLoginRequested} to surface the auth dialog. */ export function FeedModeSwitcher({ value, onChange, followingAvailable, onLoginRequested, className, }: FeedModeSwitcherProps) { const active = OPTIONS.find((opt) => opt.mode === value) ?? OPTIONS[0]; return ( {active.label} {OPTIONS.map((opt) => { const Icon = opt.icon; const isActive = opt.mode === value; const isFollowing = opt.mode === 'following'; const disabled = isFollowing && !followingAvailable; const handleSelect = (event: Event) => { if (disabled) { event.preventDefault(); onLoginRequested?.(); return; } onChange(opt.mode); }; const itemContent = ( {opt.label} {isActive && } ); if (disabled) { return ( {itemContent} Log in to see posts from people you follow ); } return itemContent; })} ); }