get contextType

This commit is contained in:
Maren Süwer
2018-10-25 13:45:52 +02:00
parent 20df283b08
commit c7684b835a
3 changed files with 56 additions and 11 deletions

View File

@@ -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<Response> {

View File

@@ -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<Props, State> {
};
}
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 <Loading />;
}
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));

View File

@@ -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<Props> {
</>
);
} else {
return <Content />;
return <Content
repository={repository}
revision={revision}
path={path}
/>;
}
}
@@ -140,7 +144,7 @@ const mapStateToProps = (state, ownProps) => {
loading,
error,
branches,
currentFileIsDirectory
currentFileIsDirectory,
};
};