GitFOSS
.ts
TypeScript
(application/typescript)
// 1st-party
import type { ReactView } from "@ethicdevs/react-monolith";
// 3rd-party
import React from "react";
// generated via script[prisma:generate]
import type { Organization, Repository, User } from "@prisma/client";
// app service
import type { LinguistFileInfos } from "../../services/codeAnalysis/types";
// app
import type {
  CommonProps,
  RepositoryFileContent,
  RepositoryLog,
} from "../../types";
import { Grid, Layout, PageWrapper, Card } from "../../components";
// app islands
import Code, { getThemedCodeCss } from "../../islands/Code";
import RepositoryCommitSummaryLine from "../../islands/RepositoryCommitSummaryLine";

export interface RepositoryBrowserViewProps extends CommonProps {
  currentRef: string;
  currentUser: null | User;
  fileContent: RepositoryFileContent;
  lastCommit: null | RepositoryLog;
  linguistInfos: LinguistFileInfos;
  parentOrg: Organization;
  path: string;
  repo: Repository;
}

const RepositoryBrowserView: ReactView<RepositoryBrowserViewProps> = ({
  commonProps,
  currentRef,
  fileContent,
  lastCommit,
  linguistInfos,
  parentOrg,
  path,
  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>
          {" / "}
          {path}
        </h1>
        <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;