fix: render files
ci-front / build (push) Successful in 2m5s

This commit is contained in:
nikita
2026-04-05 01:07:03 +03:00
parent 8f5558fdb7
commit e024f91111
2 changed files with 31 additions and 56 deletions
+16 -21
View File
@@ -299,37 +299,32 @@ export const useIDEStore = create<IDEState>((set, get) => ({
fetchTree: async () => {
try {
const data = await scriptsApi.getTree();
const nodeMap = new Map<string, FileNode>();
data.forEach((item) => {
nodeMap.set(item.name, {
const convertItem = (item: any): FileNode => {
const node: FileNode = {
id: item.id,
name: item.name,
type: item.type === "folder" ? "folder" : "file",
content: item.content || "",
path: item.name,
interpreter_id: item.interpreter_id,
children: item.type === "folder" ? [] : undefined,
});
});
};
const hasParent = new Set<string>();
data.forEach((item) => {
if (item.children) {
item.children.forEach((childName: string) => {
hasParent.add(childName);
const parent = nodeMap.get(item.name);
const child = nodeMap.get(childName);
if (parent?.children && child) {
parent.children.push(child);
}
});
if (item.type === "folder") {
node.children = [];
if (item.children && Array.isArray(item.children)) {
node.children = item.children.map((child: any) => {
const childNode = convertItem(child);
childNode.path = `${item.name}/${child.name}`;
return childNode;
});
}
}
});
const roots = [...nodeMap.entries()]
.filter(([name]) => !hasParent.has(name))
.map(([, node]) => node);
return node;
};
const roots = data.map((item) => convertItem(item));
set({
files: {