Refactor controls and pagination for Checkpoints and LoRAs: Implement unified PageControls, enhance API integration, and improve event handling for better user experience.

This commit is contained in:
Will Miao
2025-04-10 19:41:02 +08:00
parent 252e90a633
commit ee04df40c3
11 changed files with 667 additions and 264 deletions

View File

@@ -101,6 +101,11 @@ export async function loadMoreCheckpoints(resetPagination = true) {
const card = createCheckpointCard(checkpoint);
grid.appendChild(card);
});
// Increment the page number AFTER successful loading
if (data.items.length > 0) {
pageState.currentPage++;
}
} catch (error) {
console.error('Error loading checkpoints:', error);
showToast('Failed to load checkpoints', 'error');

View File

@@ -19,7 +19,6 @@ export async function loadMoreLoras(resetPage = false, updateFolders = false) {
// Clear grid if resetting
const grid = document.getElementById('loraGrid');
if (grid) grid.innerHTML = '';
initializeInfiniteScroll();
}
const params = new URLSearchParams({
@@ -62,9 +61,6 @@ export async function loadMoreLoras(resetPage = false, updateFolders = false) {
const filterLoraHash = getSessionItem('recipe_to_lora_filterLoraHash');
const filterLoraHashes = getSessionItem('recipe_to_lora_filterLoraHashes');
console.log('Filter Lora Hash:', filterLoraHash);
console.log('Filter Lora Hashes:', filterLoraHashes);
// Add hash filter parameter if present
if (filterLoraHash) {
params.append('lora_hash', filterLoraHash);
@@ -93,13 +89,10 @@ export async function loadMoreLoras(resetPage = false, updateFolders = false) {
pageState.hasMore = false;
} else if (data.items.length > 0) {
pageState.hasMore = pageState.currentPage < data.total_pages;
pageState.currentPage++;
appendLoraCards(data.items);
const sentinel = document.getElementById('scroll-sentinel');
if (sentinel && state.observer) {
state.observer.observe(sentinel);
}
// Increment the page number AFTER successful loading
pageState.currentPage++;
} else {
pageState.hasMore = false;
}
@@ -303,10 +296,7 @@ export async function resetAndReload(updateFolders = false) {
const pageState = getCurrentPageState();
console.log('Resetting with state:', { ...pageState });
// Initialize infinite scroll - will reset the observer
initializeInfiniteScroll();
// Load more loras with reset flag
// Reset pagination and load more loras
await loadMoreLoras(true, updateFolders);
}