Skip to content

Commit

Permalink
setLoading needs to split nz-m#46 -- resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasant79 committed Feb 17, 2024
1 parent 4dc6c78 commit 34ae853
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions client/src/AppContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import { Helmet } from "react-helmet";
import { useLocation } from "react-router-dom";

const ErrorComponent = ({ errorMessage }) => (
<div className="text-red-500 font-bold text-center">{errorMessage}</div>
<div className="text-center font-bold text-red-500">{errorMessage}</div>
);

const AppContainer = () => {
const location = useLocation();
const [store, setStore] = useState(null);
const [loading, setLoading] = useState(true);
const [storeloading, setStoreloading] = useState(true);
const [serverStatus, setServerStatus] = useState(true);
const [error, setError] = useState(null);

useEffect(() => {
Expand All @@ -25,7 +26,7 @@ const AppContainer = () => {
} catch (err) {
setError("Server is down. Please try again later.");
} finally {
setLoading(false);
setServerStatus(false);
}
};

Expand All @@ -43,17 +44,21 @@ const AppContainer = () => {
} catch (err) {
setError(`Error initializing the app: ${err.message}`);
} finally {
setLoading(false);
setStoreloading(false);
}
};

initializeStore();
}, []);

if (loading || error) {
if ((storeloading && serverStatus && !error) || error) {
return (
<div className="flex items-center justify-center h-screen">
{loading ? <CommonLoading /> : <ErrorComponent errorMessage={error} />}
<div className="flex h-screen items-center justify-center">
{storeloading && serverStatus && !error ? (
<CommonLoading />
) : (
<ErrorComponent errorMessage={error} />
)}
</div>
);
}
Expand Down

0 comments on commit 34ae853

Please sign in to comment.