/** * DiscoverPage component - Main discover/browse interface for PodTUI */ import { createSignal, For, Show, onMount } from "solid-js"; import { useKeyboard } from "@opentui/solid"; import { useDiscoverStore, DISCOVER_CATEGORIES } from "@/stores/discover"; import { useTheme } from "@/context/ThemeContext"; import { PodcastCard } from "./PodcastCard"; import { SelectableBox, SelectableText } from "@/components/Selectable"; import { useNavigation } from "@/context/NavigationContext"; import { KeybindProvider, useKeybinds } from "@/context/KeybindContext"; enum DiscoverPagePaneType { CATEGORIES = 1, SHOWS = 2, } export const DiscoverPaneCount = 2; export function DiscoverPage() { const discoverStore = useDiscoverStore(); const [showIndex, setShowIndex] = createSignal(0); const [categoryIndex, setCategoryIndex] = createSignal(0); const nav = useNavigation(); const keybind = useKeybinds(); onMount(() => { useKeyboard( (keyEvent: any) => { const isDown = keybind.match("down", keyEvent); const isUp = keybind.match("up", keyEvent); const isEnter = keyEvent.name === "Enter" || keyEvent.name === " "; const isSpace = keyEvent.name === " "; if (isEnter || isSpace) { const filteredPodcasts = discoverStore.filteredPodcasts(); if (filteredPodcasts.length > 0 && showIndex() < filteredPodcasts.length) { setShowIndex(showIndex() + 1); } return; } const filteredPodcasts = discoverStore.filteredPodcasts(); if (filteredPodcasts.length === 0) return; if (isDown && showIndex() < filteredPodcasts.length - 1) { setShowIndex(showIndex() + 1); } else if (isUp && showIndex() > 0) { setShowIndex(showIndex() - 1); } }, { release: false }, ); }); const handleCategorySelect = (categoryId: string) => { discoverStore.setSelectedCategory(categoryId); const index = DISCOVER_CATEGORIES.findIndex((c) => c.id === categoryId); if (index >= 0) setCategoryIndex(index); setShowIndex(0); }; const handleShowSelect = (index: number) => { setShowIndex(index); }; const handleSubscribe = (podcast: { id: string }) => { discoverStore.toggleSubscription(podcast.id); }; const { theme } = useTheme(); return ( Categories: {(category) => { const isSelected = () => discoverStore.selectedCategory() === category.id; return ( handleCategorySelect(category.id)} > {category.icon} {category.name} ); }} false} primary={nav.activeDepth() == DiscoverPagePaneType.SHOWS} > Trending in{" "} {DISCOVER_CATEGORIES.find( (c) => c.id === discoverStore.selectedCategory(), )?.name ?? "All"} {discoverStore.filteredPodcasts().length !== 0 ? ( Loading trending shows... ) : ( No podcasts found in this category. )} } when={ !discoverStore.isLoading() && discoverStore.filteredPodcasts().length === 0 } > {(podcast, index) => ( handleShowSelect(index())} onSubscribe={() => handleSubscribe(podcast)} /> )} ); }