@graphteon/juricode
Version:
We are forging the future with lines of digital steel
138 lines • 10.1 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 open_hands_1 = __importDefault(require("../api/open-hands"));
const RepositoriesTUI = ({ onBack, onSelectRepository }) => {
const [repositories, setRepositories] = (0, react_1.useState)([]);
const [filteredRepos, setFilteredRepos] = (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 [searchMode, setSearchMode] = (0, react_1.useState)(false);
const [searchTerm, setSearchTerm] = (0, react_1.useState)('');
const [showBranches, setShowBranches] = (0, react_1.useState)(false);
const [branches, setBranches] = (0, react_1.useState)([]);
const [selectedBranchIndex, setSelectedBranchIndex] = (0, react_1.useState)(0);
const [loadingBranches, setLoadingBranches] = (0, react_1.useState)(false);
const { exit } = (0, ink_1.useApp)();
(0, react_1.useEffect)(() => {
const fetchRepositories = async () => {
try {
setLoading(true);
const repos = await open_hands_1.default.retrieveUserGitRepositories();
setRepositories(repos);
setFilteredRepos(repos);
setError(null);
}
catch (err) {
setError(err instanceof Error ? err.message : 'Failed to fetch repositories');
}
finally {
setLoading(false);
}
};
fetchRepositories();
}, []);
(0, react_1.useEffect)(() => {
if (searchTerm) {
const filtered = repositories.filter(repo => repo.full_name.toLowerCase().includes(searchTerm.toLowerCase()));
setFilteredRepos(filtered);
setSelectedIndex(0);
}
else {
setFilteredRepos(repositories);
}
}, [searchTerm, repositories]);
const fetchBranches = async (repo) => {
try {
setLoadingBranches(true);
const repoBranches = await open_hands_1.default.getRepositoryBranches(repo.full_name);
setBranches(repoBranches);
setSelectedBranchIndex(0);
setShowBranches(true);
}
catch (err) {
setError(err instanceof Error ? err.message : 'Failed to fetch branches');
}
finally {
setLoadingBranches(false);
}
};
(0, ink_1.useInput)((input, key) => {
if (key.escape) {
if (showBranches) {
setShowBranches(false);
setBranches([]);
return;
}
if (searchMode) {
setSearchMode(false);
setSearchTerm('');
return;
}
onBack();
return;
}
if (loading || loadingBranches)
return;
if (searchMode) {
if (key.return) {
setSearchMode(false);
return;
}
if (key.backspace || key.delete) {
setSearchTerm(prev => prev.slice(0, -1));
return;
}
if (input && input.length === 1) {
setSearchTerm(prev => prev + input);
return;
}
return;
}
if (showBranches) {
if (key.upArrow && selectedBranchIndex > 0) {
setSelectedBranchIndex(selectedBranchIndex - 1);
}
if (key.downArrow && selectedBranchIndex < branches.length - 1) {
setSelectedBranchIndex(selectedBranchIndex + 1);
}
if (key.return && branches.length > 0) {
const selectedRepo = filteredRepos[selectedIndex];
const selectedBranch = branches[selectedBranchIndex].name;
onSelectRepository(selectedRepo, selectedBranch);
}
return;
}
if (key.upArrow && selectedIndex > 0) {
setSelectedIndex(selectedIndex - 1);
}
if (key.downArrow && selectedIndex < filteredRepos.length - 1) {
setSelectedIndex(selectedIndex + 1);
}
if (key.return && filteredRepos.length > 0) {
const selectedRepo = filteredRepos[selectedIndex];
fetchBranches(selectedRepo);
}
if (input === 's') {
setSearchMode(true);
}
if (input === 'q') {
exit();
}
});
const truncateText = (text, maxLength) => {
return text.length > maxLength ? text.substring(0, maxLength) + '...' : text;
};
if (showBranches) {
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.jsxs)(ink_1.Text, { color: "blue", bold: true, children: ["\uD83C\uDF3F Select Branch - ", filteredRepos[selectedIndex]?.full_name] }) }), (0, jsx_runtime_1.jsx)(ink_1.Box, { flexDirection: "column", flexGrow: 1, paddingX: 1, paddingY: 1, children: loadingBranches ? ((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 branches..." }) })) : branches.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 branches found." }) })) : (branches.map((branch, index) => ((0, jsx_runtime_1.jsx)(ink_1.Box, { marginBottom: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Box, { borderStyle: "single", borderColor: index === selectedBranchIndex ? '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 === selectedBranchIndex ? 'green' : 'white', bold: true, children: [index === selectedBranchIndex ? '▶ ' : ' ', branch.name, branch.protected && (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "red", children: " \uD83D\uDD12" })] }) }), branch.last_push_date && ((0, jsx_runtime_1.jsxs)(ink_1.Box, { marginTop: 1, children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: "gray", children: "Last push: " }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "blue", children: new Date(branch.last_push_date).toLocaleDateString() })] }))] }) }) }, branch.name)))) }), (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: [branches.length > 0 ? '↑↓ Navigate • Enter Select • ' : '', "ESC Back \u2022 Q Quit"] }) })] }));
}
return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", height: "100%", children: [(0, jsx_runtime_1.jsxs)(ink_1.Box, { borderStyle: "single", borderColor: "blue", paddingX: 1, children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: "blue", bold: true, children: "\uD83D\uDCDA Browse Repositories" }), searchMode && ((0, jsx_runtime_1.jsxs)(ink_1.Text, { color: "yellow", children: [" - Search: ", searchTerm, "\u2588"] }))] }), (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 repositories..." }) })) : 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] }) })) : filteredRepos.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: searchTerm ? `No repositories found matching "${searchTerm}"` : 'No repositories found.' }) })) : (filteredRepos.map((repo, 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 ? '▶ ' : ' ', repo.full_name, repo.stargazers_count && repo.stargazers_count > 0 && ((0, jsx_runtime_1.jsxs)(ink_1.Text, { color: "yellow", children: [" \u2605", repo.stargazers_count] }))] }) }), (0, jsx_runtime_1.jsxs)(ink_1.Box, { marginTop: 1, children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { color: "gray", children: "Provider: " }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "blue", children: repo.git_provider }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: "gray", children: " | " }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: repo.is_public ? 'green' : 'yellow', children: repo.is_public ? 'Public' : 'Private' })] })] }) }) }, repo.full_name)))) }), (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: [filteredRepos.length > 0 ? '↑↓ Navigate • Enter Select • ' : '', "S Search \u2022 ESC Back \u2022 Q Quit"] }) })] }));
};
exports.default = RepositoriesTUI;
//# sourceMappingURL=RepositoriesTUI.js.map