/** * Section Picker Modal * * A modal for selecting and inserting sections into content. */ import { Button, Dialog, Input } from "@cloudflare/kumo"; import { useLingui } from "@lingui/react/macro"; import { MagnifyingGlass, Stack, FolderOpen } from "@phosphor-icons/react"; import { X } from "@phosphor-icons/react"; import { useQuery } from "@tanstack/react-query"; import * as React from "react"; import { fetchSections, type Section } from "../lib/api"; import { useDebouncedValue } from "../lib/hooks"; import { cn } from "../lib/utils"; interface SectionPickerModalProps { open: boolean; onOpenChange: (open: boolean) => void; onSelect: (section: Section) => void; } export function SectionPickerModal({ open, onOpenChange, onSelect }: SectionPickerModalProps) { const { t } = useLingui(); const [searchQuery, setSearchQuery] = React.useState(""); const debouncedSearch = useDebouncedValue(searchQuery, 300); const { data: sectionsData, isLoading: sectionsLoading } = useQuery({ queryKey: ["sections", { search: debouncedSearch }], queryFn: () => fetchSections({ search: debouncedSearch || undefined, }), enabled: open, }); const sections = sectionsData?.items ?? []; // Reset search when modal opens React.useEffect(() => { if (open) { setSearchQuery(""); } }, [open]); const handleSelect = (section: Section) => { onSelect(section); onOpenChange(false); }; return (
{t`Insert Section`} ( )} />
{/* Search */}
setSearchQuery(e.target.value)} className="ps-10" autoFocus />
{/* Section grid */}
{sectionsLoading ? (
{t`Loading sections...`}
) : sections.length === 0 ? (
{searchQuery ? ( <>

{t`No sections found`}

{t`Try adjusting your search`}

) : ( <>

{t`No sections available`}

{t`Create sections in the Sections library to use them here`}

)}
) : (
{sections.map((section) => ( handleSelect(section)} /> ))}
)}
{/* Footer */}
); } function SectionCard({ section, onSelect }: { section: Section; onSelect: () => void }) { return ( ); }