Skip to content

Commit bb32287

Browse files
committed
ad skeleton
1 parent 278e145 commit bb32287

1 file changed

Lines changed: 46 additions & 7 deletions

File tree

src/pages/Notifications/index.jsx

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useNavigate } from "react-router-dom";
66
import ModalSm from "../../components/Modal/ModalSm";
77
import { getFieldTranslationByNames } from "../../services/Utility";
88
import NoNotification from "./NoNotification";
9+
import { Skeleton } from "../../components/Skeleton";
910

1011
const Div = styled.div`
1112
display: flex;
@@ -15,6 +16,7 @@ const Div = styled.div`
1516
padding-right: 15px;
1617
height: 100%;
1718
`;
19+
1820
const Container = styled.div`
1921
height: 77%;
2022
h4 {
@@ -28,30 +30,66 @@ const Container = styled.div`
2830
}
2931
`;
3032

33+
// اسکلتون برای کارت
34+
const SkeletonCard = styled.div`
35+
padding: 20px;
36+
border-radius: 5px;
37+
background-color: ${(props) =>
38+
props.theme.colors.newColors.otherColors.inputBg};
39+
40+
`;
41+
3142
const Notifications = () => {
3243
const [notifications, setNotifications] = useState([]);
44+
const [loading, setLoading] = useState(true); // اضافه شد
3345
const { Request, HTTP_METHOD } = useRequest();
3446

3547
useEffect(() => {
36-
Request("notifications").then((response) => {
37-
setNotifications(response.data.data);
38-
});
48+
setLoading(true);
49+
Request("notifications")
50+
.then((response) => {
51+
setNotifications(response.data.data || []);
52+
})
53+
.catch((error) => {
54+
console.error("Error fetching notifications:", error);
55+
setNotifications([]);
56+
})
57+
.finally(() => {
58+
setLoading(false);
59+
});
3960
}, []);
61+
4062
const handleDelete = () => {
4163
Request("notifications/read/all", HTTP_METHOD.POST)
4264
.then(() => {
4365
setNotifications([]);
4466
})
4567
.catch((err) => console.error(err));
4668
};
69+
4770
return (
4871
<ModalSm title={"238"}>
4972
<Container>
50-
{/**delete all notif */}
5173
<h4 onClick={handleDelete}>{getFieldTranslationByNames("866")}</h4>
52-
5374
<Div>
54-
{notifications.length === 0 ? (
75+
{loading ? (
76+
// اسکلتون برای 3 کارت
77+
Array.from({ length: 3 }).map((_, index) => (
78+
<SkeletonCard key={index}>
79+
<div style={{ display: "flex", alignItems: "center", justifyContent:"space-between" ,width:"100%", gap: "12px", marginBottom: "10px" }}>
80+
<div style={{ display: "flex", alignItems: "center" , gap: "12px", }}>
81+
<Skeleton width="60px" height="60px" radius="50%" />
82+
<div>
83+
<Skeleton width="120px" height="20px" radius="4px" style={{ marginBottom: "8px" }} />
84+
<Skeleton width="150px" height="14px" radius="4px" />
85+
</div>
86+
</div>
87+
<Skeleton width="35px" height="35px" radius="50%" />
88+
</div>
89+
<Skeleton width="100%" height="30px" radius="4px" />
90+
</SkeletonCard>
91+
))
92+
) : notifications.length === 0 ? (
5593
<NoNotification />
5694
) : (
5795
notifications.map((notif) => (
@@ -61,6 +99,7 @@ const Notifications = () => {
6199
key={notif.id}
62100
id={notif.id}
63101
data={notif}
102+
isLoading={false}
64103
/>
65104
))
66105
)}
@@ -70,4 +109,4 @@ const Notifications = () => {
70109
);
71110
};
72111

73-
export default Notifications;
112+
export default Notifications;

0 commit comments

Comments
 (0)