= (props: Review) => {
{Array.from({ length: props.rating }).map((_, index) => (
- {}
+
))}
diff --git a/src/pages/home/HomePage.tsx b/src/pages/home/HomePage.tsx
index 176fe79..7704e05 100644
--- a/src/pages/home/HomePage.tsx
+++ b/src/pages/home/HomePage.tsx
@@ -1,13 +1,16 @@
import { useForm, Controller } from "react-hook-form";
-import { useEffect } from "react";
+import { useEffect, useState } from "react";
import { Link, useNavigate } from "react-router-dom";
import { useDispatch, useSelector } from "react-redux";
+
import { AppDispatch, IRootState } from "../../store";
import { getRestaurantsByQueryThunk } from "../../redux/restaurant/restaurantSlice";
+import RestaurantCardSkeletonLoader from "../../components/skeletonLoader/RestaurantCardSkeletonLoader";
import RestaurantCard from "../../components/utils/cards/RestaurantCard";
import SearchInput from "../../components/utils/inputs/SearchInput";
export default function HomePage(): JSX.Element {
+ const [loading, setLoading] = useState(true);
const navigate = useNavigate();
const { control, handleSubmit } = useForm();
@@ -24,6 +27,12 @@ export default function HomePage(): JSX.Element {
fetchRestaurants();
}, [dispatch]);
+ useEffect(() => {
+ if (restaurants.length > 0) {
+ setLoading(false);
+ }
+ }, [restaurants]);
+
return (
- {restaurants.map((restaurant) => (
-
- ))}
+ {loading &&
+ Array.from({
+ length: 6,
+ }).map((_, index) => (
+
+ ))}
+ {!loading &&
+ restaurants.map((restaurant) => (
+
+ ))}
diff --git a/src/pages/login/LoginPage.tsx b/src/pages/login/LoginPage.tsx
index 8a3e776..d2fdd86 100644
--- a/src/pages/login/LoginPage.tsx
+++ b/src/pages/login/LoginPage.tsx
@@ -2,7 +2,7 @@ import { useForm, Controller } from "react-hook-form";
import { Link, useNavigate } from "react-router-dom";
import { closeSnackbar, enqueueSnackbar } from "notistack";
import { useDispatch, useSelector } from "react-redux";
-import { loginThunk } from "../../redux/auth/authSlice";
+import { loginThunk, updateMessage } from "../../redux/auth/authSlice";
import { AppDispatch, IRootState } from "../../store";
import TextInput from "../../components/utils/inputs/TextInput";
@@ -27,16 +27,23 @@ function LoginPage() {
setTimeout(() => {
navigate("/");
}, 1000);
- } else if (loginSuccess === false) {
+ } else if (loginSuccess === false && message) {
enqueueSnackbar(`${message} You may try again`, {
variant: "error",
});
}
-
setTimeout(() => {
closeSnackbar();
}, 2000);
- }, [loginSuccess, navigate, message]);
+ }, [loginSuccess, navigate, message, dispatch]);
+
+ useEffect(() => {
+ setTimeout(() => {
+ if (message) {
+ dispatch(updateMessage(""));
+ }
+ }, 2000);
+ }, [dispatch, message]);
return (
>
diff --git a/src/pages/restaurant/RestaurantOverviewPage.tsx b/src/pages/restaurant/RestaurantOverviewPage.tsx
index 8992771..da40b64 100644
--- a/src/pages/restaurant/RestaurantOverviewPage.tsx
+++ b/src/pages/restaurant/RestaurantOverviewPage.tsx
@@ -170,7 +170,7 @@ const RestaurantOverviewPage: React.FC = () => {
length: Math.round(restaurantDetail.averageRating),
}).map((_, index) => (
- {}
+
))}
diff --git a/src/pages/signUp/SignUpPage.tsx b/src/pages/signUp/SignUpPage.tsx
index 45e0da5..9fd73cd 100644
--- a/src/pages/signUp/SignUpPage.tsx
+++ b/src/pages/signUp/SignUpPage.tsx
@@ -5,7 +5,7 @@ import { useDispatch, useSelector } from "react-redux";
import { closeSnackbar, enqueueSnackbar } from "notistack";
import { AppDispatch, IRootState } from "../../store";
-import { registerThunk } from "../../redux/auth/authSlice";
+import { registerThunk, updateMessage } from "../../redux/auth/authSlice";
import TextInput from "../../components/utils/inputs/TextInput";
const SignUpPage = () => {
@@ -33,7 +33,7 @@ const SignUpPage = () => {
navigate("/");
navigate(0);
}, 1000);
- } else if (registerSuccess === false) {
+ } else if (registerSuccess === false && message) {
enqueueSnackbar(message, {
variant: "error",
});
@@ -44,6 +44,14 @@ const SignUpPage = () => {
}, 2000);
}, [registerSuccess, navigate, message]);
+ useEffect(() => {
+ setTimeout(() => {
+ if (message) {
+ dispatch(updateMessage(""));
+ }
+ }, 2000);
+ }, [dispatch, message]);
+
return (