import { useMemo } from "react"; import { Card } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Plus, RefreshCw, Building2 } from "lucide-react"; import { SiGithub } from "react-icons/si"; import type { Organization } from "@/lib/db/schema"; import type { FilterParams } from "@/types/filter"; import Fuse from "fuse.js"; import { Skeleton } from "@/components/ui/skeleton"; import { Checkbox } from "@/components/ui/checkbox"; import { getStatusColor } from "@/lib/utils"; interface OrganizationListProps { organizations: Organization[]; isLoading: boolean; filter: FilterParams; setFilter: (filter: FilterParams) => void; onMirror: ({ orgId }: { orgId: string }) => Promise; loadingOrgIds: Set; onAddOrganization?: () => void; } export function OrganizationList({ organizations, isLoading, filter, setFilter, onMirror, loadingOrgIds, onAddOrganization, }: OrganizationListProps) { const hasAnyFilter = Object.values(filter).some( (val) => val?.toString().trim() !== "" ); const filteredOrganizations = useMemo(() => { let result = organizations; if (filter.membershipRole) { result = result.filter((org) => org.membershipRole === filter.membershipRole); } if (filter.status) { result = result.filter((org) => org.status === filter.status); } if (filter.searchTerm) { const fuse = new Fuse(result, { keys: ["name", "type"], threshold: 0.3, }); result = fuse.search(filter.searchTerm).map((res) => res.item); } return result; }, [organizations, filter]); return isLoading ? (
{Array.from({ length: 5 }).map((_, i) => ( ))}
) : filteredOrganizations.length === 0 ? (

No organizations found

{hasAnyFilter ? "Try adjusting your search or filter criteria." : "Add GitHub organizations to mirror their repositories."}

{hasAnyFilter ? ( ) : ( )}
) : (
{filteredOrganizations.map((org, index) => { const isLoading = loadingOrgIds.has(org.id ?? ""); return (
{org.membershipRole} {/* needs to be updated */}
{org.repositoryCount}{" "} {org.repositoryCount === 1 ? "repository" : "repositories"}
{(org.publicRepositoryCount !== undefined || org.privateRepositoryCount !== undefined || org.forkRepositoryCount !== undefined) && (
{org.publicRepositoryCount !== undefined && (
{org.publicRepositoryCount} public )} {org.privateRepositoryCount !== undefined && org.privateRepositoryCount > 0 && (
{org.privateRepositoryCount} private )} {org.forkRepositoryCount !== undefined && org.forkRepositoryCount > 0 && (
{org.forkRepositoryCount} fork{org.forkRepositoryCount !== 1 ? 's' : ''} )}
)}
{ if (checked && !org.isIncluded && org.id) { onMirror({ orgId: org.id }); } }} /> {isLoading && ( )}
{/* dont know if this looks good. maybe revised */}
{org.status}
); })}
); }