@graphteon/juricode
Version:
We are forging the future with lines of digital steel
62 lines • 3.99 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React, { useState, useEffect } from 'react';
import { Box, Text, useInput, useApp } from 'ink';
import OpenHands from '../api/open-hands';
const TasksTUI = ({ onBack, onSelectTask }) => {
const [tasks, setTasks] = useState([]);
const [selectedIndex, setSelectedIndex] = useState(0);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const { exit } = useApp();
useEffect(() => {
const fetchTasks = async () => {
try {
setLoading(true);
const userTasks = await OpenHands.getUserConversations();
setTasks(userTasks);
setError(null);
}
catch (err) {
setError(err instanceof Error ? err.message : 'Failed to fetch tasks');
}
finally {
setLoading(false);
}
};
fetchTasks();
}, []);
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].conversation_id);
}
if (input === 'q') {
exit();
}
});
const getStatusColor = (status) => {
switch (status.toLowerCase()) {
case 'running': return 'green';
case 'stopped': return 'red';
case 'finished': return 'blue';
default: return 'yellow';
}
};
const formatDate = (dateString) => {
return new Date(dateString).toLocaleDateString();
};
return (_jsxs(Box, { flexDirection: "column", height: "100%", children: [_jsx(Box, { borderStyle: "single", borderColor: "blue", paddingX: 1, children: _jsx(Text, { color: "blue", bold: true, children: "\uD83D\uDCCB All Tasks" }) }), _jsx(Box, { flexDirection: "column", flexGrow: 1, paddingX: 1, paddingY: 1, children: loading ? (_jsx(Box, { justifyContent: "center", alignItems: "center", height: "100%", children: _jsx(Text, { color: "yellow", children: "\u23F3 Loading tasks..." }) })) : error ? (_jsx(Box, { justifyContent: "center", alignItems: "center", height: "100%", children: _jsxs(Text, { color: "red", children: ["\u274C Error: ", error] }) })) : tasks.length === 0 ? (_jsx(Box, { justifyContent: "center", alignItems: "center", height: "100%", children: _jsx(Text, { color: "gray", children: "No tasks found. Create a new task to get started!" }) })) : (tasks.map((task, index) => (_jsx(Box, { marginBottom: 1, children: _jsx(Box, { borderStyle: "single", borderColor: index === selectedIndex ? 'green' : 'gray', paddingX: 1, paddingY: 0, children: _jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { children: _jsxs(Text, { color: index === selectedIndex ? 'green' : 'white', bold: true, children: [index === selectedIndex ? '▶ ' : ' ', task.title || 'Untitled Task'] }) }), _jsxs(Box, { marginTop: 1, children: [_jsx(Text, { color: "gray", children: "ID: " }), _jsx(Text, { color: "cyan", children: task.conversation_id }), _jsx(Text, { color: "gray", children: " | Status: " }), _jsx(Text, { color: getStatusColor(task.status), children: task.status }), _jsx(Text, { color: "gray", children: " | Created: " }), _jsx(Text, { color: "blue", children: formatDate(task.created_at) })] })] }) }) }, task.conversation_id)))) }), _jsx(Box, { borderStyle: "single", borderColor: "gray", paddingX: 1, children: _jsxs(Text, { color: "gray", children: [tasks.length > 0 ? '↑↓ Navigate • Enter Select • ' : '', "ESC Back \u2022 Q Quit"] }) })] }));
};
export default TasksTUI;
//# sourceMappingURL=TasksTUI.js.map