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, Text, TouchableOpacity, View, } from "react-native"; import { GestureHandlerRootView, ScrollView, } from "react-native-gesture-handler"; export default function HomeScreen() { const { data: shows = [], error, isLoading: loading } = useShows(); const { data: streamingServices = {} } = useStreamingServices(); const [activeFilter, setActiveFilter] = React.useState("all"); const haptikFeedback = () => { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); }; const handleFilter = (type: string) => { haptikFeedback(); if (type === activeFilter) { setActiveFilter("all"); } else { setActiveFilter(type); } }; 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 ( Error: {error?.message || String(error)} ); } 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 {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, } : {})} /> ); })} ); }