diff --git a/scm-ui-components/packages/ui-components/src/apiclient.js b/scm-ui-components/packages/ui-components/src/apiclient.js index 4c648a59f6..bd19dcdf14 100644 --- a/scm-ui-components/packages/ui-components/src/apiclient.js +++ b/scm-ui-components/packages/ui-components/src/apiclient.js @@ -48,8 +48,12 @@ class ApiClient { return this.httpRequestWithJSONBody("PUT", url, contentType, payload); } - head(url: string, payload: any, contentType: string = "application/json") { - return this.httpRequestWithJSONBody("HEAD", url, contentType, payload); + head(url: string) { + let options: RequestOptions = { + method: "HEAD" + }; + options = Object.assign(options, fetchOptions); + return fetch(createUrl(url), options).then(handleStatusCode); } delete(url: string): Promise { diff --git a/scm-ui/src/repos/content/components/Content.js b/scm-ui/src/repos/content/components/Content.js index edf46454ae..ecd3352836 100644 --- a/scm-ui/src/repos/content/components/Content.js +++ b/scm-ui/src/repos/content/components/Content.js @@ -2,9 +2,23 @@ import React from "react"; import { translate } from "react-i18next"; import { apiClient } from "@scm-manager/ui-components"; +import { getSources } from "../../sources/modules/sources"; +import type { Repository, File } from "@scm-manager/ui-types"; +import { ErrorNotification, Loading } from "@scm-manager/ui-components"; +import { connect } from "react-redux"; type Props = { - t: string => string + t: string => string, + loading: boolean, + error: Error, + file: File, + repository: Repository, + revision: string, + path: string, + // context props + classes: any, + t: string => string, + match: any }; type State = { @@ -20,20 +34,43 @@ class Content extends React.Component { }; } - componentDidMount() {} + componentDidMount() { + const { file } = this.props; + getContentType(file._links.self.href).then(result => { + this.setState({ + contentType: result + }); + }); + } render() { - return "Hallo here is content"; + const { file } = this.props; + if (!file) { + return ; + } + return this.state.contentType; } } -export function getContentType(url: string) { +export function getContentType(url: string, state: any) { return apiClient .head(url) - .then(response => response.headers.get("Content-Type")) + .then(response => { + return response.headers.get("Content-Type"); + }) .catch(err => { return null; }); } -export default translate("repos")(Content); +const mapStateToProps = (state: any, ownProps: Props) => { + const { repository, revision, path } = ownProps; + + const file = getSources(state, repository, revision, path); + + return { + file + }; +}; + +export default connect(mapStateToProps)(translate("repos")(Content)); diff --git a/scm-ui/src/repos/sources/containers/Sources.js b/scm-ui/src/repos/sources/containers/Sources.js index a31a15353f..d27b2e24eb 100644 --- a/scm-ui/src/repos/sources/containers/Sources.js +++ b/scm-ui/src/repos/sources/containers/Sources.js @@ -14,7 +14,7 @@ import { } from "../../modules/branches"; import { compose } from "redux"; import Content from "../../content/components/Content"; -import { fetchSources, isDirectory } from "../modules/sources"; +import {fetchSources, isDirectory} from "../modules/sources"; type Props = { repository: Repository, @@ -102,7 +102,11 @@ class Sources extends React.Component { ); } else { - return ; + return ; } } @@ -140,7 +144,7 @@ const mapStateToProps = (state, ownProps) => { loading, error, branches, - currentFileIsDirectory + currentFileIsDirectory, }; };