fix integration

This commit is contained in:
2025-06-05 21:40:30 +02:00
parent 3bd3b9b70d
commit 48cf5cd6c4
9 changed files with 92 additions and 33 deletions

View File

@@ -1,30 +1,46 @@
import { View, FlatList} from 'react-native';
import { useEffect, useState } from 'react'
import { useAuthStore } from "@/store/authStore";
import { Heading } from '@/components/ui/heading';
import { Text } from '@/components/ui/text';
import { Link } from 'expo-router';
import { Pressable } from '@/components/ui/pressable';
import axios from 'axios';
// import axios from 'axios';
import {listCategories} from "@/api/categories";
export function CategorySection({notices, title}) {
// const notices = useNoticesStore((state) => state.notices);
const token = useAuthStore((state) => state.token);
const [categoryMap, setCategoryMap] = useState({});
useEffect(() => {
axios.get('https://testowe.zikor.pl/api/v1/vars/categories')
.then(res => setCategoryMap(res.data))
.catch(() => setCategoryMap({}));
}, []);
const categories = Array.from(
new Set(notices.map((notice) => notice.category))
).filter(Boolean);
if(token){
const fetchCategories = async () => {
let data = await listCategories();
if (Array.isArray(data)) {
setCategoryMap(data);
}
}
fetchCategories();
}
}, [token]);
const categories = Array.from(
new Set(notices.map((notice) => notice.category))
).filter(Boolean);
const getCount = (category) =>
notices.filter((notice) => notice.category === category).length;
console.log("CategoryMap:", categoryMap);
if(!categoryMap) {
return null;
}
return (
<View className="mb-6">
<Heading className="text-2xl font-bold mb-4 mt-4">{title}</Heading>