/** * RecipeListPage - Displays a list of all recipes with search and filtering */ import { useState } from 'react'; import { Link } from 'react-router-dom'; import { useRecipes } from '../hooks/useRecipes'; import { useTags } from '../hooks/useTags'; import { RecipeCard } from '../components/RecipeCard'; import { MissionControlPanel } from '../components/MissionControlPanel'; export function RecipeListPage() { const [searchTerm, setSearchTerm] = useState(''); const [searchQuery, setSearchQuery] = useState(''); const [selectedTagId, setSelectedTagId] = useState(null); const { recipes, loading, error, hasMore, loadMore } = useRecipes({ search: searchQuery, limit: 20, }); const { tags, loading: tagsLoading } = useTags(); const handleSearch = (e: React.FormEvent) => { e.preventDefault(); setSearchQuery(searchTerm); }; const handleClearSearch = () => { setSearchTerm(''); setSearchQuery(''); }; const handleClearFilters = () => { setSearchTerm(''); setSearchQuery(''); setSelectedTagId(null); }; // Note: This is client-side filtering. For better performance with large datasets, // the backend should support tag filtering in the API. // For now, when a tag is selected, we show all recipes with a note that this feature // is in development. Full tag filtering will require fetching recipe-tag associations. const filteredRecipes = recipes; const hasActiveFilters = searchQuery || selectedTagId !== null; return (
{/* Header */}

My Recipes

Browse and search your recipe collection

+ New Recipe
{/* Search Bar */}
setSearchTerm(e.target.value)} className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" /> {searchQuery && ( )}
{/* Tag Filter */} {!tagsLoading && tags.length > 0 && (
{tags.map(tag => ( ))}
)} {hasActiveFilters && (
Active filters: {searchQuery && ( Search: "{searchQuery}" )} {selectedTagId !== null && ( Tag: {tags.find(t => t.id === selectedTagId)?.name} )}
)} {selectedTagId !== null && (

Note: Tag filtering is currently a work in progress. All recipes are shown below. Individual recipe tags can be viewed on their detail pages.

)}
{/* Error State */} {error && (

Error: {error}

)} {/* Loading State (first load) */} {loading && recipes.length === 0 && (

Loading recipes...

)} {/* Empty State */} {!loading && !error && filteredRecipes.length === 0 && (
🍳

{searchQuery ? 'No recipes found' : 'No recipes yet'}

{searchQuery ? 'Try a different search term' : 'Get started by adding your first recipe'}

{!searchQuery && ( Add Your First Recipe )}
)} {/* Recipe Grid */} {filteredRecipes.length > 0 && ( <>
{filteredRecipes.map((recipe) => ( ))}
{/* Load More Button */} {hasMore && (
)} {/* Results summary */}
Showing {filteredRecipes.length} recipe{filteredRecipes.length !== 1 ? 's' : ''}
)}
); }