* 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
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { useCallback } from 'react';
|
|
import { attemptsApi } from '@/lib/api';
|
|
import { EditorSelectionDialog } from '@/components/dialogs/tasks/EditorSelectionDialog';
|
|
import type { EditorType } from 'shared/types';
|
|
|
|
type OpenEditorOptions = {
|
|
editorType?: EditorType;
|
|
filePath?: string;
|
|
};
|
|
|
|
export function useOpenInEditor(
|
|
attemptId?: string,
|
|
onShowEditorDialog?: () => void
|
|
) {
|
|
return useCallback(
|
|
async (options?: OpenEditorOptions): Promise<void> => {
|
|
if (!attemptId) return;
|
|
|
|
const { editorType, filePath } = options ?? {};
|
|
|
|
try {
|
|
const response = await attemptsApi.openEditor(attemptId, {
|
|
editor_type: editorType ?? null,
|
|
file_path: filePath ?? 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 editor:', err);
|
|
if (!editorType) {
|
|
if (onShowEditorDialog) {
|
|
onShowEditorDialog();
|
|
} else {
|
|
EditorSelectionDialog.show({
|
|
selectedAttemptId: attemptId,
|
|
filePath,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
},
|
|
[attemptId, onShowEditorDialog]
|
|
);
|
|
}
|