GitFOSS
.ts
TypeScript
(application/typescript)
// 1st-party
import type { ReactView } 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 {
  CommonProps,
  RepositoryFileDiff,
  RepositoryObject,
} from "../../types";
import { Card, Layout, PageWrapper } from "../../components";
// app islands
import Code, { getThemedCodeCss } from "../../islands/Code";
import RepositoryCommitSummaryLine from "../../islands/RepositoryCommitSummaryLine";
import RepositoryFilesDiffsList from "../../islands/RepositoryFilesDiffsList";

export interface RepositoryShowObjectViewProps extends CommonProps {
  gitObject: RepositoryObject;
  gitObjectDiffs: RepositoryFileDiff[] | null;
  parentOrg: Organization;
  repo: Repository;
}

const RepositoryShowObjectView: ReactView<RepositoryShowObjectViewProps> = ({
  commonProps,
  gitObject,
  gitObjectDiffs,
  parentOrg,
  repo,
}) => {
  return (
    <Layout {...commonProps}>
      <PageWrapper>
        <h1>
          <a href={`/${parentOrg.slug}`}>
            {parentOrg.displayName || parentOrg.slug}
          </a>
          {" / "}
          <a href={`/${parentOrg.slug}/${repo.slug}`}>
            {repo.displayName || repo.slug}
          </a>
          {" / Show / "}
          <span>{gitObject.abbreviated_commit}</span>
        </h1>
        <Card
          data-islandid={`${RepositoryCommitSummaryLine.name}$$0`}
          style={{ width: "100%", marginTop: 32, padding: 8 }}
          themeScheme={commonProps.themeScheme}
        >
          <RepositoryCommitSummaryLine
            orgSlug={parentOrg.slug}
            repoSlug={repo.slug}
            commit={gitObject}
          />
        </Card>
        {gitObject.body.trim() !== "" && (
          <>
            {getThemedCodeCss(commonProps.themeScheme)}
            <Card
              data-islandid={`${Code.name}$$0`}
              style={{ width: "100%", marginTop: 32 }}
              themeScheme={commonProps.themeScheme}
            >
              <Code
                language={"plain"}
                code={gitObject.body}
                themeScheme={commonProps.themeScheme}
              />
            </Card>
          </>
        )}
        {gitObjectDiffs != null && (
          <Card
            data-islandid={`${RepositoryFilesDiffsList.name}$$0`}
            style={{ width: "100%", marginTop: 16 }}
            themeScheme={commonProps.themeScheme}
          >
            <RepositoryFilesDiffsList
              filesDiffs={gitObjectDiffs}
              themeScheme={commonProps.themeScheme}
              orgSlug={parentOrg.slug}
              repoSlug={repo.slug}
              commitHash={gitObject.commit}
            />
          </Card>
        )}
      </PageWrapper>
    </Layout>
  );
};

RepositoryShowObjectView.displayName = "RepositoryShowObjectView";
export default RepositoryShowObjectView;