feat: create files
ci-front / build (push) Successful in 2m31s

This commit is contained in:
nikita
2026-04-05 02:09:23 +03:00
parent f71a3b1a03
commit 5073cfd357
3 changed files with 56 additions and 48 deletions
+34 -9
View File
@@ -442,6 +442,7 @@ export const useIDEStore = create<IDEState>((set, get) => ({
return;
}
// Определяем родительский путь
let parentPath: string;
if (!dialog.node) {
parentPath = "";
@@ -453,17 +454,44 @@ export const useIDEStore = create<IDEState>((set, get) => ({
parentPath = pathParts.join("/");
}
const fullPath = parentPath ? `${parentPath}/${value}` : value;
// Проверяем наличие расширения
const hasExtension =
value.includes(".") && value.split(".").pop() !== value;
let finalName = value;
let isFile = false;
// Если диалог создания файла
if (dialog.type === "newFile") {
isFile = true;
// Если нет расширения — добавляем .txt
if (!hasExtension) {
finalName = `${value}.txt`;
}
} else if (dialog.type === "newFolder") {
// Если диалог создания папки — но имя с расширением, считаем файлом
if (hasExtension) {
isFile = true;
}
}
const fullPath = parentPath ? `${parentPath}/${finalName}` : finalName;
// Сохраняем раскрытые папки ДО перезагрузки дерева
const savedExpandedFolders = new Set(get().expandedFolders);
try {
const result = await scriptsApi.createScript({
content: "",
interpreter_id: 0,
interpreter_id: 1,
path: fullPath,
});
await get().fetchTree();
// Восстанавливаем раскрытые папки
set({ expandedFolders: savedExpandedFolders });
// Собираем все пути от корня до родительской папки
const allParentPaths: string[] = [];
let current = parentPath;
while (current) {
@@ -472,17 +500,14 @@ export const useIDEStore = create<IDEState>((set, get) => ({
parts.pop();
current = parts.join("/");
}
allParentPaths.forEach((p) => {
if (!get().expandedFolders.has(p)) {
toggleFolder(p);
}
});
// Раскрываем родительскую цепочку
autoExpandPaths(new Set(allParentPaths));
if (dialog.type === "newFile") {
if (isFile) {
const createdNode: FileNode = {
id: result.id,
name: value,
name: finalName,
type: "file",
content: result.content,
path: result.path,