11 Commits

Author SHA1 Message Date
7ec883100f headers user is hidden, [userId] is changed to "Ogłsozenia uzytkownika" 2025-06-09 21:12:10 +02:00
c25495ba3f AppIco added 2025-06-09 20:51:09 +02:00
be51f1e9cc Mail sender is working 2025-06-09 20:39:00 +02:00
14bd178f84 Mail sender is working 2025-06-09 20:38:13 +02:00
7fc1312ddc Avatar + SafeAreaView 2025-06-09 19:27:05 +02:00
1d3cbeef3a Added ScreenRotation to notice and updated userNotices 2025-06-08 17:22:02 +02:00
Patryk
dbf07cea0a improve account style 2025-06-08 11:23:09 +02:00
Patryk
e2e5543e0d fix notice status 2025-06-08 10:30:14 +02:00
Patryk
ca59c94783 del duplicate url 2025-06-08 09:52:13 +02:00
Patryk
e849a39603 Merge remote-tracking branch 'origin/integrateWithAuth' 2025-06-08 09:39:56 +02:00
0e46d692f9 fix of api url and new version packages 2025-06-06 16:31:39 +02:00
14 changed files with 1535 additions and 721 deletions

View File

@@ -0,0 +1,30 @@
import { useAuthStore } from "@/store/authStore";
const API_URL = "https://hopp.zikor.pl/api/v1";
export const sendEmail = async (emailData) => {
const token = useAuthStore.getState().token;
try {
const response = await fetch(`${API_URL}/email/send`, {
method: "POST",
headers: {
"Content-Type": "application/json",
...(token && { Authorization: `Bearer ${token}` }),
},
body: JSON.stringify(emailData),
});
if (!response.ok) {
const errorMessage = `HTTP error! Status: ${response.status}`;
console.error("Error przy wysyłaniu maila", errorMessage);
return { success: false, error: errorMessage };
}
const result = await response.text();
return { success: true, result };
} catch (error) {
console.error("Error przy wysyłaniu maila:", error.message);
return { success: false, error: error.message };
}
};

View File

@@ -0,0 +1,12 @@
import axios from "axios";
import FormData from "form-data";
const API_URL = "https://hopp.zikor.pl/api/v1";
export async function listOrders() {
const response = await fetch(`${API_URL}/orders/get/all`);
const data = await response.json();
if (!response.ok) {
throw new Error(response.toString());
}
return data;
}

View File

@@ -5,7 +5,7 @@
"scheme": "com.hamx.artisanconnect", "scheme": "com.hamx.artisanconnect",
"version": "1.0.0", "version": "1.0.0",
"orientation": "portrait", "orientation": "portrait",
"icon": "./assets/icon.png", "icon": "./assets/AppIco.png",
"userInterfaceStyle": "light", "userInterfaceStyle": "light",
"newArchEnabled": true, "newArchEnabled": true,
"splash": { "splash": {

View File

@@ -8,12 +8,12 @@ import { ActivityIndicator } from "react-native";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { getUserById } from "@/api/client"; import { getUserById } from "@/api/client";
import { HStack } from "@gluestack-ui/themed"; import { HStack } from "@gluestack-ui/themed";
import { useAuthStore } from "@/store/authStore";
export default function Account() { export default function Account() {
const [user, setUser] = useState(null); const [user, setUser] = useState(null);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const currentUserId = 2; // Tymczasowo, do czasu zaimplementowania logowania bo nie moge pobrac usera const currentUserId = useAuthStore((state) => state.user_id);
useEffect(() => { useEffect(() => {
const fetchUser = async () => { const fetchUser = async () => {
setIsLoading(true); setIsLoading(true);
@@ -37,9 +37,10 @@ export default function Account() {
return <Text>Nie udało się pobrać danych użytkownika.</Text>; return <Text>Nie udało się pobrać danych użytkownika.</Text>;
} }
console.log(user);
return ( return (
<VStack className="bg-gray-50 flex-1"> <VStack className=" flex-1 m-2">
<Box className="bg-white pb-6 shadow-sm"> <Box className="bg-white p-5 rounded-lg ">
<Box className="items-center pt-6 mb-4"> <Box className="items-center pt-6 mb-4">
<Image <Image
source={{ source={{
@@ -57,12 +58,12 @@ export default function Account() {
</Text> </Text>
</Box> </Box>
<Box className="bg-white mt-4 p-5 border-t border-b border-gray-200"> <Box className="bg-white mt-4 p-5 rounded-lg">
<Text className="font-bold text-lg mb-3">Moje dane</Text> <Text className="font-bold text-lg mb-3">Moje dane</Text>
<HStack className="mb-3"> <HStack className="mb-3">
<Text className="text-gray-600 w-24">E-mail</Text> <Text className="text-gray-600 w-24">E-mail: </Text>
<Text className="flex-1">{user.email || "brak danych"}</Text> <Text className=" text-gray-600 ">{user.email}</Text>
</HStack> </HStack>
<Pressable <Pressable
@@ -73,7 +74,7 @@ export default function Account() {
</Pressable> </Pressable>
</Box> </Box>
<Box className="bg-white mt-4 p-5"> <Box className="bg-white mt-4 p-5 rounded-lg">
<Text className="font-bold text-lg mb-3">Moje konto</Text> <Text className="font-bold text-lg mb-3">Moje konto</Text>
<Link href="/dashboard/userNotices" asChild> <Link href="/dashboard/userNotices" asChild>

View File

@@ -6,11 +6,12 @@ import {Text} from "@/components/ui/text";
import { VStack } from "@/components/ui/vstack"; import { VStack } from "@/components/ui/vstack";
import { ActivityIndicator, FlatList } from "react-native"; import { ActivityIndicator, FlatList } from "react-native";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import {useAuthStore} from "@/store/authStore";
export default function UserNotices() { export default function UserNotices() {
const { notices, fetchNotices } = useNoticesStore(); const { notices, fetchNotices } = useNoticesStore();
const currentUserId = useAuthStore((state) => state.user_id);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const currentUserId = 1; // Tymczasowo, do czasu zaimplementowania logowania bo nie moge pobrac usera
useEffect(() => { useEffect(() => {
const loadNotices = async () => { const loadNotices = async () => {
@@ -24,35 +25,49 @@ export default function UserNotices() {
} }
}; };
loadNotices(); loadNotices();
}, []); }, [fetchNotices]);
const userNotices = notices.filter(notice => notice.clientId === currentUserId); const userNotices = notices
.filter((notice) => notice.clientId === currentUserId)
.sort((a, b) => new Date(b.publishDate) - new Date(a.publishDate));
if (isLoading) { if (isLoading) {
return <ActivityIndicator />; return <ActivityIndicator />;
} }
return ( return (
<VStack className="p-4"> <VStack className="p-2">
<Text className="text-2xl font-bold mb-4">Moje ogłoszenia</Text> {/* <Text className="text-2xl font-bold mb-4">Moje ogłoszenia</Text> */}
{userNotices.length > 0 ? ( {userNotices.length > 0 ? (
<FlatList <FlatList
data={userNotices} data={userNotices}
numColumns={2} // numColumns={1}
columnWrapperStyle={{ marginBottom: 10, justifyContent: "space-between" }} // columnWrapperStyle={{
// marginBottom: 10,
// justifyContent: "space-between",
// }}
renderItem={({ item }) => ( renderItem={({ item }) => (
<Box className="flex-1"> <Box className="flex-1 mb-4 pb-2 bg-white rounded-lg">
<NoticeCard notice={item} /> <NoticeCard notice={item} />
<Box className="flex-row justify-between mt-2"> <Box className="flex-row justify-between mt-2">
{item.status === "ACTIVE" ? (
<Button <Button
title="Promuj" title="Usuń"
onPress={() => { onPress={() => {
// TODO: Implementacja promocji ogłoszenia
console.log(`Promuj ogłoszenie ${item.noticeId}`); console.log(`Promuj ogłoszenie ${item.noticeId}`);
}} }}
className="bg-primary-500 py-2 px-4 rounded-md" className="bg-primary-500 py-2 px-4 rounded-md"
> ></Button>
</Button> ) : (
<Button
title="Aktywj"
onPress={() => {
console.log(`Promuj ogłoszenie ${item.noticeId}`);
}}
className="bg-primary-500 py-2 px-4 rounded-md"
></Button>
)}
<Button <Button
title="Podbij" title="Podbij"
onPress={() => { onPress={() => {
@@ -60,8 +75,7 @@ export default function UserNotices() {
console.log(`Podbij ogłoszenie ${item.noticeId}`); console.log(`Podbij ogłoszenie ${item.noticeId}`);
}} }}
className="bg-primary-500 py-2 px-4 rounded-md" className="bg-primary-500 py-2 px-4 rounded-md"
> ></Button>
</Button>
</Box> </Box>
</Box> </Box>
)} )}

View File

@@ -34,11 +34,14 @@ export default function Home() {
const notices = useNoticesStore((state) => state.notices); const notices = useNoticesStore((state) => state.notices);
// console.log("Notices:", notices); // console.log("Notices:", notices);
// console.log("Notices length:", notices.length);
const latestNotices = [...notices] const activeNotices = notices.filter((notice) => notice.status === "ACTIVE");
// console.log("Activer Notices:", activeNotices.length);
const latestNotices = [...activeNotices]
.sort((a, b) => new Date(b.publishDate) - new Date(a.publishDate)) .sort((a, b) => new Date(b.publishDate) - new Date(a.publishDate))
.slice(0, 6); .slice(0, 6);
const recomendedNotices = [...notices] const recomendedNotices = [...activeNotices]
.sort(() => Math.random() - 0.5) .sort(() => Math.random() - 0.5)
.slice(0, 6); .slice(0, 6);
@@ -47,13 +50,13 @@ export default function Home() {
{/* <View> */} {/* <View> */}
<SearchSection /> <SearchSection />
<ScrollView showsVerticalScrollIndicator={false}> <ScrollView showsVerticalScrollIndicator={false}>
<CategorySection title="Polecane kategorie" notices={notices} /> <CategorySection title="Polecane kategorie" notices={activeNotices} />
<NoticeSection <NoticeSection
title="Najnowsze ogłoszenia" title="Najnowsze ogłoszenia"
notices={latestNotices} notices={latestNotices}
ctaLink="/notices?sort=latest" ctaLink="/notices?sort=latest"
/> />
<UserSection title="Popularni sprzedawcy" notices={notices} /> <UserSection title="Popularni sprzedawcy" notices={activeNotices} />
<NoticeSection <NoticeSection
title="Proponowane ogłoszenia" title="Proponowane ogłoszenia"
notices={recomendedNotices} notices={recomendedNotices}

View File

@@ -1,4 +1,10 @@
import { FlatList, Text, ActivityIndicator, RefreshControl, Dimensions } from "react-native"; import {
FlatList,
Text,
ActivityIndicator,
RefreshControl,
Dimensions,
} from "react-native";
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons"; import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
import { useNoticesStore } from "@/store/noticesStore"; import { useNoticesStore } from "@/store/noticesStore";
@@ -11,7 +17,7 @@ import { listCategories } from "@/api/categories";
import { FormControl, FormControlLabel } from "@/components/ui/form-control"; import { FormControl, FormControlLabel } from "@/components/ui/form-control";
import { Input, InputField } from "@/components/ui/input"; import { Input, InputField } from "@/components/ui/input";
import { HStack } from "@/components/ui/hstack"; import { HStack } from "@/components/ui/hstack";
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'; import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
import { KeyboardAvoidingView, Platform } from "react-native"; import { KeyboardAvoidingView, Platform } from "react-native";
import { import {
Actionsheet, Actionsheet,
@@ -56,11 +62,11 @@ export default function Notices() {
if (Array.isArray(data)) { if (Array.isArray(data)) {
setCategories(data); setCategories(data);
} else { } else {
console.error('listCategories did not return an array:', data); console.error("listCategories did not return an array:", data);
setError(new Error('Invalid categories data')); setError(new Error("Invalid categories data"));
} }
} catch (error) { } catch (error) {
console.error('Error fetching select items:', error); console.error("Error fetching select items:", error);
setError(error); setError(error);
} }
}; };
@@ -72,10 +78,10 @@ export default function Notices() {
}, []); }, []);
useEffect(() => { useEffect(() => {
let result = notices; let result = notices.filter((notice) => notice.status === "ACTIVE");
if (params.category) { if (params.category) {
result = result.filter(notice => notice.category === params.category); result = result.filter((notice) => notice.category === params.category);
} }
if (params.sort) { if (params.sort) {
@@ -100,11 +106,10 @@ export default function Notices() {
return isNaN(priceA) || isNaN(priceB) ? 0 : priceB - priceA; return isNaN(priceA) || isNaN(priceB) ? 0 : priceB - priceA;
}); });
} }
} }
if (params.priceFrom) { if (params.priceFrom) {
result = result.filter(notice => { result = result.filter((notice) => {
const price = parseFloat(notice.price); const price = parseFloat(notice.price);
const priceFrom = parseFloat(params.priceFrom); const priceFrom = parseFloat(params.priceFrom);
return !isNaN(price) && price >= priceFrom; return !isNaN(price) && price >= priceFrom;
@@ -112,32 +117,36 @@ export default function Notices() {
} }
if (params.priceTo) { if (params.priceTo) {
result = result.filter(notice => { result = result.filter((notice) => {
const price = parseFloat(notice.price); const price = parseFloat(notice.price);
const priceTo = parseFloat(params.priceTo); const priceTo = parseFloat(params.priceTo);
return !isNaN(price) && price <= priceTo; return !isNaN(price) && price <= priceTo;
}); });
} }
if (params.search) { if (params.search) {
const searchTerm = params.search.toLowerCase(); const searchTerm = params.search.toLowerCase();
result = result.filter(notice => { result = result.filter((notice) => {
return notice.title.toLowerCase().includes(searchTerm); return notice.title.toLowerCase().includes(searchTerm);
}); });
} }
setFilteredNotices(result); setFilteredNotices(result);
}, [notices, }, [
notices,
params.category, params.category,
params.sort, params.sort,
params.priceFrom, params.priceFrom,
params.priceTo, params.priceTo,
params.search]); params.search,
]);
let filterActive = !!params.category || !!params.sort || !!params.priceFrom || !!params.priceTo || !!params.search;
let filterActive =
!!params.category ||
!!params.sort ||
!!params.priceFrom ||
!!params.priceTo ||
!!params.search;
const loadData = async () => { const loadData = async () => {
setIsLoading(true); setIsLoading(true);
@@ -154,33 +163,33 @@ export default function Notices() {
const handleCategorySelect = (value) => { const handleCategorySelect = (value) => {
router.replace({ router.replace({
pathname: "/notices", pathname: "/notices",
params: { ...params, category: value } params: { ...params, category: value },
}); });
}; };
const handlePriceFrom = (value) => { const handlePriceFrom = (value) => {
router.replace({ router.replace({
pathname: "/notices", pathname: "/notices",
params: { ...params, priceFrom: value } params: { ...params, priceFrom: value },
}); });
} };
const handlePriceTo = (value) => { const handlePriceTo = (value) => {
router.replace({ router.replace({
pathname: "/notices", pathname: "/notices",
params: { ...params, priceTo: value } params: { ...params, priceTo: value },
}); });
} };
const handleClose = () => setShowActionsheet(false); const handleClose = () => setShowActionsheet(false);
const handleSort = (value) => { const handleSort = (value) => {
router.replace({ router.replace({
pathname: "/notices", pathname: "/notices",
params: { ...params, sort: value } params: { ...params, sort: value },
}); });
setShowSortSheet(false); setShowSortSheet(false);
} };
const onRefresh = async () => { const onRefresh = async () => {
setRefreshing(true); setRefreshing(true);
@@ -201,15 +210,26 @@ export default function Notices() {
return <Text>Nie udało się pobrać listy. {error.message}</Text>; return <Text>Nie udało się pobrać listy. {error.message}</Text>;
} }
const SCREEN_HEIGHT = Dimensions.get('window').height; const SCREEN_HEIGHT = Dimensions.get("window").height;
const selectedCategory = params.category && categories?.find( const selectedCategory =
(cat) => cat.value === params.category (params.category &&
) || null; categories?.find((cat) => cat.value === params.category)) ||
null;
return ( return (
<> <>
<Box style={{ flexDirection: "row", padding: 8, paddingTop: 16, paddingBottom: 16, backgroundColor: "white", alignItems: "center", justifyContent: "space-between" }}> <Box
style={{
flexDirection: "row",
padding: 8,
paddingTop: 16,
paddingBottom: 16,
backgroundColor: "white",
alignItems: "center",
justifyContent: "space-between",
}}
>
<Box style={{ flexDirection: "row", alignItems: "center", gap: 8 }}> <Box style={{ flexDirection: "row", alignItems: "center", gap: 8 }}>
<Button variant="outline" onPress={() => setShowActionsheet(true)}> <Button variant="outline" onPress={() => setShowActionsheet(true)}>
<ButtonText>Filtruj</ButtonText> <ButtonText>Filtruj</ButtonText>
@@ -227,9 +247,11 @@ export default function Notices() {
</Box> </Box>
<Actionsheet isOpen={showActionsheet} onClose={handleClose}> <Actionsheet isOpen={showActionsheet} onClose={handleClose}>
<ActionsheetBackdrop /> <ActionsheetBackdrop />
<ActionsheetContent style={{ maxHeight: SCREEN_HEIGHT * 0.6, width: '100%' }} > <ActionsheetContent
style={{ maxHeight: SCREEN_HEIGHT * 0.6, width: "100%" }}
>
<KeyboardAwareScrollView <KeyboardAwareScrollView
contentContainerStyle={{ flexGrow: 1, width: '100%' }} contentContainerStyle={{ flexGrow: 1, width: "100%" }}
enableOnAndroid={true} enableOnAndroid={true}
extraScrollHeight={40} extraScrollHeight={40}
> >
@@ -238,24 +260,22 @@ export default function Notices() {
</ActionsheetDragIndicatorWrapper> </ActionsheetDragIndicatorWrapper>
<Box className="mb-4" style={{ width: "100%" }}> <Box className="mb-4" style={{ width: "100%" }}>
<HStack space="md" style={{ width: "100%" }}> <HStack space="md" style={{ width: "100%" }}>
<FormControl <FormControl style={{ flex: 1 }}>
style={{ flex: 1 }}>
<Input> <Input>
<InputField <InputField
keyboardType="numeric" keyboardType="numeric"
placeholder="Od:" placeholder="Od:"
value={params.priceFrom || ''} value={params.priceFrom || ""}
onChangeText={handlePriceFrom} onChangeText={handlePriceFrom}
/> />
</Input> </Input>
</FormControl> </FormControl>
<FormControl <FormControl style={{ flex: 1 }}>
style={{ flex: 1 }}>
<Input> <Input>
<InputField <InputField
keyboardType="numeric" keyboardType="numeric"
placeholder="Do:" placeholder="Do:"
value={params.priceTo || ''} value={params.priceTo || ""}
onChangeText={handlePriceTo} onChangeText={handlePriceTo}
/> />
</Input> </Input>
@@ -265,7 +285,7 @@ export default function Notices() {
<Box className="mb-4" style={{ flex: 1 }}> <Box className="mb-4" style={{ flex: 1 }}>
<Select <Select
style={{ flex: 1 }} style={{ flex: 1 }}
selectedValue={params.category || ''} selectedValue={params.category || ""}
onValueChange={handleCategorySelect} onValueChange={handleCategorySelect}
> >
<SelectTrigger variant="outline" size="md"> <SelectTrigger variant="outline" size="md">
@@ -274,25 +294,27 @@ export default function Notices() {
placeholder="Wybierz kategorię" placeholder="Wybierz kategorię"
value={selectedCategory ? selectedCategory.label : ""} value={selectedCategory ? selectedCategory.label : ""}
/> />
<SelectIcon style={{ marginRight: 12 }} as={ChevronDownIcon} /> <SelectIcon
style={{ marginRight: 12 }}
as={ChevronDownIcon}
/>
</SelectTrigger> </SelectTrigger>
<SelectPortal> <SelectPortal>
<SelectBackdrop /> <SelectBackdrop />
<SelectContent <SelectContent style={{ maxHeight: SCREEN_HEIGHT * 0.6 }}>
style={{ maxHeight: SCREEN_HEIGHT * 0.6}}
>
<SelectDragIndicatorWrapper> <SelectDragIndicatorWrapper>
<SelectDragIndicator /> <SelectDragIndicator />
</SelectDragIndicatorWrapper> </SelectDragIndicatorWrapper>
<FlatList <FlatList
style={{ width: '100%' }} style={{ width: "100%" }}
data={categories} data={categories}
keyExtractor={(item) => item.value?.toString() || item.id?.toString() || Math.random().toString()} keyExtractor={(item) =>
item.value?.toString() ||
item.id?.toString() ||
Math.random().toString()
}
renderItem={({ item }) => ( renderItem={({ item }) => (
<SelectItem <SelectItem label={item.label} value={item.value} />
label={item.label}
value={item.value}
/>
)} )}
/> />
</SelectContent> </SelectContent>
@@ -302,35 +324,43 @@ export default function Notices() {
</KeyboardAwareScrollView> </KeyboardAwareScrollView>
</ActionsheetContent> </ActionsheetContent>
</Actionsheet> </Actionsheet>
<Actionsheet isOpen={showSortSheet} onClose={() => setShowSortSheet(false)}> <Actionsheet
isOpen={showSortSheet}
onClose={() => setShowSortSheet(false)}
>
<ActionsheetBackdrop /> <ActionsheetBackdrop />
<ActionsheetContent> <ActionsheetContent>
<ActionsheetDragIndicatorWrapper> <ActionsheetDragIndicatorWrapper>
<ActionsheetDragIndicator /> <ActionsheetDragIndicator />
</ActionsheetDragIndicatorWrapper> </ActionsheetDragIndicatorWrapper>
<ActionsheetItem <ActionsheetItem
className={ !params.sort ? 'bg-gray-200' : ''} className={!params.sort ? "bg-gray-200" : ""}
onPress={() => handleSort()}> onPress={() => handleSort()}
>
<ActionsheetItemText>Trafność</ActionsheetItemText> <ActionsheetItemText>Trafność</ActionsheetItemText>
</ActionsheetItem> </ActionsheetItem>
<ActionsheetItem <ActionsheetItem
className={ params.sort == 'latest' ? 'bg-gray-200' : ''} className={params.sort == "latest" ? "bg-gray-200" : ""}
onPress={() => handleSort('latest')}> onPress={() => handleSort("latest")}
>
<ActionsheetItemText>Najnowsze</ActionsheetItemText> <ActionsheetItemText>Najnowsze</ActionsheetItemText>
</ActionsheetItem> </ActionsheetItem>
<ActionsheetItem <ActionsheetItem
className={ params.sort == 'oldest' ? 'bg-gray-200' : ''} className={params.sort == "oldest" ? "bg-gray-200" : ""}
onPress={() => handleSort('oldest')}> onPress={() => handleSort("oldest")}
>
<ActionsheetItemText>Najstarsze</ActionsheetItemText> <ActionsheetItemText>Najstarsze</ActionsheetItemText>
</ActionsheetItem> </ActionsheetItem>
<ActionsheetItem <ActionsheetItem
className={ params.sort == 'cheapest' ? 'bg-gray-200' : ''} className={params.sort == "cheapest" ? "bg-gray-200" : ""}
onPress={() => handleSort('cheapest')}> onPress={() => handleSort("cheapest")}
>
<ActionsheetItemText>Najtańsze</ActionsheetItemText> <ActionsheetItemText>Najtańsze</ActionsheetItemText>
</ActionsheetItem> </ActionsheetItem>
<ActionsheetItem <ActionsheetItem
className={ params.sort == 'expensive' ? 'bg-gray-200' : ''} className={params.sort == "expensive" ? "bg-gray-200" : ""}
onPress={() => handleSort('expensive')}> onPress={() => handleSort("expensive")}
>
<ActionsheetItemText>Najdroższe</ActionsheetItemText> <ActionsheetItemText>Najdroższe</ActionsheetItemText>
</ActionsheetItem> </ActionsheetItem>
</ActionsheetContent> </ActionsheetContent>
@@ -338,6 +368,9 @@ export default function Notices() {
<FlatList <FlatList
data={filteredNotices} data={filteredNotices}
numColumns={2} numColumns={2}
// numColumns={2}
// columnContainerClassName="m-2"
columnWrapperClassName="m-2"
columnWrapperStyle={{ gap: 8, marginHorizontal: 8 }} columnWrapperStyle={{ gap: 8, marginHorizontal: 8 }}
contentContainerStyle={{ paddingBottom: 16 }} contentContainerStyle={{ paddingBottom: 16 }}
renderItem={({ item }) => <NoticeCard notice={item} />} renderItem={({ item }) => <NoticeCard notice={item} />}

View File

@@ -17,6 +17,7 @@ return (
}} }}
> >
<Stack.Screen name="(tabs)" options={{ headerShown: false }} /> <Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="user" options={{ headerShown: false }} />
<Stack.Screen <Stack.Screen
name="(auth)/login" name="(auth)/login"
options={{ headerShown: false }}/> options={{ headerShown: false }}/>

View File

@@ -5,6 +5,7 @@ import { Heading } from "@/components/ui/heading";
import { Image } from "@/components/ui/image"; import { Image } from "@/components/ui/image";
import { Text } from "@/components/ui/text"; import { Text } from "@/components/ui/text";
import { VStack } from "@/components/ui/vstack"; import { VStack } from "@/components/ui/vstack";
import { Avatar, AvatarImage, AvatarFallbackText } from "@gluestack-ui/themed";
import { Ionicons } from "@expo/vector-icons"; import { Ionicons } from "@expo/vector-icons";
import { import {
ActivityIndicator, ActivityIndicator,
@@ -12,14 +13,16 @@ import {
FlatList, FlatList,
View, View,
TextInput, TextInput,
SafeAreaView, Alert,
} from "react-native"; } from "react-native";
import { useEffect, useState, useRef } from "react"; import { useEffect, useState, useRef } from "react";
import { useNoticesStore } from "@/store/noticesStore"; import { useNoticesStore } from "@/store/noticesStore";
import { useWishlist } from "@/store/wishlistStore"; import { useWishlist } from "@/store/wishlistStore";
import { Pressable, ScrollView } from "react-native"; import { Pressable, ScrollView } from "react-native";
import { getUserById } from "@/api/client"; import { getUserById } from "@/api/client";
import * as ScreenOrientation from "expo-screen-orientation";
const { width } = Dimensions.get("window"); import { useAuthStore } from "@/store/authStore";
import { sendEmail } from "@/api/email";
export default function NoticeDetails() { export default function NoticeDetails() {
const { id } = useLocalSearchParams(); const { id } = useLocalSearchParams();
@@ -30,20 +33,74 @@ export default function NoticeDetails() {
const [notice, setNotice] = useState(null); const [notice, setNotice] = useState(null);
const [user, setUser] = useState(null); const [user, setUser] = useState(null);
const [isUserLoading, setIsUserLoading] = useState(true); const [isUserLoading, setIsUserLoading] = useState(true);
const [isLandscape, setIsLandscape] = useState(false);
const flatListRef = useRef(null); const flatListRef = useRef(null);
const [currentIndex, setCurrentIndex] = useState(0); const [currentIndex, setCurrentIndex] = useState(0);
const [isMessageFormVisible, setIsMessageFormVisible] = useState(false); const [isMessageFormVisible, setIsMessageFormVisible] = useState(false);
const [message, setMessage] = useState(""); const [message, setMessage] = useState("");
const [Email, setEmail] = useState(""); const [isSending, setIsSending] = useState(false);
const handleSendMessage = () => {
console.log("Wiadomość do:", user?.email);
console.log("Email nadawcy:", Email);
console.log("Treść:", message);
const handleSendMessage = async () => {
setIsSending(true);
console.log("Rozpoczynanie procesu wysyłania wiadomości...");
const { user_id, token } = useAuthStore.getState();
console.log("Dane z authStore:", { user_id, token });
if (!user_id || !token) {
console.error("Brak danych zalogowanego użytkownika.");
Alert.alert("Błąd", "Zaloguj się, aby wysłać wiadomość.");
setIsSending(false);
return;
}
let currentUserEmail = "";
try {
console.log(`Pobieranie danych użytkownika dla user_id: ${user_id}`);
const currentUser = await getUserById(user_id);
console.log("Dane zalogowanego użytkownika:", currentUser);
currentUserEmail = currentUser?.email;
if (!currentUserEmail) {
console.error("Nie znaleziono adresu email zalogowanego użytkownika.");
Alert.alert("Błąd", "Nie znaleziono adresu email zalogowanego użytkownika.");
setIsSending(false);
return;
}
console.log(`Pobrano email zalogowanego użytkownika: ${currentUserEmail}`);
} catch (error) {
console.error("Błąd podczas pobierania danych użytkownika:", error);
Alert.alert("Błąd", "Nie udało się pobrać danych użytkownika. Spróbuj ponownie później.");
setIsSending(false);
return;
}
const emailData = {
to: user?.email || "",
subject: `Zapytanie ${currentUserEmail} o ogłoszenie ${notice.title}`,
body: message,
};
console.log("Dane emaila do wysyłki:", emailData);
if (!emailData.to || !emailData.subject || !emailData.body) {
console.error("Walidacja nieudana: brakujące pola w emailData.");
Alert.alert("Błąd", "Wszystkie pola są wymagane!");
setIsSending(false);
return;
}
const result = await sendEmail(emailData);
if (result.success) {
console.log("Wiadomość wysłana pomyślnie!", result.result);
setIsMessageFormVisible(false); setIsMessageFormVisible(false);
setMessage(""); setMessage("");
setEmail(""); Alert.alert("Sukces", "Wiadomość została wysłana!");
} else {
console.error("Błąd podczas wysyłania wiadomości:", result.error);
Alert.alert("Błąd", `Nie udało się wysłać wiadomości: ${result.error}`);
}
setIsSending(false);
console.log("Zakończono proces wysyłania wiadomości.");
}; };
const formatDate = (dateString) => { const formatDate = (dateString) => {
@@ -63,6 +120,7 @@ export default function NoticeDetails() {
const isInWishlist = useWishlist((state) => const isInWishlist = useWishlist((state) =>
id ? state.wishlistNotices.some((item) => item.noticeId == id) : false id ? state.wishlistNotices.some((item) => item.noticeId == id) : false
); );
const onViewableItemsChanged = useRef(({ viewableItems }) => { const onViewableItemsChanged = useRef(({ viewableItems }) => {
if (viewableItems.length > 0) { if (viewableItems.length > 0) {
setCurrentIndex(viewableItems[0].index); setCurrentIndex(viewableItems[0].index);
@@ -73,6 +131,51 @@ export default function NoticeDetails() {
itemVisiblePercentThreshold: 70, itemVisiblePercentThreshold: 70,
}).current; }).current;
useEffect(() => {
const unlockOrientation = async () => {
try {
await ScreenOrientation.unlockAsync();
} catch (err) {
console.error("Error unlocking orientation:", err);
}
};
const getInitialOrientation = async () => {
try {
const orientation = await ScreenOrientation.getOrientationAsync();
setIsLandscape(
orientation === ScreenOrientation.Orientation.LANDSCAPE_LEFT ||
orientation === ScreenOrientation.Orientation.LANDSCAPE_RIGHT
);
} catch (err) {
console.error("Error getting initial orientation:", err);
}
};
unlockOrientation();
getInitialOrientation();
const subscription = ScreenOrientation.addOrientationChangeListener(
({ orientationInfo }) => {
const isLandscapeMode =
orientationInfo.orientation ===
ScreenOrientation.Orientation.LANDSCAPE_LEFT ||
orientationInfo.orientation ===
ScreenOrientation.Orientation.LANDSCAPE_RIGHT;
setIsLandscape(isLandscapeMode);
}
);
return () => {
ScreenOrientation.removeOrientationChangeListener(subscription);
ScreenOrientation.lockAsync(
ScreenOrientation.OrientationLock.PORTRAIT_UP
).catch((err) =>
console.error("Error locking orientation on unmount:", err)
);
};
}, []);
useEffect(() => { useEffect(() => {
const fetchNotice = async () => { const fetchNotice = async () => {
setIsLoading(true); setIsLoading(true);
@@ -100,6 +203,7 @@ export default function NoticeDetails() {
if (notice) { if (notice) {
try { try {
const fetchedImages = await getAllImagesByNoticeId(notice.noticeId); const fetchedImages = await getAllImagesByNoticeId(notice.noticeId);
console.log("Fetched images:", fetchedImages);
setImages( setImages(
fetchedImages && fetchedImages.length > 0 fetchedImages && fetchedImages.length > 0
? fetchedImages ? fetchedImages
@@ -107,7 +211,7 @@ export default function NoticeDetails() {
); );
} catch (err) { } catch (err) {
console.error("Error while loading images:", err); console.error("Error while loading images:", err);
setImage("https://http.cat/404.jpg"); setImages(["https://http.cat/404.jpg"]);
} finally { } finally {
setIsImageLoading(false); setIsImageLoading(false);
} }
@@ -142,26 +246,28 @@ export default function NoticeDetails() {
} }
if (error) { if (error) {
return <Text>Błąd, spróbuj ponownie żniej: {error.message}</Text>; return <Text>Błąd, spróbuj ponownie źniej: {error.message}</Text>;
} }
if (!notice) { if (!notice) {
return <Text>Nie znaleziono ogłoszenia</Text>; return <Text>Nie znaleziono ogłoszenia</Text>;
} }
const renderImageSection = () => {
if (isImageLoading) {
return ( return (
<Card className="p-0 rounded-lg m-3 flex-1"> <Box
<Stack.Screen className={`h-auto w-full rounded-md ${
options={{ isLandscape ? "h-screen" : "aspect-[1/1]"
title: notice.title, } bg-gray-100 items-center justify-center`}
}} >
/>
{isImageLoading ? (
<Box className="h-auto w-full rounded-md aspect-[1/1] bg-gray-100 items-center justify-center">
<ActivityIndicator size="large" color="#3b82f6" /> <ActivityIndicator size="large" color="#3b82f6" />
</Box> </Box>
) : ( );
<Box className="sticky top-0 z-10 bg-white"> }
return (
<Box className={isLandscape ? "h-screen" : "sticky top-0 z-10 bg-white"}>
<FlatList <FlatList
ref={flatListRef} ref={flatListRef}
data={images} data={images}
@@ -173,48 +279,58 @@ export default function NoticeDetails() {
onViewableItemsChanged={onViewableItemsChanged} onViewableItemsChanged={onViewableItemsChanged}
viewabilityConfig={viewabilityConfig} viewabilityConfig={viewabilityConfig}
renderItem={({ item, index }) => ( renderItem={({ item, index }) => (
<View style={{ width: width }}> <View style={{ width: Dimensions.get("window").width }}>
<Image <Image
source={{ uri: item }} source={{ uri: item }}
className="h-auto w-full rounded-md aspect-square" className={`h-auto w-full rounded-md ${
isLandscape ? "h-full" : "aspect-square"
}`}
alt={`Zdjęcie ${index + 1}`} alt={`Zdjęcie ${index + 1}`}
resizeMode="contain" resizeMode={isLandscape ? "cover" : "contain"}
onError={(e) => console.error("Image load error:", e.nativeEvent.error)}
/> />
</View> </View>
)} )}
keyExtractor={(item, index) => index.toString()} keyExtractor={(item, index) => index.toString()}
/> />
{images.length > 1 && ( {images.length > 1 && (
<Box className="flex-row justify-center mt-2"> <Box className="flex-row justify-center mt-2">
{images.map((_, index) => ( {images.map((_, index) => (
<Box <Box
key={index} key={index}
className={`w-2 h-2 rounded-full mx-1 ${ className={`w-2 h-2 rounded-full mx-1 ${
index === currentIndex ? "bg-primary-500" : "bg-gray-300" index === currentIndex ? "bg-primary-500" : "bg-gray-500"}
}`} }`}
/> />
))} ))}
</Box> </Box>
)} )}
</Box> </Box>
)} );
};
return (
<SafeAreaView style={{ flex: 1 }}>
<Card className="flex-1 p-4 m-3 rounded-lg shadow-sm">
<Stack.Screen
options={{
title: notice.title,
}}
/>
<ScrollView showsVerticalScrollIndicator={false}> <ScrollView showsVerticalScrollIndicator={false}>
<VStack className="p-2"> {renderImageSection()}
<Text className="text-sm font-normal mb-2 text-typography-700"> <VStack className="p-4">
<Text className="text-sm font-normal mb-2 text-gray-600">
{formatDate(notice.publishDate)} {formatDate(notice.publishDate)}
</Text> </Text>
<Text className="text-2xl text-gray-950 font-bold mb-2 text-center bg-gray-50 rounded-md p-2"> <Text className="text-2xl font-bold mb-2 text-center bg-gray-100 rounded-md p-4">
{notice.title} {notice.title}
</Text> </Text>
<Box className="flex-row items-center bg-gray-100 rounded-md p-2">
<Box className="flex-row items-center bg-gray-50 rounded-md p-2"> <Heading size="md" className="flex-1 text-lg">
<Heading size="md" className="flex-1 text-xl text-gray-950"> <Text className="text-sm text-gray-500">Cena: </Text>
<Text className="text-sm text-typography-500">Cena: </Text>
{notice.price} {notice.price}
</Heading> </Heading>
<Pressable <Pressable
onPress={() => { onPress={() => {
toggleNoticeInWishlist(id); toggleNoticeInWishlist(id);
@@ -223,58 +339,59 @@ export default function NoticeDetails() {
<Ionicons <Ionicons
name={isInWishlist ? "heart" : "heart-outline"} name={isInWishlist ? "heart" : "heart-outline"}
size={24} size={24}
color={"primary-heading-500"} color="#3b82f6"
/> />
</Pressable> </Pressable>
</Box> </Box>
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm"> <Box className="mt-4 bg-gray-100 p-3 rounded-lg">
<Text className="text-sm text-typography-500"> <Text className="text-sm text-gray-500">
Kategoria:{" "} Kategoria:{" "}
<Text className="font-bold text-gray-950">{notice.category}</Text> <Text className="font-bold text-gray-900">{notice.category}</Text>
</Text> </Text>
</Box> </Box>
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm"> <Box className="mt-4 bg-gray-100 p-3 rounded-lg">
<Text className="text-2xl text-gray-950">Opis ogloszenia</Text> <Text className="text-xl font-bold text-gray-900">Opis ogłoszenia</Text>
<Text className="text-sm text-typography-700"> <Text className="text-sm text-gray-700">{notice.description}</Text>
{notice.description}
</Text>
</Box> </Box>
<Box className="mt-4 bg-gray-100 p-3 rounded-lg">
<Box className="mt-4 bg-gray-50 p-3 rounded-lg shadow-sm"> <Text className="text-sm text-gray-500">Użytkownik:</Text>
<Text className="text-sm text-typography-500">Uzytkownik:</Text>
{isUserLoading ? ( {isUserLoading ? (
<ActivityIndicator /> <ActivityIndicator />
) : user ? ( ) : user ? (
<> <>
<Box className="mr-4"> <Box className="mr-4">
<Image <Avatar size="md">
<AvatarImage
source={{ source={{
uri: uri:
user.profileImage || user.image ||
"https://th.bing.com/th/id/OIP.3coo_N8sieled8QNroQmkgHaHa?rs=1&pid=ImgDetMain", "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" alt="Zdjęcie profilowe"
/> />
<AvatarFallbackText>
{user.firstName?.[0]}
{user.lastName?.[0]}
</AvatarFallbackText>
</Avatar>
</Box> </Box>
<Box className="flex-1"> <Box className="flex-1">
<Text className="text-xl font-bold text-gray-950"> <Text className="text-lg font-bold text-gray-900">
{user.firstName} {user.lastName} {user.firstName} {user.lastName}
</Text> </Text>
<Text className="text-sm text-typography-700"> <Text className="text-sm text-gray-700">
Email: {user.email} Email: {user.email}
</Text> </Text>
<Pressable <Pressable
onPress={() => setIsMessageFormVisible(true)} onPress={() => setIsMessageFormVisible(true)}
className="mt-3 bg-primary-500 py-2 px-4 rounded-md" className="mt-3 bg-blue-500 py-2 px-4 rounded-md"
> >
<Text className="text-white text-center font-bold"> <Text className="text-white text-center font-bold">
Wyślij wiadomość Wyślij wiadomość
</Text> </Text>
</Pressable> </Pressable>
<Link href={`/user/${notice.clientId}`}> <Link href={`/user/${notice.clientId}`}>
<Text className="text-xl p-3 font-bold text-center text-typography-700 mt-3"> <Text className="text-lg font-bold text-center text-blue-600 mt-3">
Zobacz więcej ogłoszeń od {user.firstName} Zobacz więcej ogłoszeń od {user.firstName}
</Text> </Text>
</Link> </Link>
@@ -292,19 +409,15 @@ export default function NoticeDetails() {
<Text className="text-lg font-bold mb-4"> <Text className="text-lg font-bold mb-4">
Wyślij wiadomość do {user?.firstName} Wyślij wiadomość do {user?.firstName}
</Text> </Text>
<Text className="text-sm font-medium mb-1">Do:</Text> <Text className="text-sm font-medium mb-1">Do:</Text>
<Text className="bg-gray-100 p-3 rounded text-gray-500"> <Text className="bg-gray-100 p-3 rounded text-gray-500">
{user?.email || "Brak adresu e-mail"} {user?.email || "Brak adresu e-mail"}
</Text> </Text>
<Text className="text-sm font-medium mb-1">Twój e-mail:</Text> <Text className="text-sm font-medium mb-1">Temat:</Text>
<TextInput <Text className="bg-gray-100 p-3 rounded text-gray-500">
className="border border-gray-300 p-2 rounded" Zapytanie o ogłoszenie '{notice.title || "Brak nazwy ogłoszenia"}'
placeholder="Wpisz swój adres e-mail" </Text>
value={Email} <Text className="text-sm font-medium mb-1">Treść:</Text>
onChangeText={setEmail}
/>
<TextInput <TextInput
className="border border-gray-300 rounded-md p-2 mb-4 h-32 text-left" className="border border-gray-300 rounded-md p-2 mb-4 h-32 text-left"
multiline multiline
@@ -313,7 +426,6 @@ export default function NoticeDetails() {
value={message} value={message}
onChangeText={setMessage} onChangeText={setMessage}
/> />
<View className="flex-row justify-end space-x-2"> <View className="flex-row justify-end space-x-2">
<Pressable <Pressable
onPress={() => setIsMessageFormVisible(false)} onPress={() => setIsMessageFormVisible(false)}
@@ -321,17 +433,22 @@ export default function NoticeDetails() {
> >
<Text className="text-gray-800">Anuluj</Text> <Text className="text-gray-800">Anuluj</Text>
</Pressable> </Pressable>
<Pressable <Pressable
onPress={handleSendMessage} onPress={handleSendMessage}
className="bg-primary-500 py-2 px-4 rounded-md" className="bg-blue-500 py-2 px-4 rounded-md"
disabled={isSending}
> >
{isSending ? (
<ActivityIndicator color="#fff" />
) : (
<Text className="text-white">Wyślij</Text> <Text className="text-white">Wyślij</Text>
)}
</Pressable> </Pressable>
</View> </View>
</View> </View>
</View> </View>
)} )}
</Card> </Card>
</SafeAreaView>
); );
} }

View File

@@ -0,0 +1,11 @@
import { Stack } from 'expo-router';
export default function UserLayout() {
return (
<Stack
screenOptions={{
headerTitle: 'Ogłoszenia użytkownika',
}}
/>
);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 KiB

View File

@@ -14,9 +14,13 @@ import {useEffect, useState} from "react";
export function NoticeCard({ notice }) { export function NoticeCard({ notice }) {
const noticeId = notice?.noticeId; const noticeId = notice?.noticeId;
const toggleNoticeInWishlist = useWishlist((state) => state.toggleNoticeInWishlist); const toggleNoticeInWishlist = useWishlist(
(state) => state.toggleNoticeInWishlist
);
const isInWishlist = useWishlist((state) => const isInWishlist = useWishlist((state) =>
noticeId ? state.wishlistNotices.some((item) => item.noticeId === noticeId) : false noticeId
? state.wishlistNotices.some((item) => item.noticeId === noticeId)
: false
); );
const [image, setImage] = useState(null); const [image, setImage] = useState(null);
@@ -40,7 +44,9 @@ export function NoticeCard({notice}) {
try { try {
const images = await getAllImagesByNoticeId(noticeId); const images = await getAllImagesByNoticeId(noticeId);
if (isMounted) { if (isMounted) {
setImage(images && images.length > 0 ? images[0] : "https://http.cat/404.jpg"); setImage(
images && images.length > 0 ? images[0] : "https://http.cat/404.jpg"
);
} }
} catch (error) { } catch (error) {
console.error(`Error while loading image: ${error}`); console.error(`Error while loading image: ${error}`);

File diff suppressed because it is too large Load Diff

View File

@@ -36,10 +36,10 @@
"@tanstack/react-query": "^5.74.4", "@tanstack/react-query": "^5.74.4",
"axios": "^1.9.0", "axios": "^1.9.0",
"babel-plugin-module-resolver": "^5.0.2", "babel-plugin-module-resolver": "^5.0.2",
"expo": "^53.0.0", "expo": "^53.0.10",
"expo-auth-session": "~6.1.5", "expo-auth-session": "~6.2.0",
"expo-camera": "~16.1.6", "expo-camera": "~16.1.7",
"expo-constants": "~17.1.6", "expo-constants": "~17.1.5",
"expo-image-picker": "~16.1.4", "expo-image-picker": "~16.1.4",
"expo-linking": "~7.1.4", "expo-linking": "~7.1.4",
"expo-router": "~5.0.5", "expo-router": "~5.0.5",
@@ -51,7 +51,7 @@
"nativewind": "^4.1.23", "nativewind": "^4.1.23",
"react": "19.0.0", "react": "19.0.0",
"react-dom": "19.0.0", "react-dom": "19.0.0",
"react-native": "0.79.2", "react-native": "0.79.3",
"react-native-css-interop": "^0.1.22", "react-native-css-interop": "^0.1.22",
"react-native-gesture-handler": "~2.24.0", "react-native-gesture-handler": "~2.24.0",
"react-native-keyboard-aware-scroll-view": "^0.9.5", "react-native-keyboard-aware-scroll-view": "^0.9.5",
@@ -62,7 +62,8 @@
"react-native-web": "~0.20.0", "react-native-web": "~0.20.0",
"tailwindcss": "^3.4.17", "tailwindcss": "^3.4.17",
"zustand": "^5.0.3", "zustand": "^5.0.3",
"expo-crypto": "~14.1.4" "expo-crypto": "~14.1.4",
"expo-screen-orientation": "~8.1.7"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.20.0", "@babel/core": "^7.20.0",