From 2630b35afd39973152485a027a9be811d5d8b553 Mon Sep 17 00:00:00 2001 From: Patryk Date: Wed, 11 Jun 2025 21:11:07 +0200 Subject: [PATCH] fix uset notice list --- .../app/(tabs)/dashboard/userNotices.jsx | 5 +-- ArtisanConnect/components/UserSection.jsx | 34 +++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/ArtisanConnect/app/(tabs)/dashboard/userNotices.jsx b/ArtisanConnect/app/(tabs)/dashboard/userNotices.jsx index ee2d5d1..946b4a0 100644 --- a/ArtisanConnect/app/(tabs)/dashboard/userNotices.jsx +++ b/ArtisanConnect/app/(tabs)/dashboard/userNotices.jsx @@ -1,7 +1,7 @@ import { useNoticesStore } from "@/store/noticesStore"; import { NoticeCard } from "@/components/NoticeCard"; import { Button, ButtonText } from "@/components/ui/button"; - +import { usePathname } from "expo-router"; import { Box } from "@/components/ui/box"; import { Text } from "@/components/ui/text"; import { VStack } from "@/components/ui/vstack"; @@ -16,6 +16,7 @@ import { useRouter } from "expo-router"; export default function UserNotices() { const router = useRouter(); + const pathname = usePathname(); const { notices, fetchNotices, deleteNotice } = useNoticesStore(); const [isLoading, setIsLoading] = useState(true); const [isRedirecting, setIsRedirecting] = useState(false); @@ -41,7 +42,7 @@ export default function UserNotices() { } }; loadNotices(); - }, [fetchNotices]); + }, [pathname, fetchNotices]); const showNewToast = (title) => { const newId = Math.random(); diff --git a/ArtisanConnect/components/UserSection.jsx b/ArtisanConnect/components/UserSection.jsx index 9ddfbe9..cf4008f 100644 --- a/ArtisanConnect/components/UserSection.jsx +++ b/ArtisanConnect/components/UserSection.jsx @@ -10,26 +10,26 @@ export function UserSection({ notices, title }) { const [users, setUsers] = useState([]); const { token } = useAuthStore.getState(); - useEffect(() => { - const fetchUsers = async () => { - try { - const data = await getAllUsers(); - setUsers(data); - } catch (error) { - console.error("Ошибка при загрузке пользователей:", error); - setUsers([]); - } - }; + useEffect(() => { + const fetchUsers = async () => { + try { + const data = await getAllUsers(); + setUsers(data); + } catch (error) { + setUsers([]); + } + }; - fetchUsers(); - }, [token]); + fetchUsers(); + }, [token]); - const usersWithNoticeCount = users && users.length > 0 - ? users.map((user) => { - const count = notices.filter((n) => n.clientId === user.id).length; - return { ...user, noticeCount: count }; + const usersWithNoticeCount = + users && users.length > 0 + ? users.map((user) => { + const count = notices.filter((n) => n.clientId === user.id).length; + return { ...user, noticeCount: count }; }) - : []; + : []; const topUsers = usersWithNoticeCount .sort((a, b) => b.noticeCount - a.noticeCount)