fix uset notice list
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { useNoticesStore } from "@/store/noticesStore";
|
import { useNoticesStore } from "@/store/noticesStore";
|
||||||
import { NoticeCard } from "@/components/NoticeCard";
|
import { NoticeCard } from "@/components/NoticeCard";
|
||||||
import { Button, ButtonText } from "@/components/ui/button";
|
import { Button, ButtonText } from "@/components/ui/button";
|
||||||
|
import { usePathname } from "expo-router";
|
||||||
import { Box } from "@/components/ui/box";
|
import { Box } from "@/components/ui/box";
|
||||||
import { Text } from "@/components/ui/text";
|
import { Text } from "@/components/ui/text";
|
||||||
import { VStack } from "@/components/ui/vstack";
|
import { VStack } from "@/components/ui/vstack";
|
||||||
@@ -16,6 +16,7 @@ import { useRouter } from "expo-router";
|
|||||||
|
|
||||||
export default function UserNotices() {
|
export default function UserNotices() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const pathname = usePathname();
|
||||||
const { notices, fetchNotices, deleteNotice } = useNoticesStore();
|
const { notices, fetchNotices, deleteNotice } = useNoticesStore();
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [isRedirecting, setIsRedirecting] = useState(false);
|
const [isRedirecting, setIsRedirecting] = useState(false);
|
||||||
@@ -41,7 +42,7 @@ export default function UserNotices() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
loadNotices();
|
loadNotices();
|
||||||
}, [fetchNotices]);
|
}, [pathname, fetchNotices]);
|
||||||
|
|
||||||
const showNewToast = (title) => {
|
const showNewToast = (title) => {
|
||||||
const newId = Math.random();
|
const newId = Math.random();
|
||||||
|
|||||||
@@ -10,26 +10,26 @@ export function UserSection({ notices, title }) {
|
|||||||
const [users, setUsers] = useState([]);
|
const [users, setUsers] = useState([]);
|
||||||
const { token } = useAuthStore.getState();
|
const { token } = useAuthStore.getState();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchUsers = async () => {
|
const fetchUsers = async () => {
|
||||||
try {
|
try {
|
||||||
const data = await getAllUsers();
|
const data = await getAllUsers();
|
||||||
setUsers(data);
|
setUsers(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Ошибка при загрузке пользователей:", error);
|
setUsers([]);
|
||||||
setUsers([]);
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
fetchUsers();
|
fetchUsers();
|
||||||
}, [token]);
|
}, [token]);
|
||||||
|
|
||||||
const usersWithNoticeCount = users && users.length > 0
|
const usersWithNoticeCount =
|
||||||
? users.map((user) => {
|
users && users.length > 0
|
||||||
const count = notices.filter((n) => n.clientId === user.id).length;
|
? users.map((user) => {
|
||||||
return { ...user, noticeCount: count };
|
const count = notices.filter((n) => n.clientId === user.id).length;
|
||||||
|
return { ...user, noticeCount: count };
|
||||||
})
|
})
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const topUsers = usersWithNoticeCount
|
const topUsers = usersWithNoticeCount
|
||||||
.sort((a, b) => b.noticeCount - a.noticeCount)
|
.sort((a, b) => b.noticeCount - a.noticeCount)
|
||||||
|
|||||||
Reference in New Issue
Block a user