fix wishlist in notice screen
This commit is contained in:
@@ -6,7 +6,13 @@ import {Image} from "@/components/ui/image";
|
||||
import { Text } from "@/components/ui/text";
|
||||
import { VStack } from "@/components/ui/vstack";
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import {ActivityIndicator, Dimensions, FlatList, View, TextInput} from "react-native";
|
||||
import {
|
||||
ActivityIndicator,
|
||||
Dimensions,
|
||||
FlatList,
|
||||
View,
|
||||
TextInput,
|
||||
} from "react-native";
|
||||
import { useEffect, useState, useRef } from "react";
|
||||
import { useNoticesStore } from "@/store/noticesStore";
|
||||
import { useWishlist } from "@/store/wishlistStore";
|
||||
@@ -15,7 +21,6 @@ import {getUserById} from "@/api/client";
|
||||
|
||||
const { width } = Dimensions.get("window");
|
||||
|
||||
|
||||
export default function NoticeDetails() {
|
||||
const { id } = useLocalSearchParams();
|
||||
const [images, setImages] = useState([]);
|
||||
@@ -28,34 +33,35 @@ export default function NoticeDetails() {
|
||||
const flatListRef = useRef(null);
|
||||
const [currentIndex, setCurrentIndex] = useState(0);
|
||||
|
||||
|
||||
const [isMessageFormVisible, setIsMessageFormVisible] = useState(false);
|
||||
const [message, setMessage] = useState('');
|
||||
const [Email, setEmail] = useState('');
|
||||
const [message, setMessage] = useState("");
|
||||
const [Email, setEmail] = useState("");
|
||||
const handleSendMessage = () => {
|
||||
console.log('Wiadomość do:', user?.email);
|
||||
console.log('Email nadawcy:', Email);
|
||||
console.log('Treść:', message);
|
||||
console.log("Wiadomość do:", user?.email);
|
||||
console.log("Email nadawcy:", Email);
|
||||
console.log("Treść:", message);
|
||||
|
||||
setIsMessageFormVisible(false);
|
||||
setMessage('');
|
||||
setEmail('');
|
||||
setMessage("");
|
||||
setEmail("");
|
||||
};
|
||||
|
||||
const formatDate = (dateString) => {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('pl-PL', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit'
|
||||
return date.toLocaleDateString("pl-PL", {
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
});
|
||||
};
|
||||
|
||||
const { getNoticeById, getAllImagesByNoticeId } = useNoticesStore();
|
||||
const addNoticeToWishlist = useWishlist((state) => state.addNoticeToWishlist);
|
||||
const removeNoticeFromWishlist = useWishlist((state) => state.removeNoticeFromWishlist);
|
||||
const toggleNoticeInWishlist = useWishlist(
|
||||
(state) => state.toggleNoticeInWishlist
|
||||
);
|
||||
|
||||
const isInWishlist = useWishlist((state) =>
|
||||
notice ? state.wishlistNotices.some((item) => item.noticeId === notice.noticeId) : false
|
||||
id ? state.wishlistNotices.some((item) => item.noticeId == id) : false
|
||||
);
|
||||
const onViewableItemsChanged = useRef(({ viewableItems }) => {
|
||||
if (viewableItems.length > 0) {
|
||||
@@ -67,7 +73,6 @@ export default function NoticeDetails() {
|
||||
itemVisiblePercentThreshold: 70,
|
||||
}).current;
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const fetchNotice = async () => {
|
||||
setIsLoading(true);
|
||||
@@ -95,8 +100,11 @@ export default function NoticeDetails() {
|
||||
if (notice) {
|
||||
try {
|
||||
const fetchedImages = await getAllImagesByNoticeId(notice.noticeId);
|
||||
setImages(fetchedImages && fetchedImages.length > 0 ? fetchedImages : ["https://http.cat/404.jpg"]);
|
||||
|
||||
setImages(
|
||||
fetchedImages && fetchedImages.length > 0
|
||||
? fetchedImages
|
||||
: ["https://http.cat/404.jpg"]
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("Error while loading images:", err);
|
||||
setImage("https://http.cat/404.jpg");
|
||||
@@ -129,7 +137,6 @@ export default function NoticeDetails() {
|
||||
fetchUser();
|
||||
}, [notice]);
|
||||
|
||||
|
||||
if (isLoading) {
|
||||
return <ActivityIndicator />;
|
||||
}
|
||||
@@ -183,7 +190,9 @@ export default function NoticeDetails() {
|
||||
{images.map((_, index) => (
|
||||
<Box
|
||||
key={index}
|
||||
className={`w-2 h-2 rounded-full mx-1 ${index === currentIndex ? 'bg-primary-500' : 'bg-gray-300'}`}
|
||||
className={`w-2 h-2 rounded-full mx-1 ${
|
||||
index === currentIndex ? "bg-primary-500" : "bg-gray-300"
|
||||
}`}
|
||||
/>
|
||||
))}
|
||||
</Box>
|
||||
@@ -191,9 +200,7 @@ export default function NoticeDetails() {
|
||||
</Box>
|
||||
)}
|
||||
|
||||
<ScrollView
|
||||
showsVerticalScrollIndicator={false}
|
||||
>
|
||||
<ScrollView showsVerticalScrollIndicator={false}>
|
||||
<VStack className="p-2">
|
||||
<Text className="text-sm font-normal mb-2 text-typography-700">
|
||||
{formatDate(notice.publishDate)}
|
||||
@@ -210,11 +217,7 @@ export default function NoticeDetails() {
|
||||
|
||||
<Pressable
|
||||
onPress={() => {
|
||||
if (isInWishlist) {
|
||||
removeNoticeFromWishlist(notice.noticeId);
|
||||
} else {
|
||||
addNoticeToWishlist(notice);
|
||||
}
|
||||
toggleNoticeInWishlist(id);
|
||||
}}
|
||||
>
|
||||
<Ionicons
|
||||
@@ -226,29 +229,30 @@ export default function NoticeDetails() {
|
||||
</Box>
|
||||
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm">
|
||||
<Text className="text-sm text-typography-500">
|
||||
Kategoria: <Text className="font-bold text-gray-950">{notice.category}</Text>
|
||||
Kategoria:{" "}
|
||||
<Text className="font-bold text-gray-950">{notice.category}</Text>
|
||||
</Text>
|
||||
</Box>
|
||||
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm">
|
||||
<Text className="text-2xl text-gray-950">
|
||||
Opis ogloszenia
|
||||
</Text>
|
||||
<Text className="text-2xl text-gray-950">Opis ogloszenia</Text>
|
||||
<Text className="text-sm text-typography-700">
|
||||
{notice.description}
|
||||
</Text>
|
||||
</Box>
|
||||
|
||||
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm">
|
||||
<Text className="text-sm text-typography-500">
|
||||
Uzytkownik:
|
||||
</Text>
|
||||
<Text className="text-sm text-typography-500">Uzytkownik:</Text>
|
||||
{isUserLoading ? (
|
||||
<ActivityIndicator />
|
||||
) : user ? (
|
||||
<>
|
||||
<Box className="mr-4">
|
||||
<Image
|
||||
source={{ uri: user.profileImage || "https://th.bing.com/th/id/OIP.3coo_N8sieled8QNroQmkgHaHa?rs=1&pid=ImgDetMain" }} // Domyślny obraz, jeśli brak zdjęcia profilowego
|
||||
source={{
|
||||
uri:
|
||||
user.profileImage ||
|
||||
"https://th.bing.com/th/id/OIP.3coo_N8sieled8QNroQmkgHaHa?rs=1&pid=ImgDetMain",
|
||||
}} // Domyślny obraz, jeśli brak zdjęcia profilowego
|
||||
className="h-12 w-12 rounded-full"
|
||||
alt="Zdjęcie profilowe"
|
||||
/>
|
||||
@@ -265,7 +269,9 @@ export default function NoticeDetails() {
|
||||
onPress={() => setIsMessageFormVisible(true)}
|
||||
className="mt-3 bg-primary-500 py-2 px-4 rounded-md"
|
||||
>
|
||||
<Text className="text-white text-center font-bold">Wyślij wiadomość</Text>
|
||||
<Text className="text-white text-center font-bold">
|
||||
Wyślij wiadomość
|
||||
</Text>
|
||||
</Pressable>
|
||||
<Link href={`/user/${notice.clientId}`}>
|
||||
<Text className="text-xl p-3 font-bold text-center text-typography-700 mt-3">
|
||||
@@ -277,15 +283,15 @@ export default function NoticeDetails() {
|
||||
) : (
|
||||
<Text>Błąd podczas ładowania danych użytkownika</Text>
|
||||
)}
|
||||
|
||||
</Box>
|
||||
|
||||
</VStack>
|
||||
</ScrollView>
|
||||
{isMessageFormVisible && (
|
||||
<View className="absolute inset-0 bg-black bg-opacity-50 justify-center items-center z-20">
|
||||
<View className="bg-white p-4 rounded-lg w-4/5">
|
||||
<Text className="text-lg font-bold mb-4">Wyślij wiadomość do {user?.firstName}</Text>
|
||||
<Text className="text-lg font-bold mb-4">
|
||||
Wyślij wiadomość do {user?.firstName}
|
||||
</Text>
|
||||
|
||||
<Text className="text-sm font-medium mb-1">Do:</Text>
|
||||
<Text className="bg-gray-100 p-3 rounded text-gray-500">
|
||||
@@ -318,14 +324,14 @@ export default function NoticeDetails() {
|
||||
|
||||
<Pressable
|
||||
onPress={handleSendMessage}
|
||||
className="bg-primary-500 py-2 px-4 rounded-md">
|
||||
className="bg-primary-500 py-2 px-4 rounded-md"
|
||||
>
|
||||
<Text className="text-white">Wyślij</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user