UNPKG

@graphteon/juricode

Version:

We are forging the future with lines of digital steel

67 lines 5.11 kB
"use strict"; 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 open_hands_1 = __importDefault(require("../api/open-hands")); const SuggestedTasksTUI = ({ onBack, onSelectTask }) => { const [tasks, setTasks] = (0, react_1.useState)([]); const [selectedIndex, setSelectedIndex] = (0, react_1.useState)(0); const [loading, setLoading] = (0, react_1.useState)(true); const [error, setError] = (0, react_1.useState)(null); const { exit } = (0, ink_1.useApp)(); (0, react_1.useEffect)(() => { const fetchSuggestedTasks = async () => { try { setLoading(true); const suggestedTasks = await open_hands_1.default.getSuggestedTasks(); setTasks(suggestedTasks); setError(null); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to fetch suggested tasks'); } finally { setLoading(false); } }; fetchSuggestedTasks(); }, []); (0, ink_1.useInput)((input, key) => { if (key.escape) { onBack(); return; } if (loading) return; if (key.upArrow && selectedIndex > 0) { setSelectedIndex(selectedIndex - 1); } if (key.downArrow && selectedIndex < tasks.length - 1) { setSelectedIndex(selectedIndex + 1); } if (key.return && tasks.length > 0) { onSelectTask(tasks[selectedIndex]); } if (input === 'q') { exit(); } }); const getDifficultyColor = (difficulty) => { switch (difficulty.toLowerCase()) { case 'easy': return 'green'; case 'medium': return 'yellow'; case 'hard': return 'red'; default: return 'gray'; } }; const truncateText = (text, maxLength) => { return text.length > maxLength ? text.substring(0, maxLength) + '...' : text; }; 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: "\uD83D\uDCA1 Suggested Tasks" }) }), (0, jsx_runtime_1.jsx)(ink_1.Box, { flexDirection: "column", flexGrow: 1, paddingX: 1, paddingY: 1, children: loading ? ((0, jsx_runtime_1.jsx)(ink_1.Box, { justifyContent: "center", alignItems: "center", height: "100%", children: (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "yellow", children: "\u23F3 Loading suggested tasks..." }) })) : error ? ((0, jsx_runtime_1.jsx)(ink_1.Box, { justifyContent: "center", alignItems: "center", height: "100%", children: (0, jsx_runtime_1.jsxs)(ink_1.Text, { color: "red", children: ["\u274C Error: ", error] }) })) : tasks.length === 0 ? ((0, jsx_runtime_1.jsx)(ink_1.Box, { justifyContent: "center", alignItems: "center", height: "100%", children: (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "gray", children: "No suggested tasks available at the moment." }) })) : (tasks.map((task, 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.Box, { flexDirection: "column", children: [(0, jsx_runtime_1.jsx)(ink_1.Box, { children: (0, jsx_runtime_1.jsxs)(ink_1.Text, { color: index === selectedIndex ? 'green' : 'white', bold: true, children: [index === selectedIndex ? '▶ ' : ' ', task.title] }) }), (0, jsx_runtime_1.jsxs)(ink_1.Box, { marginTop: 1, children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: "gray", children: "Repository: " }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "cyan", children: task.repo }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "gray", children: " | Provider: " }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "blue", children: task.git_provider }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "gray", children: " | Type: " }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "yellow", children: task.task_type })] }), (0, jsx_runtime_1.jsxs)(ink_1.Box, { marginTop: 1, children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: "gray", children: "Issue #" }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "magenta", children: task.issue_number })] })] }) }) }, index)))) }), (0, jsx_runtime_1.jsx)(ink_1.Box, { borderStyle: "single", borderColor: "gray", paddingX: 1, children: (0, jsx_runtime_1.jsxs)(ink_1.Text, { color: "gray", children: [tasks.length > 0 ? '↑↓ Navigate • Enter Select • ' : '', "ESC Back \u2022 Q Quit"] }) })] })); }; exports.default = SuggestedTasksTUI; //# sourceMappingURL=SuggestedTasksTUI.js.map