* Remove unused delete file endpoint, move test helpers to test files Fix missing git id in tests * Remove unused gh cli methods * Remove unused replace_process * Fix open editor exports, remove unused struct Fix compile * Remove unused get_tasks endpoint Re-add get tasks, used by mcp * Remove unused get_execution_processes endpoint * Remove unused get tag endpoint
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { useCallback } from 'react';
|
|
import { projectsApi } from '@/lib/api';
|
|
import { ProjectEditorSelectionDialog } from '@/components/dialogs/projects/ProjectEditorSelectionDialog';
|
|
import type { EditorType, Project } from 'shared/types';
|
|
|
|
export function useOpenProjectInEditor(
|
|
project: Project | null,
|
|
onShowEditorDialog?: () => void
|
|
) {
|
|
return useCallback(
|
|
async (editorType?: EditorType) => {
|
|
if (!project) return;
|
|
|
|
try {
|
|
const response = await projectsApi.openEditor(project.id, {
|
|
editor_type: editorType ?? null,
|
|
file_path: null,
|
|
});
|
|
|
|
// If a URL is returned, open it in a new window/tab
|
|
if (response.url) {
|
|
window.open(response.url, '_blank');
|
|
}
|
|
} catch (err) {
|
|
console.error('Failed to open project in editor:', err);
|
|
if (!editorType) {
|
|
if (onShowEditorDialog) {
|
|
onShowEditorDialog();
|
|
} else {
|
|
ProjectEditorSelectionDialog.show({
|
|
selectedProject: project,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
},
|
|
[project, onShowEditorDialog]
|
|
);
|
|
}
|