GitFOSS
.ts
TypeScript
(application/typescript)
// 1st-party
import type { ReactIsland } from "@ethicdevs/react-monolith";
// 3rd-party
import React from "react";
// generated via script[generate:prisma]
import type { Organization, Repository } from "@prisma/client";
// app
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";

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 ? 16 : 32 }}
        >
          <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 }}>
                Last push: {new Date(repo.lastPushedAt).toLocaleString()}
              </p>
            )}
          </div>
        </Card>
      ))}
    </>
  );
};

RepositoriesList.displayName = "RepositoriesList";
export default RepositoriesList;