import type React from "react"; import type { ReactNode } from "react"; import { useState } from "react"; import { ChevronsDownUp, ChevronsUpDown, Pencil, Loader, CircleX, Edit, X, } from "lucide-react"; import { CodeHighlight } from "./CodeHighlight"; import { CustomTagState } from "./stateTypes"; import { FileEditor } from "../preview_panel/FileEditor"; import { useAtomValue } from "jotai"; import { selectedAppIdAtom } from "@/atoms/appAtoms"; interface MoreMinimoreWriteProps { children?: ReactNode; node?: any; path?: string; description?: string; } export const MoreMinimoreWrite: React.FC = ({ children, node, path: pathProp, description: descriptionProp, }) => { const [isContentVisible, setIsContentVisible] = useState(false); // Use props directly if provided, otherwise extract from node const path = pathProp || node?.properties?.path || ""; const description = descriptionProp || node?.properties?.description || ""; const state = node?.properties?.state as CustomTagState; const aborted = state === "aborted"; const appId = useAtomValue(selectedAppIdAtom); const [isEditing, setIsEditing] = useState(false); const inProgress = state === "pending"; const handleCancel = () => { setIsEditing(false); }; const handleEdit = () => { setIsEditing(true); setIsContentVisible(true); }; // Extract filename from path const fileName = path ? path.split("/").pop() : ""; return (
setIsContentVisible(!isContentVisible)} >
{fileName && ( {fileName} )} {inProgress && (
Writing...
)} {aborted && (
Did not finish
)}
{!inProgress && ( <> {isEditing ? ( <> ) : ( )} )} {isContentVisible ? ( ) : ( )}
{path && (
{path}
)} {description && (
Summary: {description}
)} {isContentVisible && (
e.stopPropagation()} > {isEditing ? (
) : ( {children} )}
)}
); };