import styles from "@/app/tabStyles/indexStyles"; import ShowCard from "@/components/ui/ShowCard"; import { useShows } from "@/hooks/useShows"; import { useStreamingServices } from "@/hooks/useStreamingServices"; import Feather from "@expo/vector-icons/Feather"; import * as Haptics from "expo-haptics"; import { router } from "expo-router"; import React from "react"; import { ActivityIndicator, Image, RefreshControl, ScrollView as RNScrollView, Text, TouchableOpacity, View, } from "react-native"; import { GestureHandlerRootView, ScrollView, // horizontaler ScrollView bleibt aus RNGH } from "react-native-gesture-handler"; export default function HomeScreen() { const { data: shows = [], error, isLoading: loading, refetch: refetchShows, // ⬅️ refetch aus Hook } = useShows(); const { data: streamingServices = {}, refetch: refetchServices, // ⬅️ refetch aus Hook } = useStreamingServices(); const [activeFilter, setActiveFilter] = React.useState("all"); const [refreshing, setRefreshing] = React.useState(false); // ⬅️ UI-State für Pull-to-Refresh const haptikFeedback = () => { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); }; const handleFilter = (type: string) => { haptikFeedback(); if (type === activeFilter) { setActiveFilter("all"); } else { setActiveFilter(type); } }; // ⬅️ Pull-to-Refresh Handler const onRefresh = React.useCallback(async () => { haptikFeedback(); setRefreshing(true); try { await Promise.all([ typeof refetchShows === "function" ? refetchShows() : Promise.resolve(), typeof refetchServices === "function" ? refetchServices() : Promise.resolve(), ]); } finally { setRefreshing(false); } }, [refetchShows, refetchServices]); const filteredShows = React.useMemo(() => { if (activeFilter === "all") { return shows; } if (activeFilter === "live") { return shows.filter((show) => show.running); } return shows.filter((show) => show.streamingService .split(",") .map((s) => s.trim()) .includes(activeFilter) ); }, [shows, activeFilter]); const uniqueStreamingServices = React.useMemo(() => { const uniqueServices = new Set(); shows.forEach((show) => { const services = show.streamingService.split(", ").map((s) => s.trim()); services.forEach((service) => uniqueServices.add(service)); }); return Array.from(uniqueServices); }, [shows]); if (loading) { return ( ); } if (error) { return ( ⚠️ Fehler beim Laden {error?.message || "Ein unerwarteter Fehler ist aufgetreten."} { if (typeof refetchShows === "function") refetchShows(); if (typeof refetchServices === "function") refetchServices(); }} style={{ marginTop: 6, backgroundColor: "rgba(255,255,255,0.15)", paddingVertical: 10, paddingHorizontal: 18, borderRadius: 8, }} > Erneut versuchen ); } return ( { router.push("/legal"); }} style={{ position: "absolute", left: 16, top: "63%", transform: [{ translateY: -12 }], height: 40, width: 40, alignItems: "center", justifyContent: "center", borderRadius: 10, backgroundColor: "rgba(255,255,255,0.06)", }} accessibilityRole="button" accessibilityLabel="Menü öffnen" > FLTR } > {/* ⬅️ HORIZONTALER SCROLLBEREICH BLEIBT AUS RNGH */} {activeFilter !== "all" && ( handleFilter("all")} > ALLE )} {activeFilter !== "live" && ( handleFilter("live")} > LIVE )} {uniqueStreamingServices.map((serviceName) => { const streamingService = streamingServices[ `assets.images.streamingServices.${serviceName.toLowerCase()}` ]; return ( handleFilter(serviceName)} > ); })} {filteredShows.map((show) => { const showLiveBadge = show.running; return ( router.push({ pathname: "/showDetails", params: { id: String(show.id), title: show.title, bannerUri: show.bannerUri, description: show.description, concept: show.concept, genres: show.genres, streamingService: show.streamingService, logoUri: show.logoUrl, running: String(show.running), }, }) } imageUri={show.bannerUri} streamingServicesUris={show.streamingService .split(", ") .map( (s) => streamingServices[ `assets.images.streamingServices.${s.toLowerCase()}` ] )} genres={show.genres} {...(showLiveBadge ? { liveBadgeText: "LIVE", liveBadgeContainerStyle: styles.liveBadgeContainer, } : {})} /> ); })} ); }