Compare commits
2 Commits
wishlistIn
...
df44742a7b
| Author | SHA1 | Date | |
|---|---|---|---|
| df44742a7b | |||
| 48cf5cd6c4 |
@@ -1,10 +1,15 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import {useAuthStore} from "@/store/authStore";
|
||||||
|
|
||||||
const API_URL = "https://testowe.zikor.pl/api/v1";
|
const API_URL = "https://testowe.zikor.pl/api/v1";
|
||||||
|
|
||||||
export async function listCategories() {
|
export async function listCategories() {
|
||||||
|
|
||||||
|
const { token } = useAuthStore.getState();
|
||||||
|
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${API_URL}/vars/categories`);
|
const response = await axios.get(`${API_URL}/vars/categories`, { headers });
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Nie udało się pobrać listy kategorii.", err.response.status);
|
console.error("Nie udało się pobrać listy kategorii.", err.response.status);
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import axios from "axios";
|
|||||||
import FormData from 'form-data'
|
import FormData from 'form-data'
|
||||||
import {useAuthStore} from "@/store/authStore";
|
import {useAuthStore} from "@/store/authStore";
|
||||||
|
|
||||||
// const API_URL = "https://testowe.zikor.pl/api/v1";
|
const API_URL = "https://testowe.zikor.pl/api/v1";
|
||||||
|
|
||||||
const API_URL = "http://10.0.2.2:8080/api/v1";
|
//const API_URL = "http://10.0.2.2:8080/api/v1";
|
||||||
|
|
||||||
export async function listNotices() {
|
export async function listNotices() {
|
||||||
const { token } = useAuthStore.getState();
|
const { token } = useAuthStore.getState();
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import {useAuthStore} from "@/store/authStore";
|
||||||
// import FormData from 'form-data'
|
// import FormData from 'form-data'
|
||||||
|
|
||||||
const API_URL = "https://testowe.zikor.pl/api/v1/wishlist";
|
const API_URL = "https://testowe.zikor.pl/api/v1/wishlist";
|
||||||
|
|
||||||
export async function toggleNoticeStatus(noticeId) {
|
export async function toggleNoticeStatus(noticeId) {
|
||||||
|
const { token } = useAuthStore.getState();
|
||||||
|
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(`${API_URL}/toggle/${noticeId}`, null, {
|
const response = await axios.post(`${API_URL}/toggle/${noticeId}`, {}, {
|
||||||
headers: {
|
headers
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -18,8 +20,11 @@ export async function toggleNoticeStatus(noticeId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getWishlist() {
|
export async function getWishlist() {
|
||||||
|
const { token } = useAuthStore.getState();
|
||||||
|
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${API_URL}/`);
|
const response = await axios.get(`${API_URL}/`, {headers});
|
||||||
console.log("Wishlist response:", response.data);
|
console.log("Wishlist response:", response.data);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,4 +1,16 @@
|
|||||||
import { Text } from "@/components/ui/text";
|
import { Text } from "@/components/ui/text";
|
||||||
|
import { View } from "react-native";
|
||||||
|
import { Button, ButtonText } from "@gluestack-ui/themed";
|
||||||
|
import { useAuthStore } from "@/store/authStore";
|
||||||
|
|
||||||
export default function User() {
|
export default function User() {
|
||||||
return <Text>Użytkownik</Text>;
|
const signOut = useAuthStore((state) => state.signOut);
|
||||||
|
|
||||||
|
return (<View>
|
||||||
|
<Text>Użytkownik</Text>
|
||||||
|
<Button onPress={signOut}>
|
||||||
|
<ButtonText>Wyloguj się</ButtonText>
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,14 @@ import { FlatList } from 'react-native';
|
|||||||
import { useAuthStore } from "@/store/authStore";
|
import { useAuthStore } from "@/store/authStore";
|
||||||
import { useRouter } from "expo-router";
|
import { useRouter } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
// import { SafeAreaView } from "react-native-safe-area-context";
|
||||||
|
import { SafeAreaView } from "react-native";
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const token = useAuthStore((state) => state.token);
|
const token = useAuthStore((state) => state.token);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isReady, setIsReady] = useState(false);
|
const [isReady, setIsReady] = useState(false);
|
||||||
|
const fetchNotices = useNoticesStore((state) => state.fetchNotices);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsReady(true);
|
setIsReady(true);
|
||||||
@@ -23,23 +27,36 @@ const token = useAuthStore((state) => state.token);
|
|||||||
}
|
}
|
||||||
}, [isReady, token, router]);
|
}, [isReady, token, router]);
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (token) {
|
||||||
|
fetchNotices();
|
||||||
|
}
|
||||||
|
}, [token, fetchNotices]);
|
||||||
|
|
||||||
|
|
||||||
const notices = useNoticesStore((state) => state.notices);
|
const notices = useNoticesStore((state) => state.notices);
|
||||||
const latestNotices = [...notices]
|
// console.log("Notices:", notices);
|
||||||
|
|
||||||
|
const latestNotices = [...notices]
|
||||||
.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 = [...notices]
|
||||||
.sort(() => Math.random() - 0.5)
|
.sort(() => Math.random() - 0.5)
|
||||||
.slice(0, 6);
|
.slice(0, 6);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View>
|
<SafeAreaView className="flex-1 m-2">
|
||||||
|
{/* <View> */}
|
||||||
<SearchSection/>
|
<SearchSection/>
|
||||||
<ScrollView showsVerticalScrollIndicator={false} className='m-2'>
|
<ScrollView showsVerticalScrollIndicator={false} >
|
||||||
<CategorySection title="Polecane kategorie" notices={notices} />
|
<CategorySection title="Polecane kategorie" notices={notices} />
|
||||||
<NoticeSection title="Najnowsze ogłoszenia" notices={latestNotices} ctaLink="/notices?sort=latest"/>
|
<NoticeSection title="Najnowsze ogłoszenia" notices={latestNotices} ctaLink="/notices?sort=latest"/>
|
||||||
<UserSection title="Popularni sprzedawcy" notices={notices} />
|
<UserSection title="Popularni sprzedawcy" notices={notices} />
|
||||||
<NoticeSection title="Proponowane ogłoszenia" notices={recomendedNotices} ctaLink="/notices"/>
|
<NoticeSection title="Proponowane ogłoszenia" notices={recomendedNotices} ctaLink="/notices"/>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</View>
|
{/* </View> */}
|
||||||
|
</SafeAreaView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,21 +2,13 @@ import { Stack, Redirect } from "expo-router";
|
|||||||
import "@/global.css";
|
import "@/global.css";
|
||||||
import { GluestackUIProvider } from "@/components/ui/gluestack-ui-provider";
|
import { GluestackUIProvider } from "@/components/ui/gluestack-ui-provider";
|
||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
import { useNoticesStore } from "@/store/noticesStore";
|
|
||||||
|
|
||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
export default function RootLayout() {
|
export default function RootLayout() {
|
||||||
const fetchNotices = useNoticesStore((state) => state.fetchNotices);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchNotices();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<GluestackUIProvider>
|
<GluestackUIProvider>
|
||||||
|
|
||||||
<Stack
|
<Stack
|
||||||
screenOptions={{
|
screenOptions={{
|
||||||
headerTintColor: "#1c1c1e",
|
headerTintColor: "#1c1c1e",
|
||||||
|
|||||||
@@ -1,30 +1,46 @@
|
|||||||
import { View, FlatList} from 'react-native';
|
import { View, FlatList} from 'react-native';
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
|
import { useAuthStore } from "@/store/authStore";
|
||||||
import { Heading } from '@/components/ui/heading';
|
import { Heading } from '@/components/ui/heading';
|
||||||
import { Text } from '@/components/ui/text';
|
import { Text } from '@/components/ui/text';
|
||||||
import { Link } from 'expo-router';
|
import { Link } from 'expo-router';
|
||||||
import { Pressable } from '@/components/ui/pressable';
|
import { Pressable } from '@/components/ui/pressable';
|
||||||
import axios from 'axios';
|
// import axios from 'axios';
|
||||||
|
import {listCategories} from "@/api/categories";
|
||||||
|
|
||||||
|
|
||||||
export function CategorySection({notices, title}) {
|
export function CategorySection({notices, title}) {
|
||||||
// const notices = useNoticesStore((state) => state.notices);
|
const token = useAuthStore((state) => state.token);
|
||||||
|
|
||||||
const [categoryMap, setCategoryMap] = useState({});
|
const [categoryMap, setCategoryMap] = useState({});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
axios.get('https://testowe.zikor.pl/api/v1/vars/categories')
|
if(token){
|
||||||
.then(res => setCategoryMap(res.data))
|
const fetchCategories = async () => {
|
||||||
.catch(() => setCategoryMap({}));
|
let data = await listCategories();
|
||||||
}, []);
|
if (Array.isArray(data)) {
|
||||||
|
setCategoryMap(data);
|
||||||
const categories = Array.from(
|
}
|
||||||
new Set(notices.map((notice) => notice.category))
|
}
|
||||||
).filter(Boolean);
|
|
||||||
|
|
||||||
|
fetchCategories();
|
||||||
|
}
|
||||||
|
}, [token]);
|
||||||
|
|
||||||
|
|
||||||
|
const categories = Array.from(
|
||||||
|
new Set(notices.map((notice) => notice.category))
|
||||||
|
).filter(Boolean);
|
||||||
|
|
||||||
const getCount = (category) =>
|
const getCount = (category) =>
|
||||||
notices.filter((notice) => notice.category === category).length;
|
notices.filter((notice) => notice.category === category).length;
|
||||||
|
|
||||||
|
console.log("CategoryMap:", categoryMap);
|
||||||
|
|
||||||
|
if(!categoryMap) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View className="mb-6">
|
<View className="mb-6">
|
||||||
<Heading className="text-2xl font-bold mb-4 mt-4">{title}</Heading>
|
<Heading className="text-2xl font-bold mb-4 mt-4">{title}</Heading>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Input, InputField, InputIcon, InputSlot } from "@/components/ui/input"
|
|||||||
import { SearchIcon } from "@/components/ui/icon"
|
import { SearchIcon } from "@/components/ui/icon"
|
||||||
import { Box } from "@/components/ui/box"
|
import { Box } from "@/components/ui/box"
|
||||||
import { useRouter } from "expo-router";
|
import { useRouter } from "expo-router";
|
||||||
|
import { View } from "react-native";
|
||||||
|
|
||||||
export function SearchSection({ searchQuery, setSearchQuery }) {
|
export function SearchSection({ searchQuery, setSearchQuery }) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -14,18 +15,17 @@ export function SearchSection({ searchQuery, setSearchQuery }) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<Box className="m-2 bg-white">
|
<Box className="mb-2 bg-white p-2 rounded-md">
|
||||||
<Input>
|
<Input className="p-2">
|
||||||
<InputSlot>
|
<InputSlot>
|
||||||
<InputIcon as={SearchIcon} />
|
<InputIcon as={SearchIcon} />
|
||||||
</InputSlot>
|
</InputSlot>
|
||||||
<InputField placeholder="Wyszukaj.."
|
<InputField placeholder="Wyszukaj..."
|
||||||
value={searchQuery}
|
value={searchQuery}
|
||||||
onChangeText={setSearchQuery}
|
onChangeText={setSearchQuery}
|
||||||
onSubmitEditing={handleSubmit}
|
onSubmitEditing={handleSubmit}
|
||||||
returnKeyType="search" />
|
returnKeyType="search" />
|
||||||
</Input>
|
</Input>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -4,16 +4,21 @@ import { Heading } from '@/components/ui/heading';
|
|||||||
import { FlatList } from 'react-native';
|
import { FlatList } from 'react-native';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import UserBlock from '@/components/UserBlock';
|
import UserBlock from '@/components/UserBlock';
|
||||||
|
import {useAuthStore} from "@/store/authStore";
|
||||||
|
|
||||||
|
|
||||||
export function UserSection({notices, title}) {
|
export function UserSection({notices, title}) {
|
||||||
|
const token = useAuthStore((state) => state.token);
|
||||||
|
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
|
||||||
const [users, setUsers] = useState([]);
|
const [users, setUsers] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
axios.get('https://testowe.zikor.pl/api/v1/clients/get/all')
|
if (token){
|
||||||
|
axios.get('https://testowe.zikor.pl/api/v1/clients/get/all', { headers })
|
||||||
.then(res => setUsers(res.data))
|
.then(res => setUsers(res.data))
|
||||||
.catch(() => setUsers([]));
|
.catch(() => setUsers([]));
|
||||||
}, []);
|
}
|
||||||
|
}, [token]);
|
||||||
|
|
||||||
const usersWithNoticeCount = users.map(user => {
|
const usersWithNoticeCount = users.map(user => {
|
||||||
const count = notices.filter(n => n.clientId === user.id).length;
|
const count = notices.filter(n => n.clientId === user.id).length;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {createJSONStorage, persist} from "zustand/middleware";
|
|||||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
const API_URL = "http://10.0.2.2:8080/api/v1";
|
const API_URL = "https://testowe.zikor.pl/api/v1";
|
||||||
|
|
||||||
export const useAuthStore = create(
|
export const useAuthStore = create(
|
||||||
persist(
|
persist(
|
||||||
@@ -71,8 +71,10 @@ export const useAuthStore = create(
|
|||||||
|
|
||||||
signOut: async () => {
|
signOut: async () => {
|
||||||
try {
|
try {
|
||||||
|
const {token} = useAuthStore.getState();
|
||||||
|
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
|
||||||
// Можно отправить запрос на бэкенд для инвалидации токена
|
// Можно отправить запрос на бэкенд для инвалидации токена
|
||||||
await axios.post(`${API_URL}/auth/logout`);
|
await axios.post(`${API_URL}/auth/logout`, {}, { headers });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Logout error:", error);
|
console.error("Logout error:", error);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user