import type { ReactView } from "@ethicdevs/react-monolith";
import React from "react";
import type { Organization, User } from "@prisma/client";
import type {
CommonProps,
LinguistFileInfos,
RepositoryFileContent,
RepositoryLog,
RepositoryWithForkedFromRepo,
} from "../../types";
import {
Grid,
Layout,
PageWrapper,
Card,
IslandWrapper,
} from "../../components";
import Code, { getThemedCodeCss } from "../../islands/Code";
import RepositoryCommitSummaryLine from "../../islands/RepositoryCommitSummaryLine";
import RepositoryHero from "../../islands/RepositoryHero";
export interface RepositoryBrowserViewProps extends CommonProps {
currentRef: string;
currentUser: null | User;
fileContent: RepositoryFileContent;
lastCommit: null | RepositoryLog;
linguistInfos: LinguistFileInfos;
parentOrg: Organization;
path: string;
repo: RepositoryWithForkedFromRepo;
}
const RepositoryBrowserView: ReactView<RepositoryBrowserViewProps> = ({
commonProps,
currentRef,
fileContent,
lastCommit,
linguistInfos,
parentOrg,
path,
repo,
}) => {
return (
<Layout {...commonProps}>
<PageWrapper>
<IslandWrapper data-islandid={`${RepositoryHero.name}$$0`}>
<RepositoryHero
forkedFromRepo={repo.forkedFromRepo}
forksCount={repo.forks.length}
parentOrg={parentOrg}
path={path}
repo={repo}
separator={"/"}
/>
</IslandWrapper>
<Grid.Col fluid style={{ marginTop: 32 }}>
{lastCommit && (
<Card
data-islandid={`${RepositoryCommitSummaryLine.name}$$0`}
style={{ width: "100%", padding: 8 }}
themeScheme={commonProps.themeScheme}
>
<RepositoryCommitSummaryLine
commit={lastCommit}
currentRef={currentRef}
orgSlug={parentOrg.slug}
repoSlug={repo.slug}
/>
</Card>
)}
<Card
style={{ width: "100%", marginTop: lastCommit != null ? 16 : 0 }}
themeScheme={commonProps.themeScheme}
>
<Grid.Row nowrap alignItems={"center"} style={{ width: "100%" }}>
<div>
<strong>lang:</strong> <span>{linguistInfos.language}</span>
</div>
<div style={{ marginLeft: 16 }}>
<strong>mime:</strong> <span>{linguistInfos.mimeType}</span>
</div>
</Grid.Row>
</Card>
{linguistInfos.type === "image" ? (
<Card
style={{ width: "100%", marginTop: 16 }}
themeScheme={commonProps.themeScheme}
>
<img
src={fileContent.content}
style={{ width: "100%", height: "auto" }}
/>
</Card>
) : (
<>
{getThemedCodeCss(commonProps.themeScheme)}
<Card
data-islandid={`${Code.name}$$0`}
style={{ width: "100%", marginTop: 16 }}
themeScheme={commonProps.themeScheme}
>
<Code
code={fileContent.content}
language={linguistInfos.language}
themeScheme={commonProps.themeScheme}
/>
</Card>
</>
)}
</Grid.Col>
</PageWrapper>
</Layout>
);
};
RepositoryBrowserView.displayName = "RepositoryBrowserView";
export default RepositoryBrowserView;