Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | 1x 12x 1x 1x 2x 1x 4x 4x 4x 4x 4x 12x | import { encodeResourceId } from "@/components/detail";
import React, { useMemo, useState } from "react";
import { Link } from "react-router-dom";
import { Project } from "@/objects/Project";
import { APP_ROUTES, ROUTE_PARAMS } from "@/routes/const";
import { FolderKanban, Search, ChevronRight, Calendar } from "lucide-react";
import { parseServerDate } from "@/util/time";
export interface ProjectsGridProps {
projects: Project[];
loading?: boolean;
}
// ─── Skeleton card ────────────────────────────────────────────────────────────
const SkeletonCard: React.FC = () => (
<div className="rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-5 space-y-3 animate-pulse">
<div className="flex items-start justify-between">
<div className="flex items-center gap-3">
<div className="size-9 rounded-lg bg-gray-200 dark:bg-gray-700" />
<div className="space-y-1.5">
<div className="h-4 w-40 rounded bg-gray-200 dark:bg-gray-700" />
<div className="h-3 w-24 rounded bg-gray-200 dark:bg-gray-700" />
</div>
</div>
</div>
<div className="h-3 w-full rounded bg-gray-200 dark:bg-gray-700" />
<div className="h-3 w-3/5 rounded bg-gray-200 dark:bg-gray-700" />
</div>
);
// ─── Project card ─────────────────────────────────────────────────────────────
const ProjectCard: React.FC<{ project: Project }> = ({ project }) => {
const href = APP_ROUTES.PROJECT.home.replace(ROUTE_PARAMS.PROJECT.id, encodeResourceId(project.id));
return (
<Link
to={href}
className="group flex flex-col rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shadow-sm hover:shadow-md hover:border-gray-300 dark:hover:border-gray-500 transition-all overflow-hidden"
>
<div className="flex-1 p-5 flex flex-col gap-4">
{/* Header */}
<div className="flex items-start justify-between gap-3">
<div className="flex items-center gap-3 min-w-0">
<div className="p-2 rounded-lg bg-gray-100 dark:bg-gray-700 shrink-0">
<FolderKanban className="size-5 text-gray-600 dark:text-gray-300" />
</div>
<div className="min-w-0">
<div className="text-sm font-semibold text-gray-900 dark:text-gray-100 truncate">
{project.name}
</div>
<div className="flex items-center gap-1 text-xs text-gray-400 dark:text-gray-500 mt-0.5">
<Calendar className="size-3" />
{project.created_at
? parseServerDate(project.created_at).toLocaleDateString(undefined, {
year: "numeric",
month: "short",
day: "numeric",
})
: "Project"}
</div>
</div>
</div>
<ChevronRight className="size-4 text-gray-300 dark:text-gray-600 shrink-0 mt-0.5 group-hover:text-gray-500 dark:group-hover:text-gray-400 transition-colors" />
</div>
{/* Description */}
{project.description ? (
<p className="text-xs text-gray-400 dark:text-gray-500 line-clamp-2 leading-relaxed">
{project.description}
</p>
) : (
<p className="text-xs text-gray-300 dark:text-gray-600 italic">No description.</p>
)}
</div>
</Link>
);
};
// ─── Empty state ──────────────────────────────────────────────────────────────
const EmptyState: React.FC<{ filtered: boolean }> = ({ filtered }) => (
<div className="col-span-3 flex flex-col items-center justify-center py-16 text-center">
<div className="p-4 rounded-full bg-gray-100 dark:bg-gray-700 mb-4">
<FolderKanban className="size-8 text-gray-400 dark:text-gray-500" />
</div>
<p className="text-sm font-medium text-gray-600 dark:text-gray-400">
{filtered ? "No projects match your search." : "No projects yet."}
</p>
<p className="text-xs text-gray-400 dark:text-gray-500 mt-1">
{filtered
? "Try adjusting your search."
: "Create a project to organise your agents, knowledge and rules."}
</p>
</div>
);
// ─── ProjectsGrid ─────────────────────────────────────────────────────────────
const ProjectsGrid: React.FC<ProjectsGridProps> = ({ projects, loading }) => {
const [search, setSearch] = useState("");
const filtered = useMemo(() => {
const q = search.trim().toLowerCase();
Eif (!q) return projects;
return projects.filter(
(p) =>
p.name.toLowerCase().includes(q) ||
(p.description ?? "").toLowerCase().includes(q),
);
}, [projects, search]);
return (
<div className="space-y-4">
{/* Toolbar */}
<div className="flex items-center gap-3">
<div className="relative w-full sm:w-64">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 size-3.5 text-gray-400 pointer-events-none" />
<input
type="text"
placeholder="Search projects…"
value={search}
onChange={(e) => setSearch(e.target.value)}
className="w-full pl-8 pr-3 py-2 text-sm rounded-lg border border-gray-200 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-300 dark:focus:ring-gray-500"
/>
</div>
</div>
{/* Summary */}
{!loading && projects.length > 0 && (
<p className="text-xs text-gray-400 dark:text-gray-500">
{filtered.length} of {projects.length} project{projects.length !== 1 ? "s" : ""}
{search ? " (filtered)" : ""}
</p>
)}
{/* Grid */}
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
{loading ? (
Array.from({ length: 6 }).map((_, i) => <SkeletonCard key={i} />)
) : filtered.length === 0 ? (
<EmptyState filtered={!!search} />
) : (
filtered.map((project) => <ProjectCard key={project.id} project={project} />)
)}
</div>
</div>
);
};
export default ProjectsGrid;
|