import { useId, useRef, useState } from "react"; import { NavigationDialog } from "./navigation-dialog"; import { canManageProject } from "./navigation-model"; import { TerminalAlert } from "./terminal-alert"; import type * as Api from "./api"; import type { NavigationDialogMotion } from "./navigation-dialog"; import type { DocumentCreationPhase } from "./use-document-creation"; export function NewDocumentDialog( { projects, pending, error, motion, onCreate, onAddProject, onDismiss, onRetry }: { projects: Api.NavigationProject[]; pending: ReadonlyMap; error?: string; motion: NavigationDialogMotion; onCreate: (project: Api.NavigationProject) => void; onAddProject: () => void; onDismiss: () => void; onRetry?: () => void; }, ) { let input = useRef(null); let searchId = useId(); let [query, setQuery] = useState(""); let eligible = projects.filter(project => project.available && canManageProject(project)) .sort((first, second) => first.position - second.position); let normalized = query.trim().toLocaleLowerCase(); let visible = eligible.filter(project => `${project.repositoryOwner}/${project.repositoryName}`.toLocaleLowerCase().includes(normalized) ); return ( 0 ? input : undefined} motion={motion} onDismiss={onDismiss} title="New document" > {error && ( {error} {onRetry && ( )} )} {eligible.length > 0 ? ( <>

Choose a project for your new document.

setQuery(event.target.value)} placeholder="Search projects" ref={input} value={query} />
{visible.length === 0 && (

No matching projects.

)} {visible.map(project => { let phase = pending.get(project.repositoryId); return (
{phase === "creating" ? "Creating document…" : phase ? "Opening document…" : ""}
); })}
) : (

{projects.length === 0 ? "Add a project to create your first document." : "You need write access to an available project to create a document."}

Manage repository access
)}
); }