fix integration
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -4,16 +4,21 @@ import { Heading } from '@/components/ui/heading';
|
||||
import { FlatList } from 'react-native';
|
||||
import axios from 'axios';
|
||||
import UserBlock from '@/components/UserBlock';
|
||||
import {useAuthStore} from "@/store/authStore";
|
||||
|
||||
|
||||
export function UserSection({notices, title}) {
|
||||
|
||||
const token = useAuthStore((state) => state.token);
|
||||
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
|
||||
const [users, setUsers] = useState([]);
|
||||
|
||||
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))
|
||||
.catch(() => setUsers([]));
|
||||
}, []);
|
||||
}
|
||||
}, [token]);
|
||||
|
||||
const usersWithNoticeCount = users.map(user => {
|
||||
const count = notices.filter(n => n.clientId === user.id).length;
|
||||
|
||||
Reference in New Issue
Block a user