category and logout fiexes

This commit is contained in:
Patryk
2025-06-09 21:17:30 +02:00
parent 207f8f7161
commit c2d4f5fb79
5 changed files with 21 additions and 31 deletions

View File

@@ -8,7 +8,9 @@ export async function listCategories() {
const headers = token ? { Authorization: `Bearer ${token}` } : {}; const headers = token ? { Authorization: `Bearer ${token}` } : {};
try { try {
const response = await axios.get(`${API_URL}/vars/categories`, { headers: headers }); const response = await axios.get(`${API_URL}/vars/categories`, {
headers: 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);

View File

@@ -28,7 +28,6 @@ export async function getWishlist() {
try { try {
const response = await axios.get(`${API_URL}/`, { headers }); const response = await axios.get(`${API_URL}/`, { headers });
console.log("Wishlist response:", response.data);
return response.data; return response.data;
} catch (error) { } catch (error) {
console.error("Error fetching wishlist:", error); console.error("Error fetching wishlist:", error);

View File

@@ -4,27 +4,25 @@ import { NoticeCard } from "@/components/NoticeCard";
import { Ionicons } from "@expo/vector-icons"; import { Ionicons } from "@expo/vector-icons";
import { Box } from "@/components/ui/box"; import { Box } from "@/components/ui/box";
import { Text } from "@/components/ui/text"; import { Text } from "@/components/ui/text";
import {useCallback} from "react"; import { useCallback } from "react";
import { useFocusEffect } from "@react-navigation/native"; import { useFocusEffect } from "@react-navigation/native";
export default function Wishlist() { export default function Wishlist() {
const wishlistNotices = useWishlist((state) => state.wishlistNotices); const wishlistNotices = useWishlist((state) => state.wishlistNotices);
const fetchWishlist = useWishlist((state) => state.fetchWishlist); const fetchWishlist = useWishlist((state) => state.fetchWishlist);
useFocusEffect( useFocusEffect(
useCallback(() => { useCallback(() => {
fetchWishlist(); fetchWishlist();
}, [fetchWishlist]) }, [fetchWishlist])
); );
const styles = { const styles = {
container: { container: {
margin: 10, margin: 10,
} },
} };
// console.log("Wishlist notices:", wishlistNotices);
if (wishlistNotices.length === 0) { if (wishlistNotices.length === 0) {
return ( return (
<Box style={styles.container} className="flex-row flex-1 justify-center"> <Box style={styles.container} className="flex-row flex-1 justify-center">

View File

@@ -19,7 +19,7 @@ export function CategorySection({ notices, title }) {
}; };
fetchCategories(); fetchCategories();
}); }, []);
const categories = Array.from( const categories = Array.from(
new Set(notices.map((notice) => notice.category)) new Set(notices.map((notice) => notice.category))

View File

@@ -2,6 +2,7 @@ import { create } from "zustand";
import { createJSONStorage, persist } from "zustand/middleware"; 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";
import { router } from "expo-router";
const API_URL = "https://hopp.zikor.pl/api/v1"; const API_URL = "https://hopp.zikor.pl/api/v1";
@@ -104,34 +105,24 @@ export const useAuthStore = create(
}, },
signOut: async () => { signOut: async () => {
const { token } = get();
const headers = token ? { Authorization: `Bearer ${token}` } : {};
try { try {
await axios.post(`${API_URL}/auth/logout`); await axios.post(
`${API_URL}/auth/logout`,
{},
{
headers: headers,
}
);
} catch (error) { } catch (error) {
console.error("Logout error:", error); console.error("Logout error:", error);
} finally { } finally {
delete axios.defaults.headers.common["Authorization"]; delete axios.defaults.headers.common["Authorization"];
set({ user_id: null, token: null }); set({ user_id: null, token: null });
router.replace("/login");
} }
}, },
// checkAuth: async () => {
// const { token } = useAuthStore.getState();
// if (!token) return null;
// set({ isLoading: true });
// try {
// axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
// const response = await axios.get(`${API_URL}/auth/me`);
// set({ user_id: response.data, isLoading: false });
// return response.data;
// } catch (error) {
// delete axios.defaults.headers.common["Authorization"];
// set({ user_id: null, token: null, isLoading: false });
// return null;
// }
// },
}; };
}, },
{ {