import React, { useState, useEffect } from "react"; import { View, Text, StyleSheet, TouchableOpacity, TextInput, FlatList, ActivityIndicator, LayoutAnimation, UIManager, Platform, Alert, } from "react-native"; import { Ionicons } from "@react-native-vector-icons/ionicons"; import colors from "../../components/colors"; import * as keychain from "react-native-keychain"; import { BASE_URL } from "../../utils/ApiUrls"; // Enable LayoutAnimation for Android if (Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental) { UIManager.setLayoutAnimationEnabledExperimental(true); } const GroupCard = ({ item }: { item: any }) => { const [expanded, setExpanded] = useState(false); const toggleExpand = () => { LayoutAnimation.easeInEaseOut(); setExpanded(!expanded); }; const initial = item.groupName ? item.groupName.charAt(0).toUpperCase() : "?"; return ( {initial} {item.groupName} {item.description} {item.visibility} • {item.cycleType} {expanded && ( {Object.entries(item).map(([key, value]) => ( {key}:{" "} {Array.isArray(value) ? value.join("-") : String(value)} ))} )} ); }; // ✅ Group List with Search const GroupList = () => { const [groups, setGroups] = useState([]); const [filteredGroups, setFilteredGroups] = useState([]); const [loading, setLoading] = useState(true); const [search, setSearch] = useState(""); useEffect(() => { const fetchGroups = async () => { const credentials = await keychain.getGenericPassword(); if (!credentials) { Alert.alert("Error", "You are not logged in"); return; } const token = credentials.password; try { const res = await fetch(`${BASE_URL}fund/getAll/my/groups`, { headers: { Accept: "*/*", Authorization: `Bearer ${token}` }, }); console.log("my groups response", res); const data = await res.json(); setGroups(data.data || []); setFilteredGroups(data.data || []); } catch (e) { console.error("API error", e); } finally { setLoading(false); } }; fetchGroups(); }, []); useEffect(() => { if (search.trim() === "") { setFilteredGroups(groups); } else { setFilteredGroups( groups.filter((g) => g.groupName.toLowerCase().includes(search.toLowerCase()) ) ); } }, [search, groups]); if (loading) return ; return ( <> item.id} renderItem={({ item }) => } ListEmptyComponent={ No groups found } /> ); }; export default GroupList; const styles = StyleSheet.create({ searchContainer: { flexDirection: "row", alignItems: "center", backgroundColor: colors.white, borderRadius: 12, paddingHorizontal: 12, marginVertical: 10, height: 45, shadowColor: "#000", shadowOpacity: 0.05, shadowRadius: 5, elevation: 2, }, searchInput: { flex: 1, marginLeft: 8, color: colors.textDark }, groupCard: { backgroundColor: colors.white, padding: 14, borderRadius: 14, marginBottom: 12, shadowColor: "#000", shadowOpacity: 0.05, shadowRadius: 4, elevation: 2, }, groupLeft: { flexDirection: "row", alignItems: "center" }, groupAvatar: { width: 50, height: 50, borderRadius: 25, backgroundColor: colors.pastelPink, justifyContent: "center", alignItems: "center", marginRight: 12, }, avatarText: { fontSize: 18, fontWeight: "700", color: colors.Home }, groupName: { fontSize: 16, fontWeight: "600", color: colors.textDark }, groupDescription: { fontSize: 13, color: colors.textLight, marginTop: 2 }, groupMeta: { fontSize: 12, color: colors.Home, marginTop: 2 }, detailsBox: { marginTop: 10, padding: 10, borderRadius: 8, backgroundColor: "#f9f9f9", }, detailText: { fontSize: 12, color: colors.textDark, marginBottom: 4 }, emptyText: { textAlign: "center", color: colors.textLight, marginTop: 20 }, centered: { flex: 1, justifyContent: "center", alignItems: "center" }, sectionTitle: { fontSize: 18, fontWeight: "600", color: colors.textDark }, });