filter: add streaming service filter option

This commit is contained in:
Cron1cle
2025-10-08 03:07:58 +02:00
parent 6e23434e6c
commit 5c49acb2f4
2 changed files with 79 additions and 2 deletions

View File

@@ -4,7 +4,13 @@ import { useShowContext } from "@/contexts/ShowContext";
import { useStreamingServiceContext } from "@/contexts/StreamingServiceContext"; import { useStreamingServiceContext } from "@/contexts/StreamingServiceContext";
import { router } from "expo-router"; import { router } from "expo-router";
import React from "react"; import React from "react";
import { ActivityIndicator, Text, View } from "react-native"; import {
ActivityIndicator,
Text,
TouchableOpacity,
View,
Image,
} from "react-native";
import { import {
GestureHandlerRootView, GestureHandlerRootView,
ScrollView, ScrollView,
@@ -13,6 +19,32 @@ import {
export default function HomeScreen() { export default function HomeScreen() {
const { shows, error, loading } = useShowContext(); const { shows, error, loading } = useShowContext();
const { streamingServices } = useStreamingServiceContext(); const { streamingServices } = useStreamingServiceContext();
const [filteredShows, setFilteredShows] = React.useState(shows);
React.useEffect(() => {
setFilteredShows(shows);
}, [shows]);
const handleFilter = (type: string) => {
if (type === "all") {
setFilteredShows(shows);
return;
}
if (type === "live") {
const filtered = shows.filter((show) => show.running);
setFilteredShows(filtered);
return;
}
const filtered = shows.filter((show) => show.streamingService === type);
setFilteredShows(filtered);
};
const uniqueStreamingServices = React.useMemo(() => {
const uniqueServices = new Set(shows.map((show) => show.streamingService));
return Array.from(uniqueServices);
}, [shows]);
if (loading) { if (loading) {
return ( return (
@@ -47,7 +79,46 @@ export default function HomeScreen() {
<Text style={styles.title}>FLTR</Text> <Text style={styles.title}>FLTR</Text>
</View> </View>
<ScrollView contentContainerStyle={{ paddingBottom: 30 }}> <ScrollView contentContainerStyle={{ paddingBottom: 30 }}>
{shows.map((show) => { <View style={styles.filterSection}>
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={{
alignItems: "center",
paddingHorizontal: 10,
gap: 10,
}}
>
{uniqueStreamingServices.map((serviceName) => {
const streamingService =
streamingServices[
`assets.images.streamingServices.${serviceName.toLowerCase()}`
];
return (
<TouchableOpacity
key={serviceName}
style={{
padding: 5,
backgroundColor: "hsl(221, 39%, 80%)",
borderRadius: 50,
}}
onPress={() => handleFilter(serviceName)}
>
<Image
source={{ uri: streamingService }}
style={{
width: 45,
height: 45,
borderRadius: 30,
resizeMode: "contain",
}}
/>
</TouchableOpacity>
);
})}
</ScrollView>
</View>
{filteredShows.map((show) => {
const showLiveBadge = show.running; const showLiveBadge = show.running;
const streamingService = const streamingService =
streamingServices[ streamingServices[

View File

@@ -37,4 +37,10 @@ export default StyleSheet.create({
paddingVertical: 5, paddingVertical: 5,
paddingHorizontal: 10, paddingHorizontal: 10,
}, },
filterSection: {
width: "100%",
height: 70,
backgroundColor: "hsl(221, 39%, 5%)",
marginTop: 20,
},
}); });