import type { ReactView } from "@ethicdevs/react-monolith";
import React from "react";
import type { Organization, Repository } from "@prisma/client";
import type {
CommonProps,
RepositoryFileDiff,
RepositoryObject,
} from "../../types";
import { Card, Code, Layout, PageWrapper } from "../../components";
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 }}
themeScheme={commonProps.themeScheme}
>
<RepositoryCommitSummaryLine
orgSlug={parentOrg.slug}
repoSlug={repo.slug}
commit={gitObject}
/>
</Card>
{gitObject.body.trim() !== "" && (
<Card
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;