()
| 36 | * Initialize the samples page |
| 37 | */ |
| 38 | export async function initSamplesPage(): Promise<void> { |
| 39 | if (initialized) return; |
| 40 | initialized = true; |
| 41 | |
| 42 | try { |
| 43 | // Load samples data |
| 44 | samplesData = await fetchData<SamplesData>("samples.json"); |
| 45 | |
| 46 | if (!samplesData || samplesData.cookbooks.length === 0) { |
| 47 | showEmptyState(); |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | // Initialize search with all recipes |
| 52 | const allRecipes = samplesData.cookbooks.flatMap((cookbook) => |
| 53 | cookbook.recipes.map( |
| 54 | (recipe) => |
| 55 | ({ |
| 56 | ...recipe, |
| 57 | title: recipe.name, |
| 58 | cookbookId: cookbook.id, |
| 59 | } as SearchableItem & { cookbookId: string }) |
| 60 | ) |
| 61 | ); |
| 62 | search = new FuzzySearch(allRecipes); |
| 63 | |
| 64 | // Setup UI |
| 65 | setupModal(); |
| 66 | setupFilters(); |
| 67 | setupSearch(); |
| 68 | setupRecipeListeners(); |
| 69 | updateResultsCount(); |
| 70 | } catch (error) { |
| 71 | console.error("Failed to initialize samples page:", error); |
| 72 | showEmptyState(); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Show empty state when no cookbooks are available |
no test coverage detected