Refactor RecipeManager and ImportManager for improved functionality

- Removed deprecated global functions from RecipeManager to streamline the API and enhance clarity.
- Updated the import handling in ImportManager to directly call loadRecipes on the RecipeManager, ensuring better integration.
- Adjusted the recipes.html template to utilize the ImportManager for showing the import modal, improving code consistency.
This commit is contained in:
Will Miao
2025-03-20 15:57:00 +08:00
parent 4a47dc2073
commit 19ff2ebfe1
4 changed files with 4 additions and 31 deletions

View File

@@ -1,8 +1,6 @@
import { modalManager } from './ModalManager.js'; import { modalManager } from './ModalManager.js';
import { showToast } from '../utils/uiHelpers.js'; import { showToast } from '../utils/uiHelpers.js';
import { LoadingManager } from './LoadingManager.js'; import { LoadingManager } from './LoadingManager.js';
import { state } from '../state/index.js';
import { resetAndReload } from '../api/loraApi.js';
export class ImportManager { export class ImportManager {
constructor() { constructor() {
@@ -922,13 +920,7 @@ export class ImportManager {
// Close modal and reload recipes // Close modal and reload recipes
modalManager.closeModal('importModal'); modalManager.closeModal('importModal');
// Refresh the recipe list if needed window.recipeManager.loadRecipes(true); // true to reset pagination
if (typeof refreshRecipes === 'function') {
refreshRecipes();
} else {
// Fallback to reloading the page
resetAndReload();
}
} else { } else {
// Handle error // Handle error

View File

@@ -308,7 +308,6 @@ export class SearchManager {
// Call the appropriate manager's load method based on page type // Call the appropriate manager's load method based on page type
if (this.currentPage === 'recipes' && window.recipeManager) { if (this.currentPage === 'recipes' && window.recipeManager) {
console.log("load recipes")
window.recipeManager.loadRecipes(true); // true to reset pagination window.recipeManager.loadRecipes(true); // true to reset pagination
} else if (this.currentPage === 'loras' && window.loadMoreLoras) { } else if (this.currentPage === 'loras' && window.loadMoreLoras) {
// Reset loras page and reload // Reset loras page and reload

View File

@@ -56,22 +56,7 @@ class RecipeManager {
_exposeGlobalFunctions() { _exposeGlobalFunctions() {
// Only expose what's needed for the page // Only expose what's needed for the page
window.recipeManager = this; window.recipeManager = this;
window.importRecipes = () => this.importRecipes();
window.importManager = this.importManager; window.importManager = this.importManager;
// Deprecated - kept for backwards compatibility
window.loadMoreRecipes = () => {
console.warn('loadMoreRecipes is deprecated, use infiniteScroll instead');
this.pageState.currentPage++;
this.loadRecipes(false);
};
// Add appendRecipeCards function for compatibility
window.appendRecipeCards = (recipes) => {
console.warn('appendRecipeCards is deprecated, use recipeManager.updateRecipesGrid instead');
const data = { items: recipes, has_more: false };
this.updateRecipesGrid(data, false);
};
} }
initEventListeners() { initEventListeners() {
@@ -140,6 +125,8 @@ class RecipeManager {
} }
const data = await response.json(); const data = await response.json();
console.log('Recipes data:', data);
// Update recipes grid // Update recipes grid
this.updateRecipesGrid(data, resetPage); this.updateRecipesGrid(data, resetPage);
@@ -205,11 +192,6 @@ class RecipeManager {
showRecipeDetails(recipe) { showRecipeDetails(recipe) {
this.recipeModal.showRecipeDetails(recipe); this.recipeModal.showRecipeDetails(recipe);
} }
// Add a method to handle recipe import
importRecipes() {
this.importManager.showImportModal();
}
} }
// Initialize components // Initialize components

View File

@@ -27,7 +27,7 @@
<div class="controls"> <div class="controls">
<div class="action-buttons"> <div class="action-buttons">
<div title="Import recipes" class="control-group"> <div title="Import recipes" class="control-group">
<button onclick="modalManager.showModal('importModal')"><i class="fas fa-file-import"></i> Import</button> <button onclick="importManager.showImportModal()"><i class="fas fa-file-import"></i> Import</button>
</div> </div>
</div> </div>
</div> </div>