Files
SCM-Manager/scm-ui/src/containers/Index.js

81 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-10-11 10:27:57 +02:00
// @flow
import React, { Component } from "react";
import App from "./App";
import { connect } from "react-redux";
import { translate } from "react-i18next";
import { withRouter } from "react-router-dom";
import { Loading, ErrorPage } from "@scm-manager/ui-components";
2018-10-11 10:27:57 +02:00
import {
fetchIndexResources,
getFetchIndexResourcesFailure,
getLinks,
2018-10-11 10:27:57 +02:00
isFetchIndexResourcesPending
} from "../modules/indexResource";
import PluginLoader from "./PluginLoader";
2018-10-11 10:27:57 +02:00
type Props = {
error: Error,
loading: boolean,
indexResources: any,
2018-10-11 10:27:57 +02:00
// dispatcher functions
fetchIndexResources: () => void,
// context props
t: string => string
};
class Index extends Component<Props> {
componentDidMount() {
this.props.fetchIndexResources();
}
render() {
const { indexResources, loading, error, t } = this.props;
2018-10-11 10:27:57 +02:00
if (error) {
2018-10-11 10:27:57 +02:00
return (
<ErrorPage
title={t("app.error.title")}
subtitle={t("app.error.subtitle")}
error={error}
/>
);
}
else if (loading || !indexResources) {
return <Loading />;
} else {
return (
<PluginLoader>
<App />
</PluginLoader>
);
2018-10-11 10:27:57 +02:00
}
}
}
const mapDispatchToProps = (dispatch: any) => {
return {
fetchIndexResources: () => dispatch(fetchIndexResources())
};
};
const mapStateToProps = state => {
const loading = isFetchIndexResourcesPending(state);
const error = getFetchIndexResourcesFailure(state);
const indexResources = getLinks(state);
2018-10-11 10:27:57 +02:00
return {
loading,
error,
indexResources
2018-10-11 10:27:57 +02:00
};
};
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(translate("commons")(Index))
);