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