import styles from "@/app/tabStyles/indexStyles"; import ShowCard from "@/components/ui/ShowCard"; import { useShowContext } from "@/contexts/ShowContext"; import { useStreamingServiceContext } from "@/contexts/StreamingServiceContext"; 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 { shows, error, loading } = useShowContext(); const { streamingServices } = useStreamingServiceContext(); const [filteredShows, setFilteredShows] = React.useState(shows); const [activeFilter, setActiveFilter] = React.useState("all"); const haptikFeedback = () => { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); } React.useEffect(() => { setFilteredShows(shows); }, [shows]); const handleFilter = (type: string) => { haptikFeedback(); setActiveFilter(type); if (type === "all") { setFilteredShows(shows); return; } if (type === "live") { const filtered = shows.filter((show) => show.running); setFilteredShows(filtered); return; } if (type === activeFilter) { setFilteredShows(shows); setActiveFilter('all'); return; } const filtered = shows.filter((show) => show.streamingService.split(',').map(s => s.trim()).includes(type) ); setFilteredShows(filtered); }; 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} ); } return ( 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, } : {})} /> ); })} ); }