mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 05:25:44 +01:00
get contextType
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user