"use client" import React, { useMemo, useState } from "react" import { TopicDetailHeader } from "./Header" import { useAccountOrGuest, useCoState } from "@/lib/providers/jazz-provider" import { JAZZ_GLOBAL_GROUP_ID } from "@/lib/constants" import { Topic } from "@/lib/schema" import { TopicDetailList } from "./list" import { atom } from "jotai" import { Skeleton } from "@/components/ui/skeleton" import { GraphNode } from "../../public/PublicHomeRoute" import { LaIcon } from "@/components/custom/la-icon" const graph_data_promise = import("@/components/routes/public/graph-data.json").then(a => a.default) interface TopicDetailRouteProps { topicName: string } export const openPopoverForIdAtom = atom(null) export function TopicDetailRoute({ topicName }: TopicDetailRouteProps) { const raw_graph_data = React.use(graph_data_promise) as GraphNode[] const { me } = useAccountOrGuest({ root: { personalLinks: [] } }) const topicID = useMemo(() => me && Topic.findUnique({ topicName }, JAZZ_GLOBAL_GROUP_ID, me), [topicName, me]) const topic = useCoState(Topic, topicID, { latestGlobalGuide: { sections: [] } }) const [activeIndex, setActiveIndex] = useState(-1) const topicExists = raw_graph_data.find(node => node.name === topicName) if (!topicExists) { return } const flattenedItems = topic?.latestGlobalGuide?.sections.flatMap(section => [ { type: "section" as const, data: section }, ...(section?.links?.map(link => ({ type: "link" as const, data: link })) || []) ]) if (!topic || !me || !flattenedItems) { return } return ( <> ) } function NotFoundPlaceholder() { return (
Topic not found
There is no topic with the given identifier.
) } function TopicDetailSkeleton() { return ( <>
{[...Array(10)].map((_, index) => (
))}
) }