Refactor panel position management and enhance recipe card handling

- Removed redundant updatePanelPositions calls from various components and centralized the logic in the uiHelpers.js for better maintainability.
- Introduced appendRecipeCards function in RecipeManager to streamline the addition of recipe cards from search results.
- Cleaned up unused code related to search input handling and recipe loading, improving overall code clarity and performance.
- Updated HeaderManager and SearchManager to utilize the new updatePanelPositions function, ensuring consistent panel positioning across the application.
This commit is contained in:
Will Miao
2025-03-20 09:54:13 +08:00
parent caf5b1528c
commit a88b0239eb
9 changed files with 56 additions and 202 deletions

View File

@@ -33,10 +33,7 @@ export class RecipeSearchManager extends SearchManager {
const grid = document.getElementById('recipeGrid');
if (!searchTerm) {
if (state) {
state.pages.recipes.currentPage = 1;
}
this.resetAndReloadRecipes();
window.recipeManager.loadRecipes();
return;
}
@@ -112,34 +109,12 @@ export class RecipeSearchManager extends SearchManager {
}
}
resetAndReloadRecipes() {
if (window.recipeManager && typeof window.recipeManager.loadRecipes === 'function') {
window.recipeManager.loadRecipes();
} else {
// Fallback to reloading the page
window.location.reload();
}
}
appendRecipeCards(recipes) {
// This function would be implemented in the recipes page
// Similar to appendLoraCards for loras
const grid = document.getElementById('recipeGrid');
if (!grid) return;
if (typeof window.appendRecipeCards === 'function') {
window.appendRecipeCards(recipes);
} else {
// Fallback implementation
recipes.forEach(recipe => {
const card = document.createElement('div');
card.className = 'recipe-card';
card.innerHTML = `
<h3>${recipe.name}</h3>
<p>${recipe.description || 'No description'}</p>
`;
grid.appendChild(card);
});
}
// Create data object in the format expected by the RecipeManager
const data = { items: recipes, has_more: false };
window.recipeManager.updateRecipesGrid(data, false);
}
}