// @flow import React from "react"; import { translate } from "react-i18next"; import { getSources } from "../modules/sources"; import type { File, Repository } from "@scm-manager/ui-types"; import { DateFromNow, ErrorNotification, Loading } from "@scm-manager/ui-components"; import { connect } from "react-redux"; import ImageViewer from "../components/content/ImageViewer"; import SourcecodeViewer from "../components/content/SourcecodeViewer"; import DownloadViewer from "../components/content/DownloadViewer"; import FileSize from "../components/FileSize"; import injectSheet from "react-jss"; import classNames from "classnames"; import { ExtensionPoint } from "@scm-manager/ui-extensions"; import { getContentType } from "./contentType"; type Props = { loading: boolean, error: Error, file: File, repository: Repository, revision: string, path: string, classes: any, t: string => string }; type State = { contentType: string, language: string, loaded: boolean, collapsed: boolean, error?: Error }; const styles = { toCenterContent: { display: "block" }, pointer: { cursor: "pointer" } }; class Content extends React.Component { constructor(props: Props) { super(props); this.state = { contentType: "", language: "", loaded: false, collapsed: true }; } componentDidMount() { const { file } = this.props; getContentType(file._links.self.href) .then(result => { if (result.error) { this.setState({ ...this.state, error: result.error, loaded: true }); } else { this.setState({ ...this.state, contentType: result.type, language: result.language, loaded: true }); } }) .catch(err => {}); } toggleCollapse = () => { this.setState(prevState => ({ collapsed: !prevState.collapsed })); }; showHeader() { const { file, classes, t } = this.props; const collapsed = this.state.collapsed; const icon = collapsed ? "fa-angle-right" : "fa-angle-down"; return ( ); } showMoreInformation() { const collapsed = this.state.collapsed; const { classes, file, revision, t } = this.props; const date = ; const description = file.description ? (

{file.description.split("\n").map((item, key) => { return ( {item}
); })}

) : null; const fileSize = file.directory ? "" : ; if (!collapsed) { return (
{t("sources.content.path")} {file.path}
{t("sources.content.branch")} {revision}
{t("sources.content.size")} {fileSize}
{t("sources.content.lastModified")} {date}
{t("sources.content.description")} {description}
); } return null; } showContent() { const { file, revision } = this.props; const { contentType, language } = this.state; if (contentType.startsWith("image/")) { return ; } else if (language) { return ; } else if (contentType.startsWith("text/")) { return ; } else { return ( ); } } render() { const { file, classes } = this.props; const { loaded, error } = this.state; if (!file || !loaded) { return ; } if (error) { return ; } const header = this.showHeader(); const content = this.showContent(); const moreInformation = this.showMoreInformation(); return (
); } } const mapStateToProps = (state: any, ownProps: Props) => { const { repository, revision, path } = ownProps; const file = getSources(state, repository, revision, path); return { file }; }; export default injectSheet(styles)( connect(mapStateToProps)(translate("repos")(Content)) );