diff --git a/js/src/features/layout.tsx b/js/src/features/layout.tsx index 050ef5e..828acdb 100644 --- a/js/src/features/layout.tsx +++ b/js/src/features/layout.tsx @@ -1,6 +1,6 @@ import { WindowControls } from "@/components/window-controls"; import { Button } from "@/components/ui/button"; -import { Outlet, useLocation, useNavigate } from "react-router-dom"; +import { Outlet, useLocation, useNavigate, useParams } from "react-router-dom"; import { Home, Settings } from "lucide-react"; import { Breadcrumb, @@ -12,6 +12,30 @@ import { } from "@/components/ui/breadcrumb"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { useNetworks } from "@/hooks/use-networks"; +import { particlePath, toFirestoreDocPath } from "@/lib/particle-path"; +import { useLiveParticle } from "@/hooks/use-particle"; +import { useEffect } from "react"; +import { useQuery } from "@tanstack/react-query"; +import { getParticle } from "@/lib/firestore-particles"; +import type { Particle } from "@/api/types"; + +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(); @@ -33,8 +57,24 @@ function NetworkBreadcrumbContent({ networkId }: { networkId: string }) { function TopBar() { const navigate = useNavigate(); - const segments = useLocation().pathname.split("/").filter(Boolean); - const networkId = segments[0] ?? null; + const { networkId, "*": rest } = useParams(); + const segments = [networkId, ...rest?.split("/") ?? []].filter(Boolean); + + console.log(segments); + + const path = rest ? particlePath(networkId!, rest.split("/").filter(Boolean)) : null; + + const { data: particle } = useQuery( + { + queryKey: ["particle", path], + queryFn: async () => { + if (!path) return null; + const particle = await getParticle(toFirestoreDocPath(path)); + return particle; + }, + enabled: !!path, + }, + ); return (