Added rates containers + cached language selection
This commit is contained in:
@@ -2,6 +2,7 @@ import React, { useEffect, Suspense, lazy, useState } from "react";
|
||||
import { useApolloClient, useQuery } from "@apollo/react-hooks";
|
||||
import { Switch, Route, Redirect } from "react-router-dom";
|
||||
import firebase from "../firebase/firebase.utils";
|
||||
import i18next from "i18next";
|
||||
|
||||
import "./App.css";
|
||||
|
||||
@@ -12,7 +13,7 @@ import ErrorBoundary from "../components/error-boundary/error-boundary.component
|
||||
|
||||
import { auth } from "../firebase/firebase.utils";
|
||||
import { UPSERT_USER } from "../graphql/user.queries";
|
||||
import { GET_CURRENT_USER } from "../graphql/local.queries";
|
||||
import { GET_CURRENT_USER, GET_LANGUAGE } from "../graphql/local.queries";
|
||||
// import { QUERY_BODYSHOP } from "../graphql/bodyshop.queries";
|
||||
|
||||
import PrivateRoute from "../utils/private-route";
|
||||
@@ -89,11 +90,23 @@ export default () => {
|
||||
};
|
||||
}, [apolloClient]);
|
||||
const HookCurrentUser = useQuery(GET_CURRENT_USER);
|
||||
const HookLanguage = useQuery(GET_LANGUAGE);
|
||||
|
||||
if (!loaded) return <LoadingSpinner />;
|
||||
if (HookCurrentUser.loading) return <LoadingSpinner />;
|
||||
if (HookCurrentUser.error)
|
||||
return <AlertComponent message={HookCurrentUser.error.message} />;
|
||||
if (HookCurrentUser.loading || HookLanguage.loading)
|
||||
return <LoadingSpinner />;
|
||||
if (HookCurrentUser.error || HookLanguage.error)
|
||||
return (
|
||||
<AlertComponent
|
||||
message={HookCurrentUser.error.message || HookLanguage.error.message}
|
||||
/>
|
||||
);
|
||||
|
||||
if (HookLanguage.data.language)
|
||||
i18next.changeLanguage(HookLanguage.data.language, (err, t) => {
|
||||
if (err)
|
||||
return console.log("Error encountered when changing languages.", err);
|
||||
});
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user