From 758b6e3467ccb9b110c5d10214ee2b068cce2d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maren=20S=C3=BCwer?= Date: Thu, 11 Oct 2018 10:27:57 +0200 Subject: [PATCH] fetch index resources at beginning --- scm-ui/src/containers/Index.js | 81 ++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 scm-ui/src/containers/Index.js diff --git a/scm-ui/src/containers/Index.js b/scm-ui/src/containers/Index.js new file mode 100644 index 0000000000..d894215fab --- /dev/null +++ b/scm-ui/src/containers/Index.js @@ -0,0 +1,81 @@ +// @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 { + fetchMe +} from "../modules/auth"; + +import { + Loading, + ErrorPage, +} from "@scm-manager/ui-components"; +import { + fetchIndexResources, + getFetchIndexResourcesFailure, + isFetchIndexResourcesPending +} from "../modules/indexResource"; + +type Props = { + error: Error, + loading: boolean, + + // dispatcher functions + fetchIndexResources: () => void, + + // context props + t: string => string +}; + +class Index extends Component { + componentDidMount() { + this.props.fetchIndexResources(); + } + + render() { + const { + loading, + error, + t, + } = this.props; + + if (loading) { + return ; + } else if (error) { + return ( + + ); + } else { + return ; + } + } +} + +const mapDispatchToProps = (dispatch: any) => { + return { + fetchMe: (link: string) => dispatch(fetchMe(link)), + fetchIndexResources: () => dispatch(fetchIndexResources()) + }; +}; + +const mapStateToProps = state => { + const loading = isFetchIndexResourcesPending(state); + const error = getFetchIndexResourcesFailure(state); + return { + loading, + error + }; +}; + +export default withRouter( + connect( + mapStateToProps, + mapDispatchToProps + )(translate("commons")(Index)) +);