mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 07:05:43 -03:00
refactor: centralize resetAndReload functionality in baseModelApi
This commit is contained in:
@@ -754,4 +754,8 @@ export function getModelApiClient() {
|
|||||||
}
|
}
|
||||||
_singletonClient.setModelType(state.currentPageType);
|
_singletonClient.setModelType(state.currentPageType);
|
||||||
return _singletonClient;
|
return _singletonClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function resetAndReload(updateFolders = false) {
|
||||||
|
return getModelApiClient().loadMoreWithVirtualScroll(true, updateFolders);
|
||||||
}
|
}
|
||||||
@@ -22,10 +22,6 @@ export async function loadMoreCheckpoints(resetPage = false, updateFolders = fal
|
|||||||
return checkpointApiClient.loadMoreWithVirtualScroll(resetPage, updateFolders);
|
return checkpointApiClient.loadMoreWithVirtualScroll(resetPage, updateFolders);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function resetAndReload(updateFolders = false) {
|
|
||||||
return checkpointApiClient.loadMoreWithVirtualScroll(true, updateFolders);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checkpoint-specific functions
|
// Checkpoint-specific functions
|
||||||
export async function getCheckpointInfo(name) {
|
export async function getCheckpointInfo(name) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ export async function loadMoreLoras(resetPage = false, updateFolders = false) {
|
|||||||
return loraApiClient.loadMoreWithVirtualScroll(resetPage, updateFolders);
|
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
|
// LoRA-specific functions that don't have common equivalents
|
||||||
export async function fetchModelDescription(modelId, filePath) {
|
export async function fetchModelDescription(modelId, filePath) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { BaseContextMenu } from './BaseContextMenu.js';
|
import { BaseContextMenu } from './BaseContextMenu.js';
|
||||||
import { ModelContextMenuMixin } from './ModelContextMenuMixin.js';
|
import { ModelContextMenuMixin } from './ModelContextMenuMixin.js';
|
||||||
import { resetAndReload } from '../../api/checkpointApi.js';
|
import { getModelApiClient, resetAndReload } from '../../api/baseModelApi.js';
|
||||||
import { getModelApiClient } from '../../api/baseModelApi.js';
|
|
||||||
import { showToast } from '../../utils/uiHelpers.js';
|
import { showToast } from '../../utils/uiHelpers.js';
|
||||||
import { showDeleteModal, showExcludeModal } from '../../utils/modalUtils.js';
|
import { showDeleteModal, showExcludeModal } from '../../utils/modalUtils.js';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { BaseContextMenu } from './BaseContextMenu.js';
|
import { BaseContextMenu } from './BaseContextMenu.js';
|
||||||
import { ModelContextMenuMixin } from './ModelContextMenuMixin.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 { copyToClipboard, sendLoraToWorkflow } from '../../utils/uiHelpers.js';
|
||||||
import { showExcludeModal, showDeleteModal } from '../../utils/modalUtils.js';
|
import { showExcludeModal, showDeleteModal } from '../../utils/modalUtils.js';
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
import { showToast } from '../utils/uiHelpers.js';
|
import { showToast } from '../utils/uiHelpers.js';
|
||||||
import { state, getCurrentPageState } from '../state/index.js';
|
import { state, getCurrentPageState } from '../state/index.js';
|
||||||
import { formatDate } from '../utils/formatters.js';
|
import { formatDate } from '../utils/formatters.js';
|
||||||
import { resetAndReload as resetAndReloadLoras } from '../api/loraApi.js';
|
import { resetAndReload} from '../api/baseModelApi.js';
|
||||||
import { resetAndReload as resetAndReloadCheckpoints } from '../api/checkpointApi.js';
|
|
||||||
import { LoadingManager } from '../managers/LoadingManager.js';
|
import { LoadingManager } from '../managers/LoadingManager.js';
|
||||||
|
|
||||||
export class ModelDuplicatesManager {
|
export class ModelDuplicatesManager {
|
||||||
@@ -622,12 +621,7 @@ export class ModelDuplicatesManager {
|
|||||||
|
|
||||||
// If models were successfully deleted
|
// If models were successfully deleted
|
||||||
if (data.total_deleted > 0) {
|
if (data.total_deleted > 0) {
|
||||||
// Reload model data with updated folders
|
await resetAndReload(true);
|
||||||
if (this.modelType === 'loras') {
|
|
||||||
await resetAndReloadLoras(true);
|
|
||||||
} else {
|
|
||||||
await resetAndReloadCheckpoints(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if there are still duplicates
|
// Check if there are still duplicates
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// AlphabetBar.js - Component for alphabet filtering
|
// AlphabetBar.js - Component for alphabet filtering
|
||||||
import { getCurrentPageState } from '../../state/index.js';
|
import { getCurrentPageState } from '../../state/index.js';
|
||||||
import { getStorageItem, setStorageItem } from '../../utils/storageHelpers.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
|
* AlphabetBar class - Handles the alphabet filtering UI and interactions
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// CheckpointsControls.js - Specific implementation for the Checkpoints page
|
// CheckpointsControls.js - Specific implementation for the Checkpoints page
|
||||||
import { PageControls } from './PageControls.js';
|
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 { showToast } from '../../utils/uiHelpers.js';
|
||||||
import { downloadManager } from '../../managers/DownloadManager.js';
|
import { downloadManager } from '../../managers/DownloadManager.js';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// LorasControls.js - Specific implementation for the LoRAs page
|
// LorasControls.js - Specific implementation for the LoRAs page
|
||||||
import { PageControls } from './PageControls.js';
|
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 { getSessionItem, removeSessionItem } from '../../utils/storageHelpers.js';
|
||||||
import { createAlphabetBar } from '../alphabet/index.js';
|
import { createAlphabetBar } from '../alphabet/index.js';
|
||||||
import { downloadManager } from '../../managers/DownloadManager.js';
|
import { downloadManager } from '../../managers/DownloadManager.js';
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ export class BulkManager {
|
|||||||
if (!state.bulkMode) {
|
if (!state.bulkMode) {
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
|
|
||||||
|
// TODO: fix this, no DOM manipulation should be done here
|
||||||
// Force a lightweight refresh of the cards to ensure proper display
|
// Force a lightweight refresh of the cards to ensure proper display
|
||||||
// This is less disruptive than a full resetAndReload()
|
// This is less disruptive than a full resetAndReload()
|
||||||
document.querySelectorAll('.lora-card').forEach(card => {
|
document.querySelectorAll('.lora-card').forEach(card => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
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 { getModelApiClient } from '../api/baseModelApi.js';
|
import { getModelApiClient, resetAndReload } from '../api/baseModelApi.js';
|
||||||
import { getStorageItem, setStorageItem } from '../utils/storageHelpers.js';
|
import { getStorageItem, setStorageItem } from '../utils/storageHelpers.js';
|
||||||
|
|
||||||
export class DownloadManager {
|
export class DownloadManager {
|
||||||
@@ -416,15 +416,7 @@ export class DownloadManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Trigger reload with folder update - use dynamic import based on model type
|
await resetAndReload(true);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showToast(error.message, 'error');
|
showToast(error.message, 'error');
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { modalManager } from './ModalManager.js';
|
import { modalManager } from './ModalManager.js';
|
||||||
import { showToast } from '../utils/uiHelpers.js';
|
import { showToast } from '../utils/uiHelpers.js';
|
||||||
import { state } from '../state/index.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 { setStorageItem, getStorageItem } from '../utils/storageHelpers.js';
|
||||||
import { DOWNLOAD_PATH_TEMPLATES, MAPPABLE_BASE_MODELS } from '../utils/constants.js';
|
import { DOWNLOAD_PATH_TEMPLATES, MAPPABLE_BASE_MODELS } from '../utils/constants.js';
|
||||||
|
|
||||||
@@ -664,7 +664,7 @@ export class SettingsManager {
|
|||||||
await window.recipeManager.loadRecipes();
|
await window.recipeManager.loadRecipes();
|
||||||
} else if (this.currentPage === 'checkpoints') {
|
} else if (this.currentPage === 'checkpoints') {
|
||||||
// Reload the checkpoints without updating folders
|
// Reload the checkpoints without updating folders
|
||||||
await window.checkpointsManager.loadCheckpoints();
|
await resetAndReload(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { state, getCurrentPageState } from '../state/index.js';
|
import { getCurrentPageState } from '../state/index.js';
|
||||||
import { resetAndReload } from '../api/loraApi.js';
|
|
||||||
import { getStorageItem, setStorageItem } from './storageHelpers.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
|
* Utility function to copy text to clipboard with fallback for older browsers
|
||||||
@@ -168,25 +167,6 @@ function updateThemeToggleIcons(theme) {
|
|||||||
themeToggle.classList.add(`theme-${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) {
|
function filterByFolder(folderPath) {
|
||||||
document.querySelectorAll('.lora-card').forEach(card => {
|
document.querySelectorAll('.lora-card').forEach(card => {
|
||||||
card.style.display = card.dataset.folder === folderPath ? '' : 'none';
|
card.style.display = card.dataset.folder === folderPath ? '' : 'none';
|
||||||
|
|||||||
Reference in New Issue
Block a user