import { useNoticesStore } from "@/store/noticesStore";
import { NoticeCard } from "@/components/NoticeCard";
import { Button } from "react-native";
import { Box } from "@/components/ui/box";
import { Text } from "@/components/ui/text";
import { VStack } from "@/components/ui/vstack";
import { ActivityIndicator, FlatList } from "react-native";
import { useEffect, useState } from "react";
import {useAuthStore} from "@/store/authStore";
export default function UserNotices() {
const { notices, fetchNotices } = useNoticesStore();
const currentUserId = useAuthStore((state) => state.user_id);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
const loadNotices = async () => {
setIsLoading(true);
try {
await fetchNotices();
} catch (err) {
console.error("Błąd podczas pobierania ogłoszeń:", err);
} finally {
setIsLoading(false);
}
};
loadNotices();
}, [fetchNotices]);
const userNotices = notices
.filter((notice) => notice.clientId === currentUserId)
.sort((a, b) => new Date(b.publishDate) - new Date(a.publishDate));
if (isLoading) {
return ;
}
return (
{/* Moje ogłoszenia */}
{userNotices.length > 0 ? (
(
{item.status === "ACTIVE" ? (
) : (
)}
)}
keyExtractor={(item) => item.noticeId.toString()}
/>
) : (
Nie masz żadnych ogłoszeń.
)}
);
}