@graphteon/juricode
Version:
We are forging the future with lines of digital steel
107 lines • 5.59 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const ink_1 = require("ink");
const TasksTUI_1 = __importDefault(require("./TasksTUI"));
const SuggestedTasksTUI_1 = __importDefault(require("./SuggestedTasksTUI"));
const RepositoriesTUI_1 = __importDefault(require("./RepositoriesTUI"));
const CreateTaskTUI_1 = __importDefault(require("./CreateTaskTUI"));
const ConversationTUI_1 = __importDefault(require("./ConversationTUI"));
const open_hands_1 = __importDefault(require("../api/open-hands"));
const MainMenuTUI = () => {
const [currentScreen, setCurrentScreen] = (0, react_1.useState)('main');
const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(0);
const [conversationId, setConversationId] = (0, react_1.useState)('');
const { exit } = (0, ink_1.useApp)();
const menuItems = [
{ title: '📋 View All Tasks', value: 'tasks' },
{ title: '💡 Suggested Tasks', value: 'suggested' },
{ title: '📚 Browse Repositories', value: 'repositories' },
{ title: '📝 Create New Task', value: 'create' },
{ title: '🚪 Exit', value: 'exit' }
];
(0, ink_1.useInput)((input, key) => {
if (currentScreen !== 'main')
return;
if (key.escape) {
exit();
return;
}
if (key.upArrow && selectedIndex > 0) {
setSelectedIndex(selectedIndex - 1);
}
if (key.downArrow && selectedIndex < menuItems.length - 1) {
setSelectedIndex(selectedIndex + 1);
}
if (key.return) {
const selectedItem = menuItems[selectedIndex];
if (selectedItem.value === 'exit') {
exit();
}
else {
setCurrentScreen(selectedItem.value);
}
}
if (input === 'q') {
exit();
}
});
const handleBack = () => {
setCurrentScreen('main');
setSelectedIndex(0);
};
const handleSelectTask = (taskId) => {
setConversationId(taskId);
setCurrentScreen('conversation');
};
const handleSelectSuggestedTask = async (task) => {
try {
const conversation = await open_hands_1.default.createConversationFromSuggestedTask(task);
setConversationId(conversation.conversation_id);
setCurrentScreen('conversation');
}
catch (error) {
console.error('Failed to create conversation from suggested task:', error);
handleBack();
}
};
const handleSelectRepository = async (repo, branch) => {
try {
const conversation = await open_hands_1.default.createConversation(repo.full_name, repo.git_provider, undefined, [], undefined, branch || 'main');
setConversationId(conversation.conversation_id);
setCurrentScreen('conversation');
}
catch (error) {
console.error('Failed to create conversation from repository:', error);
handleBack();
}
};
const handleTaskCreated = (newConversationId) => {
setConversationId(newConversationId);
setCurrentScreen('conversation');
};
const renderScreen = () => {
switch (currentScreen) {
case 'tasks':
return ((0, jsx_runtime_1.jsx)(TasksTUI_1.default, { onBack: handleBack, onSelectTask: handleSelectTask }));
case 'suggested':
return ((0, jsx_runtime_1.jsx)(SuggestedTasksTUI_1.default, { onBack: handleBack, onSelectTask: handleSelectSuggestedTask }));
case 'repositories':
return ((0, jsx_runtime_1.jsx)(RepositoriesTUI_1.default, { onBack: handleBack, onSelectRepository: handleSelectRepository }));
case 'create':
return ((0, jsx_runtime_1.jsx)(CreateTaskTUI_1.default, { onBack: handleBack, onTaskCreated: handleTaskCreated }));
case 'conversation':
return ((0, jsx_runtime_1.jsx)(ConversationTUI_1.default, { taskId: conversationId }));
case 'main':
default:
return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", height: "100%", children: [(0, jsx_runtime_1.jsx)(ink_1.Box, { borderStyle: "single", borderColor: "blue", paddingX: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "blue", bold: true, children: "\uD83C\uDFE0 JuriCode Main Menu" }) }), (0, jsx_runtime_1.jsx)(ink_1.Box, { flexDirection: "column", flexGrow: 1, paddingX: 1, paddingY: 1, children: menuItems.map((item, index) => ((0, jsx_runtime_1.jsx)(ink_1.Box, { marginBottom: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Box, { borderStyle: "single", borderColor: index === selectedIndex ? 'green' : 'gray', paddingX: 1, paddingY: 0, children: (0, jsx_runtime_1.jsxs)(ink_1.Text, { color: index === selectedIndex ? 'green' : 'white', bold: true, children: [index === selectedIndex ? '▶ ' : ' ', item.title] }) }) }, item.value))) }), (0, jsx_runtime_1.jsx)(ink_1.Box, { borderStyle: "single", borderColor: "gray", paddingX: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "gray", children: "\u2191\u2193 Navigate \u2022 Enter Select \u2022 Q Quit" }) })] }));
}
};
return renderScreen();
};
exports.default = MainMenuTUI;
//# sourceMappingURL=MainMenuTUI.js.map