From 00681ccda24fa2ee6e3aca4dac33bbe27bd3d1fa Mon Sep 17 00:00:00 2001
From: Radek <104318242+radekm2000@users.noreply.github.com>
Date: Sat, 30 Mar 2024 17:53:00 +0100
Subject: [PATCH] add skeletons for main page and navbar
---
.../src/components/MainPageSkeleton.tsx | 43 ++++++++++
client/ecommerce/src/components/Navbar.tsx | 9 +-
.../src/components/NavbarSkeleton.tsx | 52 ++++++++++++
.../src/components/pages/MainPage.tsx | 8 +-
.../ecommerce/src/components/pages/Member.tsx | 85 ++++++++++---------
5 files changed, 147 insertions(+), 50 deletions(-)
create mode 100644 client/ecommerce/src/components/MainPageSkeleton.tsx
create mode 100644 client/ecommerce/src/components/NavbarSkeleton.tsx
diff --git a/client/ecommerce/src/components/MainPageSkeleton.tsx b/client/ecommerce/src/components/MainPageSkeleton.tsx
new file mode 100644
index 0000000..695e961
--- /dev/null
+++ b/client/ecommerce/src/components/MainPageSkeleton.tsx
@@ -0,0 +1,43 @@
+import { Box, Card, CardContent, CardHeader, Skeleton } from "@mui/material";
+
+export const MainPageSkeleton = () => {
+ return (
+
+
+ {Array(4)
+ .fill(4)
+ .map((v, index) => (
+
+
+
+
+
+
+
+ ))}
+
+
+ );
+};
diff --git a/client/ecommerce/src/components/Navbar.tsx b/client/ecommerce/src/components/Navbar.tsx
index b282aeb..52469d5 100644
--- a/client/ecommerce/src/components/Navbar.tsx
+++ b/client/ecommerce/src/components/Navbar.tsx
@@ -33,6 +33,7 @@ import { useMarkProductNotificationAsRead } from "../hooks/useMarkProductNotific
import PopoverPopupState from "./PopoverPopupState";
import { useFetchUserInfo } from "../hooks/useFetchUserInfo";
import { isAdmin } from "../utils/isAdmin";
+import { NavbarSkeleton } from "./NavbarSkeleton";
export const NotAuthed = () => {
return (
@@ -160,9 +161,10 @@ export const Navbar = () => {
if (!user.username && !user.id) {
return ;
}
- if (isNotificationsLoading) {
- return "isNotificationsLoading...";
+ if (isNotificationsLoading || isProductNotificationsLoading) {
+ return ;
}
+
if (!notificationsReceived) {
return "Notifications not received yet";
}
@@ -170,9 +172,6 @@ export const Navbar = () => {
if (!productNotificationsReceived) {
return "Product notifications not received yet";
}
- if (isProductNotificationsLoading) {
- return "isProductNotificationsLoading...";
- }
const handleSearchTextClick = () => {
const params = new URLSearchParams();
diff --git a/client/ecommerce/src/components/NavbarSkeleton.tsx b/client/ecommerce/src/components/NavbarSkeleton.tsx
new file mode 100644
index 0000000..967ab77
--- /dev/null
+++ b/client/ecommerce/src/components/NavbarSkeleton.tsx
@@ -0,0 +1,52 @@
+import { Box, Divider, Skeleton } from "@mui/material";
+
+export const NavbarSkeleton = () => {
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
diff --git a/client/ecommerce/src/components/pages/MainPage.tsx b/client/ecommerce/src/components/pages/MainPage.tsx
index 053410d..569f487 100644
--- a/client/ecommerce/src/components/pages/MainPage.tsx
+++ b/client/ecommerce/src/components/pages/MainPage.tsx
@@ -5,6 +5,7 @@ import { Box, Typography } from "@mui/material";
import { useAllProducts } from "../../hooks/useAllProducts";
import { NotAuthed } from "../Navbar";
import { PaginatedProducts } from "../PaginatedProducts";
+import { MainPageSkeleton } from "../MainPageSkeleton";
export const MainPage = () => {
const { user, setUser } = useUserContext();
@@ -20,11 +21,8 @@ export const MainPage = () => {
}
}, [isSuccess, setUser, userInfo]);
- if (isUserInfoLoading) {
- return "userInfo loading...";
- }
- if (isProductsDataLoading) {
- return "products data loading...";
+ if (isUserInfoLoading || isProductsDataLoading) {
+ return ;
}
if (!products) {
return "No products to display";
diff --git a/client/ecommerce/src/components/pages/Member.tsx b/client/ecommerce/src/components/pages/Member.tsx
index ad046f2..78b81fe 100644
--- a/client/ecommerce/src/components/pages/Member.tsx
+++ b/client/ecommerce/src/components/pages/Member.tsx
@@ -14,9 +14,11 @@ export const Member = () => {
const params = useParams();
const [location, setLocation] = useLocation();
const userId = params?.userId;
- const { data: user } = useUserInfo(parseInt(userId!));
+ const { data: user, isLoading: isUserInfoLoading } = useUserInfo(
+ parseInt(userId!)
+ );
console.log(user);
- const { data: products } = useAllProducts();
+ const { data: products, isLoading: isUserProductsLoading } = useAllProducts();
useEffect(() => {
const params = new URLSearchParams();
@@ -26,11 +28,32 @@ export const Member = () => {
}
});
- if (!user) {
- return;
- }
- if (!userId) {
- return;
+ if (isUserInfoLoading || isUserProductsLoading || !user || !userId) {
+ return (
+
+
+
+
+
+
+ );
}
const memberProducts = products?.filter(
@@ -67,39 +90,21 @@ export const Member = () => {
maxWidth: "100%",
}}
>
- {!user.username && products === undefined ? (
- <>
-
-
-
-
- >
- ) : (
- <>
-
-
-
-
- >
- )}
+
+
+
+
);
};