import { WindowControls } from "@/components/window-controls"; import { Button } from "@/components/ui/button"; import { useNavigate, useParams } from "react-router-dom"; import { Home, Settings, Users, Volume2, VolumeOff } from "lucide-react"; import { Switch } from "@/components/ui/switch"; import { useAutoplayStore } from "@/stores/autoplay-store"; import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from "@/components/ui/breadcrumb"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { useNetworks } from "@/hooks/use-networks"; import { particlePath } from "@/lib/particle-path"; import { useParticle } from "@/hooks/use-particle"; import type { Particle } from "@/api/types"; import { PropsWithChildren, useCallback } from "react"; import { useDockBadge } from "@/hooks/use-dock-badge"; import { toast } from "sonner"; function getParticleDisplayName(particle: Particle): string { switch (particle.type) { case "stream": case "folder": return particle.properties.name; case "quest": return particle.properties.title; case "paper": return particle.properties.title; case "file": return particle.properties.filename; case "text": return particle.properties.content.slice(0, 30); case "media": return particle.type; } } function NetworkBreadcrumbContent({ networkId }: { networkId: string }) { const { data: networks } = useNetworks(); const network = networks?.find((n) => n.id === networkId); const name = network?.name ?? networkId; const initials = name.slice(0, 2).toUpperCase(); return ( {initials} {name} ); } function AutoplayToggle() { const muted = useAutoplayStore((s) => s.muted); const toggleMuted = useAutoplayStore((s) => s.toggleMuted); const handleToggle = useCallback(() => { toggleMuted(); if (muted) { toast.success("Auto-play enabled"); } else { toast.info("Auto-play disabled"); } }, [toggleMuted, muted]); return (
{muted ? : }
); } function TopBar() { const navigate = useNavigate(); const { networkId, "*": rest } = useParams(); const segments = [networkId, ...rest?.split("/") ?? []].filter(Boolean); const path = rest && networkId ? particlePath(networkId, rest.split("/").filter(Boolean)) : undefined; const { data: particle } = useParticle(path); return (
{segments.length === 0 ? ( ) : ( navigate("/")} > )} {networkId && ( {segments.length === 1 ? ( ) : ( navigate(`/${networkId}`)} > )} )} {particle && ( {getParticleDisplayName(particle)} )}
{networkId && ( )}
); } export default function Layout({ children }: PropsWithChildren) { const { networkId } = useParams(); useDockBadge(networkId); return (
{children}
); }