refactor: centralize resetAndReload functionality in baseModelApi

This commit is contained in:
Will Miao
2025-07-25 17:48:02 +08:00
parent 7f205cdcc8
commit a3d6e62035
13 changed files with 21 additions and 56 deletions

View File

@@ -754,4 +754,8 @@ export function getModelApiClient() {
}
_singletonClient.setModelType(state.currentPageType);
return _singletonClient;
}
export async function resetAndReload(updateFolders = false) {
return getModelApiClient().loadMoreWithVirtualScroll(true, updateFolders);
}

View File

@@ -22,10 +22,6 @@ export async function loadMoreCheckpoints(resetPage = false, updateFolders = fal
return checkpointApiClient.loadMoreWithVirtualScroll(resetPage, updateFolders);
}
export async function resetAndReload(updateFolders = false) {
return checkpointApiClient.loadMoreWithVirtualScroll(true, updateFolders);
}
// Checkpoint-specific functions
export async function getCheckpointInfo(name) {
try {

View File

@@ -22,10 +22,6 @@ export async function loadMoreLoras(resetPage = false, updateFolders = false) {
return loraApiClient.loadMoreWithVirtualScroll(resetPage, updateFolders);
}
export async function resetAndReload(updateFolders = false) {
return loraApiClient.loadMoreWithVirtualScroll(true, updateFolders);
}
// LoRA-specific functions that don't have common equivalents
export async function fetchModelDescription(modelId, filePath) {
try {

View File

@@ -1,7 +1,6 @@
import { BaseContextMenu } from './BaseContextMenu.js';
import { ModelContextMenuMixin } from './ModelContextMenuMixin.js';
import { resetAndReload } from '../../api/checkpointApi.js';
import { getModelApiClient } from '../../api/baseModelApi.js';
import { getModelApiClient, resetAndReload } from '../../api/baseModelApi.js';
import { showToast } from '../../utils/uiHelpers.js';
import { showDeleteModal, showExcludeModal } from '../../utils/modalUtils.js';

View File

@@ -1,6 +1,7 @@
import { BaseContextMenu } from './BaseContextMenu.js';
import { ModelContextMenuMixin } from './ModelContextMenuMixin.js';
import { refreshSingleLoraMetadata, saveModelMetadata, replacePreview, resetAndReload } from '../../api/loraApi.js';
import { refreshSingleLoraMetadata, saveModelMetadata, replacePreview } from '../../api/loraApi.js';
import { resetAndReload } from '../../api/baseModelApi.js';
import { copyToClipboard, sendLoraToWorkflow } from '../../utils/uiHelpers.js';
import { showExcludeModal, showDeleteModal } from '../../utils/modalUtils.js';

View File

@@ -2,8 +2,7 @@
import { showToast } from '../utils/uiHelpers.js';
import { state, getCurrentPageState } from '../state/index.js';
import { formatDate } from '../utils/formatters.js';
import { resetAndReload as resetAndReloadLoras } from '../api/loraApi.js';
import { resetAndReload as resetAndReloadCheckpoints } from '../api/checkpointApi.js';
import { resetAndReload} from '../api/baseModelApi.js';
import { LoadingManager } from '../managers/LoadingManager.js';
export class ModelDuplicatesManager {
@@ -622,12 +621,7 @@ export class ModelDuplicatesManager {
// If models were successfully deleted
if (data.total_deleted > 0) {
// Reload model data with updated folders
if (this.modelType === 'loras') {
await resetAndReloadLoras(true);
} else {
await resetAndReloadCheckpoints(true);
}
await resetAndReload(true);
// Check if there are still duplicates
try {

View File

@@ -1,7 +1,7 @@
// AlphabetBar.js - Component for alphabet filtering
import { getCurrentPageState } from '../../state/index.js';
import { getStorageItem, setStorageItem } from '../../utils/storageHelpers.js';
import { resetAndReload } from '../../api/loraApi.js';
import { resetAndReload } from '../../api/baseModelApi.js';
/**
* AlphabetBar class - Handles the alphabet filtering UI and interactions

View File

@@ -1,6 +1,7 @@
// CheckpointsControls.js - Specific implementation for the Checkpoints page
import { PageControls } from './PageControls.js';
import { loadMoreCheckpoints, resetAndReload, refreshCheckpoints, fetchCivitai } from '../../api/checkpointApi.js';
import { loadMoreCheckpoints, refreshCheckpoints, fetchCivitai } from '../../api/checkpointApi.js';
import { resetAndReload } from '../../api/baseModelApi.js';
import { showToast } from '../../utils/uiHelpers.js';
import { downloadManager } from '../../managers/DownloadManager.js';

View File

@@ -1,6 +1,7 @@
// LorasControls.js - Specific implementation for the LoRAs page
import { PageControls } from './PageControls.js';
import { loadMoreLoras, fetchCivitai, resetAndReload, refreshLoras } from '../../api/loraApi.js';
import { loadMoreLoras, fetchCivitai, refreshLoras } from '../../api/loraApi.js';
import { resetAndReload } from '../../api/baseModelApi.js';
import { getSessionItem, removeSessionItem } from '../../utils/storageHelpers.js';
import { createAlphabetBar } from '../alphabet/index.js';
import { downloadManager } from '../../managers/DownloadManager.js';

View File

@@ -102,6 +102,7 @@ export class BulkManager {
if (!state.bulkMode) {
this.clearSelection();
// TODO: fix this, no DOM manipulation should be done here
// Force a lightweight refresh of the cards to ensure proper display
// This is less disruptive than a full resetAndReload()
document.querySelectorAll('.lora-card').forEach(card => {

View File

@@ -1,7 +1,7 @@
import { modalManager } from './ModalManager.js';
import { showToast } from '../utils/uiHelpers.js';
import { LoadingManager } from './LoadingManager.js';
import { getModelApiClient } from '../api/baseModelApi.js';
import { getModelApiClient, resetAndReload } from '../api/baseModelApi.js';
import { getStorageItem, setStorageItem } from '../utils/storageHelpers.js';
export class DownloadManager {
@@ -416,15 +416,7 @@ export class DownloadManager {
}
});
// Trigger reload with folder update - use dynamic import based on model type
const modelType = this.apiClient.modelType;
if (modelType === 'loras') {
const { resetAndReload } = await import('../api/loraApi.js');
await resetAndReload(true);
} else if (modelType === 'checkpoints') {
const { resetAndReload } = await import('../api/checkpointApi.js');
await resetAndReload(true);
}
await resetAndReload(true);
} catch (error) {
showToast(error.message, 'error');

View File

@@ -1,7 +1,7 @@
import { modalManager } from './ModalManager.js';
import { showToast } from '../utils/uiHelpers.js';
import { state } from '../state/index.js';
import { resetAndReload } from '../api/loraApi.js';
import { resetAndReload } from '../api/baseModelApi.js';
import { setStorageItem, getStorageItem } from '../utils/storageHelpers.js';
import { DOWNLOAD_PATH_TEMPLATES, MAPPABLE_BASE_MODELS } from '../utils/constants.js';
@@ -664,7 +664,7 @@ export class SettingsManager {
await window.recipeManager.loadRecipes();
} else if (this.currentPage === 'checkpoints') {
// Reload the checkpoints without updating folders
await window.checkpointsManager.loadCheckpoints();
await resetAndReload(false);
}
}

View File

@@ -1,7 +1,6 @@
import { state, getCurrentPageState } from '../state/index.js';
import { resetAndReload } from '../api/loraApi.js';
import { getCurrentPageState } from '../state/index.js';
import { getStorageItem, setStorageItem } from './storageHelpers.js';
import { NODE_TYPES, NODE_TYPE_ICONS, DEFAULT_NODE_COLOR } from './constants.js';
import { NODE_TYPE_ICONS, DEFAULT_NODE_COLOR } from './constants.js';
/**
* Utility function to copy text to clipboard with fallback for older browsers
@@ -168,25 +167,6 @@ function updateThemeToggleIcons(theme) {
themeToggle.classList.add(`theme-${theme}`);
}
export function toggleFolder(tag) {
const tagElement = (tag instanceof HTMLElement) ? tag : this;
const folder = tagElement.dataset.folder;
const wasActive = tagElement.classList.contains('active');
document.querySelectorAll('.folder-tags .tag').forEach(t => {
t.classList.remove('active');
});
if (!wasActive) {
tagElement.classList.add('active');
state.activeFolder = folder;
} else {
state.activeFolder = null;
}
resetAndReload();
}
function filterByFolder(folderPath) {
document.querySelectorAll('.lora-card').forEach(card => {
card.style.display = card.dataset.folder === folderPath ? '' : 'none';