+
{haveNotification ? (
notifications?.map((notification) => (
-
+
+
+
))
) : (
- No Notifications
+ {loading ? (
+
+ ) : (
+ "No Notifications"
+ )}
)}
diff --git a/frontend/src/hooks/useNotifications.ts b/frontend/src/hooks/useNotifications.ts
index d819d09..1f74820 100644
--- a/frontend/src/hooks/useNotifications.ts
+++ b/frontend/src/hooks/useNotifications.ts
@@ -7,32 +7,40 @@ const useNotifications = () => {
const [notifications, setNotifications] = useState
();
const [haveNotification, setHaveNotification] = useState(false);
const { auth, navigate, refresh } = useFetchWithAuthExports();
+ const [loading, setLoading] = useState();
useEffect(() => {
+ setLoading(true);
const getNotifications = async () => {
- const response = await fetchWithAuth(
- navigate,
- refresh,
- auth,
- "/notification/get-by-user",
- "get"
- );
-
- if (response.status === 404) {
- setHaveNotification(false);
- return;
+ try {
+ const response = await fetchWithAuth(
+ navigate,
+ refresh,
+ auth,
+ "/notification/get-by-user",
+ "get"
+ );
+
+ if (response.status === 404) {
+ setHaveNotification(false);
+ return;
+ }
+
+ setHaveNotification(true);
+
+ const noticationsAPI = await response.json();
+ setNotifications(noticationsAPI);
+ } catch (error) {
+ alert(error);
+ } finally {
+ setLoading(false);
}
-
- setHaveNotification(true);
-
- const noticationsAPI = await response.json();
- setNotifications(noticationsAPI);
};
getNotifications();
}, []);
- return { notifications, haveNotification };
+ return { notifications, haveNotification, loading };
};
export default useNotifications;
diff --git a/frontend/src/pages/HomePage.tsx b/frontend/src/pages/HomePage.tsx
index 026d10b..5f992cf 100644
--- a/frontend/src/pages/HomePage.tsx
+++ b/frontend/src/pages/HomePage.tsx
@@ -2,17 +2,18 @@ import Header from "../components/Header";
import { useNavigate } from "react-router-dom";
import useUser from "../hooks/useUser";
import NotificationsList from "../components/NotificationsList";
+import Loading from "../components/Loading";
const HomePage = () => {
const navigate = useNavigate();
- const { data: data } = useUser();
-
- console.log(data);
+ const { data: data, loading } = useUser();
const handleRegisterButton = () => {
navigate("/register-driver");
};
-
+ if (loading) {
+ return ;
+ }
return (