import { useState } from 'react' import { useEditorStore } from '../../store/editorStore' import type { FileNode } from '../../types/editor' interface Props { node: FileNode depth: number } export function FileTreeNode({ node, depth }: Props): JSX.Element { const [expanded, setExpanded] = useState(true) const { activeFilePath, setActiveFile } = useEditorStore() const openFile = async (): Promise => { if (node.type === 'file') { const content = await window.api.readFile(node.path) setActiveFile(node.path, content) } } if (node.type === 'directory') { return (
{expanded && node.children?.map((child) => ( ))}
) } const isActive = activeFilePath === node.path return ( ) }