UNPKG

gensx

Version:
70 lines 3.6 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Box, Text, useApp } from "ink"; import { useEffect, useState } from "react"; import { ErrorMessage } from "../../components/ErrorMessage.js"; import { LoadingSpinner } from "../../components/LoadingSpinner.js"; import { listProjects } from "../../models/projects.js"; import { getAuth } from "../../utils/config.js"; function useProjects() { const [projects, setProjects] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const { exit } = useApp(); useEffect(() => { let mounted = true; async function fetchData() { try { // Check authentication first const authConfig = await getAuth(); if (!authConfig) { throw new Error("Not authenticated. Please run 'gensx login' first."); } // Fetch projects const projectList = await listProjects(); if (mounted) { setProjects(projectList); setLoading(false); } } catch (err) { if (mounted) { const error = err instanceof Error ? err : new Error(String(err)); setError(error); setLoading(false); setTimeout(() => { exit(); }, 100); } } } void fetchData(); return () => { mounted = false; }; }, [exit]); return { projects, loading, error, }; } export function ListProjectsUI() { const { projects, loading, error } = useProjects(); if (error) { return _jsx(ErrorMessage, { message: error.message }); } if (loading) { return _jsx(LoadingSpinner, {}); } return (_jsxs(Box, { flexDirection: "column", gap: 1, children: [_jsx(Box, { children: _jsxs(Text, { children: ["Found", " ", _jsx(Text, { bold: true, color: "cyan", children: projects.length }), " ", "project", projects.length === 1 ? "" : "s"] }) }), projects.length > 0 ? (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "─".repeat(54) }), _jsx(Box, { paddingLeft: 1, children: _jsxs(Text, { bold: true, children: [_jsx(Text, { color: "cyan", children: "NAME".padEnd(30) }), _jsx(Text, { color: "cyan", children: "UPDATED AT" })] }) }), _jsx(Text, { children: "─".repeat(54) }), _jsx(Box, { flexDirection: "column", children: projects.map((project) => (_jsx(Box, { paddingLeft: 1, children: _jsxs(Text, { children: [_jsx(Text, { color: "green", children: project.name.padEnd(30) }), _jsx(Text, { dimColor: true, children: new Date(project.updatedAt) .toLocaleString(undefined, { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", hour12: true, }) .replace(/,/, "") })] }) }, project.id))) }), _jsx(Text, { children: "─".repeat(54) })] })) : (_jsx(Box, { children: _jsx(Text, { dimColor: true, children: "No projects found" }) }))] })); } //# sourceMappingURL=list.js.map