Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setLoading needs to split #46 -- resolved #47

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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