import type { ReactIsland } from "@ethicdevs/react-monolith";
import React from "react";
import type { Organization, Repository } from "@prisma/client";
import type { WithThemeSchemeProp } from "../types";
import { AppRoute } from "../routes.defs";
import { Card } from "../components/Card.styled";
import { Grid } from "../components/Grid";
import { buildRouteLink } from "../utils/shared";
import { NamedColors } from "../utils/style";
export interface RepositoriesListProps {
repositories: (Repository & { parentOrg: Organization })[];
}
const RepositoriesList: ReactIsland<
RepositoriesListProps & WithThemeSchemeProp
> = ({ repositories, themeScheme }) => {
return (
<>
{repositories.map((repo, idx) => (
<Card
key={repo.id}
themeScheme={themeScheme}
style={{ marginTop: idx >= 1 ? 4 : 16 }}
>
<Grid.Row fluid nowrap>
<h1 style={{ margin: 0, flex: 1 }}>
<a
href={buildRouteLink(AppRoute.REPOSITORY_DETAILS, {
orgSlug: repo.parentOrg.slug,
repoSlug: repo.slug,
})}
>
{repo.parentOrg.displayName || repo.parentOrg.slug}
{" / "}
{repo.displayName || repo.slug}
{" ∙ "}
<span style={{ textTransform: "capitalize" }}>
({repo.visibility.toLowerCase()})
</span>
</a>
</h1>
{repo.isFork && (
<p style={{ margin: 0, marginTop: 8 }}>
<code>[fork]</code>
</p>
)}
</Grid.Row>
<div>
<p style={{ margin: 0, marginTop: 8 }}>{repo.shortDescription}</p>
{repo.lastPushedAt != null && (
<p
style={{
margin: 0,
marginTop: 8,
fontSize: 14,
color: NamedColors.TEXT_MUTED[themeScheme],
}}
>
Last push: {new Date(repo.lastPushedAt).toLocaleString()}
</p>
)}
</div>
</Card>
))}
</>
);
};
RepositoriesList.displayName = "RepositoriesList";
export default RepositoriesList;