brackt/app/components/DraftSidebar.tsx
Claude 30b5fced8c
Fix all code review issues with push notifications
- Extract snake draft order calculation to shared getTeamForPick()
  helper in lib/draft-order.ts, removing the duplicated logic
- Fix notification firing on user's own picks (guard with team id check)
- Fix notification firing after draft is complete (early return)
- Use a ref for sendNotification to prevent full socket handler
  re-registration every time the toggle is changed
- Add permission drift listener via Permissions API so the UI reacts
  if the user revokes notification permission in browser settings
- Add SSR guard for document.hidden in sendNotification
- Remove redundant isSupported prop from NotificationSettings;
  derive unsupported state from permissionState === "unsupported"
- Move NotificationSettings out of QueueSection prop-drilling path;
  render it via a new settingsSection slot on DraftSidebar instead

https://claude.ai/code/session_0149MvVUYDY6pFUAV1fL4K69
2026-02-20 21:45:35 +00:00

122 lines
3.8 KiB
TypeScript

import type { ReactNode } from "react";
import { ChevronLeft, ChevronRight } from "lucide-react";
import { Button } from "~/components/ui/button";
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "~/components/ui/accordion";
import { cn } from "~/lib/utils";
interface DraftSidebarProps {
collapsed: boolean;
onCollapsedChange: (collapsed: boolean) => void;
queueSection: ReactNode;
recentPicksSection: ReactNode;
settingsSection?: ReactNode;
className?: string;
}
export function DraftSidebar({
collapsed,
onCollapsedChange,
queueSection,
recentPicksSection,
settingsSection,
className,
}: DraftSidebarProps) {
if (collapsed) {
return (
<div
className={cn(
"relative flex-shrink-0 bg-card border-r border-border transition-all duration-300 flex flex-col",
"w-12 hidden lg:block", // Hide completely on mobile when collapsed
className
)}
>
<div className="flex-1" />
{/* Expand button at bottom to match hide button position */}
<div className="border-t border-border p-2 flex-shrink-0">
<Button
variant="ghost"
size="icon"
onClick={() => onCollapsedChange(false)}
className="w-full"
aria-label="Expand sidebar"
>
<ChevronRight className="h-4 w-4" />
</Button>
</div>
</div>
);
}
return (
<>
{/* Mobile backdrop */}
<div
className="fixed inset-0 bg-black/50 z-40 lg:hidden"
onClick={() => onCollapsedChange(true)}
aria-label="Close sidebar"
/>
<div
className={cn(
"relative flex-shrink-0 bg-card border-r border-border transition-all duration-300 flex flex-col",
"w-[450px]",
// Mobile: fixed overlay, Desktop: normal sidebar
"fixed inset-y-0 left-0 z-50 lg:relative lg:z-auto",
className
)}
>
<Accordion
type="multiple"
defaultValue={["queue", "recent-picks"]}
className="flex-1 overflow-hidden flex flex-col"
>
{/* Queue Section */}
<AccordionItem value="queue" className="border-b flex-shrink-0">
<AccordionTrigger className="px-4 py-3 hover:no-underline bg-muted/50 hover:bg-muted">
<h2 className="font-semibold text-sm">My Queue</h2>
</AccordionTrigger>
<AccordionContent className="max-h-[35vh] overflow-y-auto pb-0">
{queueSection}
</AccordionContent>
</AccordionItem>
{/* Recent Picks Section */}
<AccordionItem value="recent-picks" className="border-0 flex-1 overflow-hidden flex flex-col">
<AccordionTrigger className="px-4 py-3 hover:no-underline bg-muted/50 hover:bg-muted flex-shrink-0">
<h2 className="font-semibold text-sm">Recent Picks</h2>
</AccordionTrigger>
<AccordionContent className="pb-0 flex-1 overflow-y-auto">
{recentPicksSection}
</AccordionContent>
</AccordionItem>
</Accordion>
{/* Settings section (e.g. notification toggle) */}
{settingsSection && (
<div className="border-t border-border px-4 py-3 flex-shrink-0">
{settingsSection}
</div>
)}
{/* Collapse button at bottom */}
<div className="border-t border-border p-2 flex-shrink-0">
<Button
variant="ghost"
size="sm"
onClick={() => onCollapsedChange(true)}
className="w-full flex items-center justify-center gap-2"
aria-label="Collapse sidebar"
>
<ChevronLeft className="h-4 w-4" />
<span className="text-sm">Hide Sidebar</span>
</Button>
</div>
</div>
</>
);
}