import React from "react"; import { WithTranslation, withTranslation } from "react-i18next"; import SourcecodeViewer from "../components/content/SourcecodeViewer"; import ImageViewer from "../components/content/ImageViewer"; import MarkdownViewer from "../components/content/MarkdownViewer"; import DownloadViewer from "../components/content/DownloadViewer"; import { ExtensionPoint } from "@scm-manager/ui-extensions"; import { getContentType } from "./contentType"; import { File, Repository } from "@scm-manager/ui-types"; import { ErrorNotification, Loading, Button, Level } from "@scm-manager/ui-components"; import { Icon } from "@scm-manager/ui-components/src"; type Props = WithTranslation & { repository: Repository; file: File; revision: string; path: string; }; type State = { contentType: string; language: string; renderMarkdown: boolean; loaded: boolean; error?: Error; }; class SourcesView extends React.Component { constructor(props: Props) { super(props); this.state = { contentType: "", language: "", loaded: false, renderMarkdown: true }; } componentDidMount() { const { file } = this.props; getContentType(file._links.self.href) .then(result => { this.setState({ ...this.state, contentType: result.type, language: result.language, loaded: true }); }) .catch(error => { this.setState({ ...this.state, error, loaded: true }); }); } toggleMarkdown = () => { this.setState({ renderMarkdown: !this.state.renderMarkdown }); }; showSources() { const { file, revision } = this.props; const { contentType, language, renderMarkdown } = this.state; if (contentType.startsWith("image/")) { return ; } else if (contentType.includes("markdown")) { return ( <> } /> {renderMarkdown ? : } ); } else if (language) { return ; } else if (contentType.startsWith("text/")) { return ; } else { return ( ); } } render() { const { file } = this.props; const { loaded, error } = this.state; if (!file || !loaded) { return ; } if (error) { return ; } const sources = this.showSources(); return
{sources}
; } } export default withTranslation("repos")(SourcesView);