import { useEffect, useMemo, useState } from "react"; import { Link } from "react-router-dom"; import NoticeCard from "../components/NoticeCard"; import { useAuthStore } from "../store/authStore"; import { useNoticesStore } from "../store/noticesStore"; export default function MyNotices() { const { user_id } = useAuthStore(); const { notices, deleteNotice, fetchNotices } = useNoticesStore(); const [isLoading, setIsLoading] = useState(true); useEffect(() => { let isMounted = true; const loadNotices = async () => { setIsLoading(true); try { await fetchNotices(); } finally { if (isMounted) { setIsLoading(false); } } }; loadNotices(); return () => { isMounted = false; }; }, [fetchNotices]); const userNotices = useMemo( () => notices .filter((notice) => String(notice.clientId) === String(user_id)) .sort((a, b) => new Date(b.publishDate) - new Date(a.publishDate)), [notices, user_id] ); const handleDelete = async (noticeId) => { const confirmed = window.confirm("Usunac ogloszenie?"); if (!confirmed) { return; } await deleteNotice(noticeId); await fetchNotices(); }; return (

Moje ogloszenia

Dodaj nowe
{isLoading ? (
Ladowanie...
) : null} {!isLoading && userNotices.length === 0 ? (
Nie masz jeszcze ogloszen.
) : null} {!isLoading && userNotices.length > 0 ? (
{userNotices.map((notice) => ( {/* {notice.status === "INACTIVE" ? (*/ Edytuj /*) : null} */} } key={notice.noticeId} notice={notice} /> ))}
) : null}
); }