BOD-36 #comment Issue encountered when changing loading status from parent container in App.Container.jsx. No issues when changing status from another component.

This commit is contained in:
Patrick Fic
2020-03-17 12:05:21 -07:00
parent ca457c76ab
commit b114a34bb5
5 changed files with 290 additions and 58 deletions

View File

@@ -13,12 +13,22 @@ import SpinnerComponent from "../components/loading-spinner/loading-spinner.comp
//import { shouldRefreshToken, refreshToken } from "../graphql/middleware";
import errorLink from "../graphql/apollo-error-handling";
import App from "./App";
import { connect } from "react-redux";
import {
endLoading,
startLoading
} from "../redux/application/application.actions";
const mapDispatchToProps = dispatch => ({
startLoading: () => dispatch(startLoading()),
endLoading: () => dispatch(endLoading())
});
class AppContainer extends Component {
state = {
client: null,
loaded: false
};
async componentDidMount() {
const httpLink = new HttpLink({
uri: process.env.REACT_APP_GRAPHQL_ENDPOINT
@@ -81,6 +91,24 @@ class AppContainer extends Component {
if (process.env.NODE_ENV === "development") {
middlewares.push(apolloLogger);
}
//New
// const startLoad = new ApolloLink((operation, forward) => {
// console.log("Starting", operation);
// this.props.startLoading();
// return forward(operation);
// });
// const endLoad = new ApolloLink((operation, forward) => {
// return forward(operation).map(response => {
// console.log("Completed", operation);
// this.props.endLoading();
// return response;
// });
// });
// middlewares.push(startLoad, endLoad);
//End new
middlewares.push(errorLink.concat(authLink.concat(link)));
const cache = new InMemoryCache();
@@ -101,7 +129,6 @@ class AppContainer extends Component {
render() {
const { client, loaded } = this.state;
if (!loaded) {
return <SpinnerComponent />;
}
@@ -114,4 +141,4 @@ class AppContainer extends Component {
}
}
export default AppContainer;
export default connect(null, mapDispatchToProps)(AppContainer);