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

@@ -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));